2 # pin a release in apt, useful for unstable repositories
5 Optional[Enum['file', 'present', 'absent']] $ensure = present,
6 Optional[String] $explanation = undef,
7 Variant[Integer] $order = 50,
8 Variant[String, Array] $packages = '*',
9 Variant[Numeric, String] $priority = 0,
10 Optional[String] $release = '', # a=
11 Optional[String] $origin = '',
12 Optional[String] $version = '',
13 Optional[String] $codename = '', # n=
14 Optional[String] $release_version = '', # v=
15 Optional[String] $component = '', # c=
16 Optional[String] $originator = '', # o=
17 Optional[String] $label = '', # l=
21 $_explanation = $explanation
23 if defined('$caller_module_name') { # strict vars check
24 $_explanation = "${caller_module_name}: ${name}"
26 $_explanation = ": ${name}"
30 $pin_release_array = [
38 $pin_release = join($pin_release_array, '')
40 # Read the manpage 'apt_preferences(5)', especially the chapter
41 # 'The Effect of APT Preferences' to understand the following logic
42 # and the difference between specific and general form
43 if is_array($packages) {
44 $packages_string = join($packages, ' ')
46 $packages_string = $packages
49 if $packages_string != '*' { # specific form
50 if ( $pin_release != '' and ( $origin != '' or $version != '' )) or
51 ( $version != '' and ( $pin_release != '' or $origin != '' )) {
52 fail('parameters release, origin, and version are mutually exclusive')
54 } else { # general form
56 fail('parameter version cannot be used in general form')
58 if ( $pin_release != '' and $origin != '' ) {
59 fail('parameters release and origin are mutually exclusive')
63 # According to man 5 apt_preferences:
64 # The files have either no or "pref" as filename extension
65 # and only contain alphanumeric, hyphen (-), underscore (_) and period
66 # (.) characters. Otherwise APT will print a notice that it has ignored a
67 # file, unless that file matches a pattern in the
68 # Dir::Ignore-Files-Silently configuration list - in which case it will
69 # be silently ignored.
70 $file_name = regsubst($title, '[^0-9a-z\-_\.]', '_', 'IG')
72 $headertmp = epp('apt/_header.epp')
74 $pinpreftmp = epp('apt/pin.pref.epp', {
76 'pin_release' => $pin_release,
77 'release' => $release,
78 'codename' => $codename,
79 'release_version' => $release_version,
80 'component' => $component,
81 'originator' => $originator,
83 'version' => $version,
85 'explanation' => $_explanation,
86 'packages_string' => $packages_string,
87 'priority' => $priority,
90 apt::setting { "pref-${file_name}":
93 content => "${headertmp}${pinpreftmp}",
94 notify_update => false,