(MODULES-3414) Limit non-strict parsing to pre-3.5.0 only
[puppet-modules/puppetlabs-apt.git] / manifests / params.pp
index e3cc8252f99ab34127b221080f5d7b2ffa80cdc0..ea1087e7a93655e371cb99c1d039a0f64c5016ef 100644 (file)
@@ -1,39 +1,33 @@
 class apt::params {
 
-  if defined('$caller_module_name') and $caller_module_name and $caller_module_name != $module_name {
-    fail('apt::params is a private class and cannot be accessed directly')
-  }
-
   if $::osfamily != 'Debian' {
     fail('This module only works on Debian or derivatives like Ubuntu')
   }
 
-  # Strict variables facts lookup compatibility
-  $xfacts = {
-    'lsbdistcodename' => defined('$lsbdistcodename') ? {
-      true    => $::lsbdistcodename,
-      default => undef,
-    },
-    'lsbdistrelease' => defined('$lsbdistrelease') ? {
-      true    => $::lsbdistrelease,
-      default => undef,
-    },
-    'lsbmajdistrelease' => defined('$lsbmajdistrelease') ? {
-      true    => $::lsbmajdistrelease,
-      default => undef,
-    },
-    'lsbdistdescription' => defined('$lsbdistdescription') ? {
-      true    => $::lsbdistdescription,
-      default => undef,
-    },
-    'lsbminordistrelease' => defined('$lsbminordistrelease') ? {
-      true    => $::lsbminordistrelease,
-      default => undef,
-    },
-    'lsbdistid' => defined('$lsbdistid') ? {
-      true    => $::lsbdistid,
-      default => undef,
-    },
+  # prior to puppet 3.5.0, defined() couldn't test if a variable was defined.
+  # strict_variables wasn't added until 3.5.0, so this should be fine.
+  if $::puppetversion and versioncmp($::puppetversion, '3.5.0') < 0 {
+    $xfacts = {
+      'lsbdistcodename'     => $::lsbdistcodename,
+      'lsbdistrelease'      => $::lsbdistrelease,
+      'lsbdistid'           => $::lsbdistid,
+    }
+  } else {
+    # Strict variables facts lookup compatibility
+    $xfacts = {
+      'lsbdistcodename' => defined('$lsbdistcodename') ? {
+        true    => $::lsbdistcodename,
+        default => undef,
+      },
+      'lsbdistrelease' => defined('$lsbdistrelease') ? {
+        true    => $::lsbdistrelease,
+        default => undef,
+      },
+      'lsbdistid' => defined('$lsbdistid') ? {
+        true    => $::lsbdistid,
+        default => undef,
+      },
+    }
   }
 
   $root           = '/etc/apt'
@@ -52,7 +46,7 @@ class apt::params {
     },
     'pref'   => {
       'path' => $preferences_d,
-      'ext'  => '',
+      'ext'  => '.pref',
     },
     'list'   => {
       'path' => $sources_list_d,
@@ -61,23 +55,23 @@ class apt::params {
   }
 
   $update_defaults = {
-    'always'    => false,
     'frequency' => 'reluctantly',
     'timeout'   => undef,
     'tries'     => undef,
   }
 
   $proxy_defaults = {
-    'host'  => undef,
-    'port'  => 8080,
-    'https' => false,
+    'ensure' => undef,
+    'host'   => undef,
+    'port'   => 8080,
+    'https'  => false,
   }
 
   $purge_defaults = {
-    'sources.list'   => true,
-    'sources.list.d' => true,
-    'preferences'    => true,
-    'preferences.d'  => true,
+    'sources.list'   => false,
+    'sources.list.d' => false,
+    'preferences'    => false,
+    'preferences.d'  => false,
   }
 
   $source_key_defaults = {
@@ -93,56 +87,56 @@ class apt::params {
   }
 
   case $xfacts['lsbdistid'] {
-    'ubuntu', 'debian': {
-      $distid = $xfacts['lsbdistid']
-      $distcodename = $xfacts['lsbdistcodename']
-    }
-    'linuxmint': {
-      if $xfacts['lsbdistcodename'] == 'debian' {
-        $distid = 'debian'
-        $distcodename = 'wheezy'
-      } else {
-        $distid = 'ubuntu'
-        $distcodename = $xfacts['lsbdistcodename'] ? {
-          'qiana'  => 'trusty',
-          'petra'  => 'saucy',
-          'olivia' => 'raring',
-          'nadia'  => 'quantal',
-          'maya'   => 'precise',
+    'debian': {
+      case $xfacts['lsbdistcodename'] {
+        'squeeze': {
+          $backports = {
+            'location' => 'http://httpredir.debian.org/debian-backports',
+            'key'      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+            'repos'    => 'main contrib non-free',
+          }
+        }
+        default: {
+          $backports = {
+            'location' => 'http://httpredir.debian.org/debian',
+            'key'      => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
+            'repos'    => 'main contrib non-free',
+          }
         }
       }
+
+      $ppa_options = undef
+      $ppa_package = undef
+
     }
-    undef: {
-      fail('Unable to determine lsbdistid, is lsb-release installed?')
-    }
-    default: {
-      fail("Unsupported lsbdistid (${::lsbdistid})")
-    }
-  }
-  case $distid {
     'ubuntu': {
-      case $distcodename {
-        'lucid': {
+      $backports = {
+        'location' => 'http://archive.ubuntu.com/ubuntu',
+        'key'      => '630239CC130E1A7FD81A27B140976EAF437D05B5',
+        'repos'    => 'main universe multiverse restricted',
+      }
+
+      if $xfacts['lsbdistcodename'] == 'lucid' {
           $ppa_options        = undef
           $ppa_package        = 'python-software-properties'
-        }
-        'precise': {
+      } elsif $xfacts['lsbdistcodename'] == 'precise' {
           $ppa_options        = '-y'
           $ppa_package        = 'python-software-properties'
-        }
-        'trusty', 'utopic', 'vivid': {
+      } elsif versioncmp($xfacts['lsbdistrelease'], '14.04') >= 0 {
           $ppa_options        = '-y'
           $ppa_package        = 'software-properties-common'
-        }
-        default: {
+      } else {
           $ppa_options        = '-y'
-          $ppa_package        = 'software-properties-common'
-        }
+          $ppa_package        = 'python-software-properties'
       }
     }
-    '', default: {
+    undef: {
+      fail('Unable to determine lsbdistid, please install lsb-release first')
+    }
+    default: {
       $ppa_options = undef
       $ppa_package = undef
+      $backports   = undef
     }
   }
 }