Class: FPM::Fry::Detector::Container

Inherits:
Struct
  • Object
show all
Defined in:
lib/fpm/fry/detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client

Returns:

  • (Object)

    the current value of client



17
18
19
# File 'lib/fpm/fry/detector.rb', line 17

def client
  @client
end

#containerObject

Returns the value of attribute container

Returns:

  • (Object)

    the current value of container



17
18
19
# File 'lib/fpm/fry/detector.rb', line 17

def container
  @container
end

#distributionObject (readonly)

Returns the value of attribute distribution.



18
19
20
# File 'lib/fpm/fry/detector.rb', line 18

def distribution
  @distribution
end

#versionObject (readonly)

Returns the value of attribute version.



19
20
21
# File 'lib/fpm/fry/detector.rb', line 19

def version
  @version
end

Instance Method Details

#detect!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fpm/fry/detector.rb', line 21

def detect!
  begin
    client.read(container,'/etc/lsb-release') do |file|
      file.read.each_line do |line|
        case(line)
        when /\ADISTRIB_ID=/ then
          @distribution = $'.strip.downcase
        when /\ADISTRIB_RELEASE=/ then
          @version = $'.strip
        end
      end
    end
    return !!(@distribution and @version)
  rescue Client::FileNotFound
  end
  begin
    client.read(container,'/etc/debian_version') do |file|
      content = file.read
      if /\A\d+(?:\.\d+)+\Z/ =~ content
        @distribution = 'debian'
        @version = content.strip
      end
    end
    return !!(@distribution and @version)
  rescue Client::FileNotFound
  end
  begin
    client.read(container,'/etc/redhat-release') do |file|
      if file.header.typeflag == "2" # centos links this file
        client.read(container,File.absolute_path(file.header.linkname,'/etc')) do |file|
          detect_redhat_release(file)
        end
      else
        detect_redhat_release(file)
      end
    end
    return !!(@distribution and @version)
  rescue Client::FileNotFound
  end
  return false
end