pin.pp 2.4 KB

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