diff options
author | varac <varacanero@zeromail.org> | 2015-12-05 20:26:39 +0100 |
---|---|---|
committer | varac <varacanero@zeromail.org> | 2015-12-05 20:26:39 +0100 |
commit | b6cb0285053a0ffd23082d7e63a87108ca0e3fbd (patch) | |
tree | a142332e3419df289e9437b6477971276cbc836f /lib/facter/debian_codename.rb | |
parent | ab90d1d0fe9655d367c637e95dff59e4dbe2dd35 (diff) | |
parent | d372562329371c24df889d69ca4d476eda6497e9 (diff) |
Merge remote-tracking branch 'shared/master' into leap_master
Diffstat (limited to 'lib/facter/debian_codename.rb')
-rw-r--r-- | lib/facter/debian_codename.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/facter/debian_codename.rb b/lib/facter/debian_codename.rb new file mode 100644 index 0000000..06ec5ff --- /dev/null +++ b/lib/facter/debian_codename.rb @@ -0,0 +1,40 @@ +begin + require 'facter/util/debian' +end + +def version_to_codename(version) + if Facter::Util::Debian::CODENAMES.has_key?(version) + return Facter::Util::Debian::CODENAMES[version] + else + Facter.warn("Could not determine codename from version '#{version}'") + end +end + +Facter.add(:debian_codename) do + has_weight 99 + confine :operatingsystem => 'Debian' + setcode do + Facter.value('lsbdistcodename') + end +end + +Facter.add(:debian_codename) do + has_weight 66 + confine :operatingsystem => 'Debian' + setcode do + version_to_codename(Facter.value('operatingsystemmajrelease')) + end +end + +Facter.add(:debian_codename) do + has_weight 33 + confine :operatingsystem => 'Debian' + setcode do + debian_version = File.open('/etc/debian_version', &:readline) + if debian_version.match(/^\d+/) + version_to_codename(debian_version.scan(/^(\d+)/)[0][0]) + elsif debian_version.match(/^[a-z]+\/(sid|unstable)/) + debian_version.scan(/^([a-z]+)\//)[0][0] + end + end +end |