pin.pp 2.4 KB

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