File: mark.pp

package info (click to toggle)
puppet-module-puppetlabs-apt 9.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 572 kB
  • sloc: ruby: 438; sh: 31; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,350 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# @summary Manages apt-mark settings
#
# @param setting
#   auto, manual, hold, unhold
#   specifies the behavior of apt in case of no more dependencies installed
#   https://manpages.debian.org/stable/apt/apt-mark.8.en.html
#
define apt::mark (
  Enum['auto','manual','hold','unhold'] $setting,
) {
  if $title !~ /^[a-z0-9][a-z0-9.+\-]+$/ {
    fail("Invalid package name: ${title}")
  }

  if $setting == 'unhold' {
    $unless_cmd = undef
  } else {
    $action = "show${setting}"

    # It would be ideal if we could break out this command in to an array of args, similar
    # to $onlyif_cmd and $command. However, in this case it wouldn't work as expected due
    # to the inclusion of a pipe character.
    # When passed to the exec function, the posix provider will strip everything to the right of the pipe,
    # causing the command to return a full list of packages for the given action.
    # The trade off is to use an interpolated string knowing that action is built from an enum value and
    # title is pre-validated.
    $unless_cmd = ["/usr/bin/apt-mark ${action} ${title} | grep ${title} -q"]
  }

  $onlyif_cmd = [['/usr/bin/dpkg', '-l', $title]]
  $command = ['/usr/bin/apt-mark', $setting, $title]

  exec { "apt-mark ${setting} ${title}":
    command => $command,
    onlyif  => $onlyif_cmd,
    unless  => $unless_cmd,
  }
}