1 # @summary Manages apt-mark settings
4 # auto, manual, hold, unhold
5 # specifies the behavior of apt in case of no more dependencies installed
6 # https://manpages.debian.org/stable/apt/apt-mark.8.en.html
9 Enum['auto','manual','hold','unhold'] $setting,
11 if $title !~ /^[a-zA-Z0-9\-_\.]+$/ {
12 fail("Invalid package name: ${title}")
15 if $setting == 'unhold' {
18 $action = "show${setting}"
20 # It would be ideal if we could break out this command in to an array of args, similar
21 # to $onlyif_cmd and $command. However, in this case it wouldn't work as expected due
22 # to the inclusion of a pipe character.
23 # When passed to the exec function, the posix provider will strip everything to the right of the pipe,
24 # causing the command to return a full list of packages for the given action.
25 # The trade off is to use an interpolated string knowing that action is built from an enum value and
26 # title is pre-validated.
27 $unless_cmd = ["/usr/bin/apt-mark ${action} ${title} | grep ${title} -q"]
30 $onlyif_cmd = [['/usr/bin/dpkg', '-l', $title]]
31 $command = ['/usr/bin/apt-mark', $setting, $title]
33 exec { "apt-mark ${setting} ${title}":
35 onlyif => $onlyif_cmd,
36 unless => $unless_cmd,