inspec/lib/vulcano/plugins/backend_linux_lsb.rb
Christoph Hartmann 8fff2ee989 add author header
2015-10-06 18:55:44 +02:00

60 lines
1.4 KiB
Ruby

# encoding: utf-8
# author: Dominik Richter
# author: Christoph Hartmann
#
# This is heavily based on:
#
# OHAI https://github.com/chef/ohai
# by Adam Jacob, Chef Software Inc
#
class Vulcano::Plugins::Backend
module LinuxLSB
def lsb_config(content)
{
id: content[/^DISTRIB_ID=["']?(.+?)["']?$/, 1],
release: content[/^DISTRIB_RELEASE=["']?(.+?)["']?$/, 1],
codename: content[/^DISTRIB_CODENAME=["']?(.+?)["']?$/, 1],
}
end
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
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
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
end
end