Module: FPM::Fry::Detector

Defined in:
lib/fpm/fry/detector.rb

Class Method Summary collapse

Class Method Details

.detect(inspector) ⇒ Hash<Symbol, String>

Detects a set of basic properties about an image.

Parameters:

Returns:

  • (Hash<Symbol, String>)


9
10
11
12
13
14
15
16
17
18
19
20
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
# File 'lib/fpm/fry/detector.rb', line 9

def self.detect(inspector)
  found = {}
  if inspector.exists? '/usr/bin/apt-get'
    found[:flavour] = 'debian'
  elsif inspector.exists? '/bin/rpm'
    found[:flavour] = 'redhat'
  end
  begin
    inspector.read_content('/etc/lsb-release').each_line do |line|
      case(line)
      when /\ADISTRIB_ID=/ then
        found[:distribution] = $'.strip.downcase
      when /\ADISTRIB_RELEASE=/ then
        found[:release] = $'.strip
      when /\ADISTRIB_CODENAME=/ then
        found[:codename] = $'.strip
      end
    end
  rescue Client::FileNotFound
  end

  begin
    inspector.read_content('/etc/os-release').each_line do |line|
      case(line)
      when /\AVERSION=\"(\w+) \((\w+)\)\"/ then
        found[:release] ||= $1
        found[:codename] ||= $2
      end
    end
  rescue Client::FileNotFound
  end
  begin
    content = inspector.read_content('/etc/debian_version')
    if /\A\d+(?:\.\d+)+\Z/ =~ content
      found[:distribution] ||= 'debian'
      found[:release] = content.strip
    end
  rescue Client::FileNotFound
  end
  begin
    content = inspector.read_content('/etc/redhat-release')
    content.each_line do |line|
      case(line)
      when /\A(\w+)(?: Linux)? release ([\d\.]+)/ then
        found[:distribution] ||= $1.strip.downcase
        found[:release] = $2.strip
      end
    end
  rescue Client::FileNotFound
  end
  return found
end