X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=manifests%2Fmark.pp;h=08e396c02f1e28fe93e0bedca97b2f08eef395f6;hb=c01f2ca5353853db87279ae4410a58b560f0adef;hp=dfad6b83d9ee96bee41e40cd382f435078533778;hpb=d55aec700c02c14e44f74b68ef6629ba43158363;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/manifests/mark.pp b/manifests/mark.pp index dfad6b8..08e396c 100644 --- a/manifests/mark.pp +++ b/manifests/mark.pp @@ -8,17 +8,31 @@ define apt::mark ( Enum['auto','manual','hold','unhold'] $setting, ) { - case $setting { - 'unhold': { - $unless_cmd = undef - } - default: { - $unless_cmd = "/usr/bin/apt-mark show${setting} ${title} | /bin/fgrep -qs ${title}" - } + if $title !~ /^[a-zA-Z0-9\-_]+$/ { + fail("Invalid package name: ${title}") } - exec { "/usr/bin/apt-mark ${setting} ${title}": - onlyif => "/usr/bin/dpkg -l ${title}", - unless => $unless_cmd, + + 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, + } +}