Module: Train::Extras::LinuxLSB

Included in:
DetectLinux
Defined in:
lib/train/extras/linux_lsb.rb

Instance Method Summary collapse

Instance Method Details

#detect_linux_via_lsbObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/train/extras/linux_lsb.rb', line 41

def detect_linux_via_lsb
  return false if lsb[:id].nil?
  id = lsb[:id].downcase
  case id
  when /redhat/
    @platform[:family] = 'redhat'
  when /amazon/
    @platform[:family] = 'amazon'
  when /scientificsl/
    @platform[:family] = 'scientific'
  when /xenserver/
    @platform[:family] = 'xenserver'
  else
    @platform[:family] = id
  end
  @platform[:release] = lsb[:release]
  true
end

#lsbObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/train/extras/linux_lsb.rb', line 30

def lsb
  return @lsb if defined?(@lsb)
  @lsb = {}
  if !(raw = get_config('/etc/lsb-release')).nil?
    @lsb = lsb_config(raw)
  elsif unix_file?('/usr/bin/lsb_release')
    @lsb = lsb_release
  end
  @lsb
end

#lsb_config(content) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/train/extras/linux_lsb.rb', line 13

def lsb_config(content)
  {
    id:       content[/^DISTRIB_ID=["']?(.+?)["']?$/, 1],
    release:  content[/^DISTRIB_RELEASE=["']?(.+?)["']?$/, 1],
    codename: content[/^DISTRIB_CODENAME=["']?(.+?)["']?$/, 1],
  }
end

#lsb_releaseObject



21
22
23
24
25
26
27
28
# File 'lib/train/extras/linux_lsb.rb', line 21

def lsb_release
  raw = @backend.run_command('lsb_release -a').stdout
  {
    id:       raw[/^Distributor ID:\s+(.+)$/, 1],
    release:  raw[/^Release:\s+(.+)$/, 1],
    codename: raw[/^Codename:\s+(.+)$/, 1],
  }
end