From 602e57455db6f09d48bc2f578d89fb13b7cb0d6b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 8 Feb 2012 22:23:49 +0100 Subject: [PATCH] support absent/present in __package_apt Signed-off-by: Nico Schottelius --- conf/type/__package_apt/explorer/pkg_status | 8 ++++---- conf/type/__package_apt/gencode-remote | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/conf/type/__package_apt/explorer/pkg_status b/conf/type/__package_apt/explorer/pkg_status index dbb3af3e..04926b60 100755 --- a/conf/type/__package_apt/explorer/pkg_status +++ b/conf/type/__package_apt/explorer/pkg_status @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -28,11 +28,11 @@ else fi # Except dpkg failing, if package is not known / installed -packages="$(apt-cache showpkg "$name" | sed -e "1,/Reverse Provides:/d" | cut -d ' ' -f 1) $name" +packages="$(apt-cache showpkg "$name" | sed -e "1,/Reverse Provides:/d" | cut -d ' ' -f 1) $name" for p in $packages; do if [ -n "$(dpkg -s "$p" 2>/dev/null | grep "^Status: install ok installed$")" ]; then - echo "installed $p" + echo "present $p" exit 0 fi done -echo "removed" +echo absent diff --git a/conf/type/__package_apt/gencode-remote b/conf/type/__package_apt/gencode-remote index 594ab8cb..da58ca1b 100755 --- a/conf/type/__package_apt/gencode-remote +++ b/conf/type/__package_apt/gencode-remote @@ -1,6 +1,6 @@ #!/bin/sh # -# 2011 Nico Schottelius (nico-cdist at schottelius.org) +# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -28,11 +28,18 @@ else fi state_should="$(cat "$__object/parameter/state")" + +# Correct pre 2.1 naming - FIXME in 2.1 +case "$state_should" in + installed) state_should="present" ;; + removed) state_should="absent" ;; +esac + state_is="$(cat "$__object/explorer/pkg_status")" case "$state_is" in - installed*) + present*) name="$(echo "$state_is" | cut -d ' ' -f 2)" - state_is="installed" + state_is="present" ;; esac @@ -40,10 +47,10 @@ aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes" if [ "$state_is" != "$state_should" ]; then case "$state_should" in - installed) + present) echo $aptget install \"$name\" ;; - removed) + absent) echo $aptget remove \"$name\" ;; *) @@ -52,4 +59,3 @@ if [ "$state_is" != "$state_should" ]; then ;; esac fi -