pin.pp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # pin.pp
  2. # pin a release in apt, useful for unstable repositories
  3. define apt::pin(
  4. $ensure = present,
  5. $explanation = "${caller_module_name}: ${name}",
  6. $order = '',
  7. $packages = '*',
  8. $priority = 0,
  9. $release = '', # a=
  10. $origin = '',
  11. $version = '',
  12. $codename = '', # n=
  13. $release_version = '', # v=
  14. $component = '', # c=
  15. $originator = '', # o=
  16. $label = '' # l=
  17. ) {
  18. include apt::params
  19. $preferences_d = $apt::params::preferences_d
  20. if $order != '' and !is_integer($order) {
  21. fail('Only integers are allowed in the apt::pin order param')
  22. }
  23. $pin_release_array = [
  24. $release,
  25. $codename,
  26. $release_version,
  27. $component,
  28. $originator,
  29. $label]
  30. $pin_release = join($pin_release_array, '')
  31. # Read the manpage 'apt_preferences(5)', especially the chapter
  32. # 'The Effect of APT Preferences' to understand the following logic
  33. # and the difference between specific and general form
  34. if is_array($packages) {
  35. $packages_string = join($packages, ' ')
  36. } else {
  37. $packages_string = $packages
  38. }
  39. if $packages_string != '*' { # specific form
  40. if ( $pin_release != '' and ( $origin != '' or $version != '' )) or
  41. ( $version != '' and ( $pin_release != '' or $origin != '' )) {
  42. fail('parameters release, origin, and version are mutually exclusive')
  43. }
  44. } else { # general form
  45. if $version != '' {
  46. fail('parameter version cannot be used in general form')
  47. }
  48. if ( $pin_release != '' and $origin != '' ) {
  49. fail('parameters release and origin are mutually exclusive')
  50. }
  51. }
  52. # According to man 5 apt_preferences:
  53. # The files have either no or "pref" as filename extension
  54. # and only contain alphanumeric, hyphen (-), underscore (_) and period
  55. # (.) characters. Otherwise APT will print a notice that it has ignored a
  56. # file, unless that file matches a pattern in the
  57. # Dir::Ignore-Files-Silently configuration list - in which case it will
  58. # be silently ignored.
  59. $file_name = regsubst($title, '[^0-9a-z\-_\.]', '_', 'IG')
  60. $path = $order ? {
  61. '' => "${preferences_d}/${file_name}.pref",
  62. default => "${preferences_d}/${order}-${file_name}.pref",
  63. }
  64. file { "${file_name}.pref":
  65. ensure => $ensure,
  66. path => $path,
  67. owner => root,
  68. group => root,
  69. mode => '0644',
  70. content => template('apt/pin.pref.erb'),
  71. }
  72. }