aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/debian_codename.rb42
-rw-r--r--lib/facter/debian_lts.rb16
-rw-r--r--lib/facter/debian_nextcodename.rb23
-rw-r--r--lib/facter/debian_nextrelease.rb23
-rw-r--r--lib/facter/debian_release.rb38
-rw-r--r--lib/facter/ubuntu_codename.rb8
-rw-r--r--lib/facter/ubuntu_nextcodename.rb20
-rw-r--r--lib/facter/util/debian.rb18
-rw-r--r--lib/facter/util/ubuntu.rb21
-rw-r--r--lib/puppet/parser/functions/debian_nextcodename.rb13
-rw-r--r--lib/puppet/parser/functions/debian_nextrelease.rb11
-rw-r--r--lib/puppet/parser/functions/debian_release.rb12
-rw-r--r--lib/puppet/parser/functions/debian_release_version.rb11
13 files changed, 209 insertions, 47 deletions
diff --git a/lib/facter/debian_codename.rb b/lib/facter/debian_codename.rb
new file mode 100644
index 0000000..254877a
--- /dev/null
+++ b/lib/facter/debian_codename.rb
@@ -0,0 +1,42 @@
+begin
+ require 'facter/util/debian'
+rescue LoadError
+ require "#{File.dirname(__FILE__)}/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
diff --git a/lib/facter/debian_lts.rb b/lib/facter/debian_lts.rb
new file mode 100644
index 0000000..f53a9eb
--- /dev/null
+++ b/lib/facter/debian_lts.rb
@@ -0,0 +1,16 @@
+begin
+ require 'facter/util/debian'
+rescue LoadError
+ require "#{File.dirname(__FILE__)}/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..c4c569b
--- /dev/null
+++ b/lib/facter/debian_nextcodename.rb
@@ -0,0 +1,23 @@
+begin
+ require 'facter/util/debian'
+rescue LoadError
+ require "#{File.dirname(__FILE__)}/util/debian"
+end
+
+def debian_codename_to_next(codename)
+ if codename == "sid"
+ return "experimental"
+ else
+ codenames = Facter::Util::Debian::CODENAMES
+ versions = Facter::Util::Debian::CODENAMES.invert
+ current_version = versions[codename]
+ return codenames[(current_version.to_i + 1).to_s]
+ 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..2c334cc
--- /dev/null
+++ b/lib/facter/debian_release.rb
@@ -0,0 +1,38 @@
+begin
+ require 'facter/util/debian'
+rescue LoadError
+ require "#{File.dirname(__FILE__)}/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..dcd1d42
--- /dev/null
+++ b/lib/facter/ubuntu_nextcodename.rb
@@ -0,0 +1,20 @@
+begin
+ require 'facter/util/ubuntu'
+rescue LoadError
+ require "#{File.dirname(__FILE__)}/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..52c15e8
--- /dev/null
+++ b/lib/facter/util/ubuntu.rb
@@ -0,0 +1,21 @@
+module Facter
+ module Util
+ module Ubuntu
+ CODENAMES = [
+ "lucid",
+ "maverick",
+ "natty",
+ "oneiric",
+ "precise",
+ "quantal",
+ "raring",
+ "saucy",
+ "trusty",
+ "utopic",
+ "vivid",
+ "wily",
+ "xenial"
+ ]
+ end
+ end
+end
diff --git a/lib/puppet/parser/functions/debian_nextcodename.rb b/lib/puppet/parser/functions/debian_nextcodename.rb
deleted file mode 100644
index 3d5c3bd..0000000
--- a/lib/puppet/parser/functions/debian_nextcodename.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-module Puppet::Parser::Functions
- newfunction(:debian_nextcodename, :type => :rvalue) do |args|
- case args[0]
- when "etch" then "lenny"
- when "lenny" then "squeeze"
- when "squeeze" then "wheezy"
- when "wheezy" then "jessie"
- when "jessie" then "sid"
- when "sid" then "experimental"
- else "sid"
- end
- end
-end
diff --git a/lib/puppet/parser/functions/debian_nextrelease.rb b/lib/puppet/parser/functions/debian_nextrelease.rb
deleted file mode 100644
index 76c3e0d..0000000
--- a/lib/puppet/parser/functions/debian_nextrelease.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module Puppet::Parser::Functions
- newfunction(:debian_nextrelease, :type => :rvalue) do |args|
- case args[0]
- when 'oldstable' then 'stable'
- when 'stable' then 'testing'
- when 'testing' then 'unstable'
- when 'unstable' then 'experimental'
- else 'unstable'
- end
- end
-end
diff --git a/lib/puppet/parser/functions/debian_release.rb b/lib/puppet/parser/functions/debian_release.rb
deleted file mode 100644
index d7b6718..0000000
--- a/lib/puppet/parser/functions/debian_release.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-module Puppet::Parser::Functions
- newfunction(:debian_release, :type => :rvalue) do |args|
- case args[0]
- when 'squeeze' then 'oldstable'
- when 'wheezy' then 'stable'
- when 'jessie' then 'testing'
- when 'sid' then 'unstable'
- when 'experimental' then 'experimental'
- else 'testing'
- end
- end
-end
diff --git a/lib/puppet/parser/functions/debian_release_version.rb b/lib/puppet/parser/functions/debian_release_version.rb
deleted file mode 100644
index 0abe90e..0000000
--- a/lib/puppet/parser/functions/debian_release_version.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module Puppet::Parser::Functions
- newfunction(:debian_release_version, :type => :rvalue) do |args|
- case args[0]
- when 'etch' then '4.0'
- when 'lenny' then '5.0'
- when 'squeeze' then '6.0'
- when 'wheezy' then '7.0'
- else ''
- end
- end
-end