summaryrefslogtreecommitdiff
path: root/lib/facter
diff options
context:
space:
mode:
authorJerome Charaoui <jcharaoui@cmaisonneuve.qc.ca>2015-10-09 12:08:26 -0400
committerJerome Charaoui <jcharaoui@cmaisonneuve.qc.ca>2015-10-09 12:08:26 -0400
commite4d777e5ec333c819a6b87b5c0186f67e86361ee (patch)
treeb36957b74b417e68e9c09bf5300957d2e9f4857e /lib/facter
parentcc53ce119f5b9b239bc1b8cdcaae6a668b8d1f8c (diff)
parent3a7dd605e344cd8bdfa33a1fb82bfefe948cbd00 (diff)
Fix merge conflict in README
Diffstat (limited to 'lib/facter')
-rw-r--r--lib/facter/debian_codename.rb40
-rw-r--r--lib/facter/debian_lts.rb14
-rw-r--r--lib/facter/debian_nextcodename.rb22
-rw-r--r--lib/facter/debian_nextrelease.rb23
-rw-r--r--lib/facter/debian_release.rb36
-rw-r--r--lib/facter/ubuntu_codename.rb8
-rw-r--r--lib/facter/ubuntu_nextcodename.rb18
-rw-r--r--lib/facter/util/debian.rb18
-rw-r--r--lib/facter/util/ubuntu.rb20
9 files changed, 199 insertions, 0 deletions
diff --git a/lib/facter/debian_codename.rb b/lib/facter/debian_codename.rb
new file mode 100644
index 0000000..73eeea2
--- /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(version_to_codename.scan(/^(\d+)/)[0][0])
+ elsif debian_version.match(/^[a-z]+\/(sid|unstable)/)
+ debian_version.scan(/^([a-z]+)\//)[0][0]
+ end
+ end
+end
diff --git a/lib/facter/debian_lts.rb b/lib/facter/debian_lts.rb
new file mode 100644
index 0000000..1c137e1
--- /dev/null
+++ b/lib/facter/debian_lts.rb
@@ -0,0 +1,14 @@
+begin
+ require 'facter/util/debian'
+end
+
+Facter.add(:debian_lts) do
+ confine :operatingsystem => 'Debian'
+ setcode do
+ if Facter::Util::Debian::LTS.include? Facter.value('debian_codename')
+ true
+ else
+ false
+ end
+ end
+end
diff --git a/lib/facter/debian_nextcodename.rb b/lib/facter/debian_nextcodename.rb
new file mode 100644
index 0000000..af16cc8
--- /dev/null
+++ b/lib/facter/debian_nextcodename.rb
@@ -0,0 +1,22 @@
+begin
+ require 'facter/util/debian'
+end
+
+def debian_codename_to_next(codename)
+ if codename == "sid"
+ return "experimental"
+ else
+ codenames = Facter::Util::Debian::CODENAMES.values
+ i = codenames.index(codename)
+ if i and i+1 < codenames.count
+ return codenames[i+1]
+ end
+ end
+end
+
+Facter.add(:debian_nextcodename) do
+ confine :operatingsystem => 'Debian'
+ setcode do
+ debian_codename_to_next(Facter.value('debian_codename'))
+ end
+end
diff --git a/lib/facter/debian_nextrelease.rb b/lib/facter/debian_nextrelease.rb
new file mode 100644
index 0000000..2a9c4f5
--- /dev/null
+++ b/lib/facter/debian_nextrelease.rb
@@ -0,0 +1,23 @@
+def debian_release_to_next(release)
+ releases = [
+ 'oldoldoldstable',
+ 'oldoldstable',
+ 'oldstable',
+ 'stable',
+ 'testing',
+ 'unstable',
+ 'experimental',
+ ]
+ if releases.include? release
+ if releases.index(release)+1 < releases.count
+ return releases[releases.index(release)+1]
+ end
+ end
+end
+
+Facter.add(:debian_nextrelease) do
+ confine :operatingsystem => 'Debian'
+ setcode do
+ debian_release_to_next(Facter.value('debian_release'))
+ end
+end
diff --git a/lib/facter/debian_release.rb b/lib/facter/debian_release.rb
new file mode 100644
index 0000000..09e8eef
--- /dev/null
+++ b/lib/facter/debian_release.rb
@@ -0,0 +1,36 @@
+begin
+ require 'facter/util/debian'
+end
+
+def debian_codename_to_release(codename)
+ stable = Facter::Util::Debian::STABLE
+ versions = Facter::Util::Debian::CODENAMES.invert
+ release = nil
+ if codename == "sid"
+ release = "unstable"
+ elsif versions.has_key? codename
+ version = versions[codename].to_i
+ if version == stable
+ release = "stable"
+ elsif version < stable
+ release = "stable"
+ for i in version..stable - 1
+ release = "old" + release
+ end
+ elsif version == stable + 1
+ release = "testing"
+ end
+ end
+ if release.nil?
+ Facter.warn("Could not determine release from codename #{codename}!")
+ end
+ return release
+end
+
+Facter.add(:debian_release) do
+ has_weight 99
+ confine :operatingsystem => 'Debian'
+ setcode do
+ debian_codename_to_release(Facter.value('debian_codename'))
+ end
+end
diff --git a/lib/facter/ubuntu_codename.rb b/lib/facter/ubuntu_codename.rb
new file mode 100644
index 0000000..814fd94
--- /dev/null
+++ b/lib/facter/ubuntu_codename.rb
@@ -0,0 +1,8 @@
+Facter.add(:ubuntu_codename) do
+ confine :operatingsystem => 'Ubuntu'
+ setcode do
+ Facter.value('lsbdistcodename')
+ end
+end
+
+
diff --git a/lib/facter/ubuntu_nextcodename.rb b/lib/facter/ubuntu_nextcodename.rb
new file mode 100644
index 0000000..38b64ad
--- /dev/null
+++ b/lib/facter/ubuntu_nextcodename.rb
@@ -0,0 +1,18 @@
+begin
+ require 'facter/util/ubuntu'
+end
+
+def ubuntu_codename_to_next(codename)
+ codenames = Facter::Util::Ubuntu::CODENAMES
+ i = codenames.index(codename)
+ if i and i+1 < codenames.count
+ return codenames[i+1]
+ end
+end
+
+Facter.add(:ubuntu_nextcodename) do
+ confine :operatingsystem => 'Ubuntu'
+ setcode do
+ ubuntu_codename_to_next(Facter.value('ubuntu_codename'))
+ end
+end
diff --git a/lib/facter/util/debian.rb b/lib/facter/util/debian.rb
new file mode 100644
index 0000000..290c17b
--- /dev/null
+++ b/lib/facter/util/debian.rb
@@ -0,0 +1,18 @@
+module Facter
+ module Util
+ module Debian
+ STABLE = 8
+ CODENAMES = {
+ "5" => "lenny",
+ "6" => "squeeze",
+ "7" => "wheezy",
+ "8" => "jessie",
+ "9" => "stretch",
+ "10" => "buster",
+ }
+ LTS = [
+ "squeeze",
+ ]
+ end
+ end
+end
diff --git a/lib/facter/util/ubuntu.rb b/lib/facter/util/ubuntu.rb
new file mode 100644
index 0000000..1b2411a
--- /dev/null
+++ b/lib/facter/util/ubuntu.rb
@@ -0,0 +1,20 @@
+module Facter
+ module Util
+ module Ubuntu
+ CODENAMES = [
+ "lucid",
+ "maverick",
+ "natty",
+ "oneiric",
+ "precise",
+ "quantal",
+ "raring",
+ "saucy",
+ "trusty",
+ "utopic",
+ "vivid",
+ "wily",
+ ]
+ end
+ end
+end