From 1713a70428427b8d33a7c223cfed8943f8332e78 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 9 Feb 2012 19:06:13 +0100 Subject: [PATCH] begin changes to __package_luarocks and __package_pkg_openbsd Signed-off-by: Nico Schottelius --- conf/type/__package_apt/gencode-remote | 1 - conf/type/__package_luarocks/gencode-remote | 2 +- .../type/__package_pkg_openbsd/gencode-remote | 73 ++++++++++++------- 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/conf/type/__package_apt/gencode-remote b/conf/type/__package_apt/gencode-remote index 32049a27..47e76ec8 100755 --- a/conf/type/__package_apt/gencode-remote +++ b/conf/type/__package_apt/gencode-remote @@ -31,7 +31,6 @@ state_should="$(cat "$__object/parameter/state")" # Correct pre 2.1 naming - FIXME in 2.1 case "$state_should" in - # FIXME: print warning to stderr! installed) echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 state_should="present" diff --git a/conf/type/__package_luarocks/gencode-remote b/conf/type/__package_luarocks/gencode-remote index 179022b1..29fd7e38 100755 --- a/conf/type/__package_luarocks/gencode-remote +++ b/conf/type/__package_luarocks/gencode-remote @@ -29,7 +29,7 @@ else name="$__object_id" fi -state="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" is_installed="$(grep "(installed)" "$__object/explorer/pkg_status" || true)" case "$state" in diff --git a/conf/type/__package_pkg_openbsd/gencode-remote b/conf/type/__package_pkg_openbsd/gencode-remote index eee2a3d9..e8309f20 100755 --- a/conf/type/__package_pkg_openbsd/gencode-remote +++ b/conf/type/__package_pkg_openbsd/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2011 Andi Brönnimann (andi-cdist at v-net.ch) +# 2012 Nico Schottelius (nico-cdist at schottelius.org) # # This file is part of cdist. # @@ -42,44 +43,60 @@ else name="$__object_id" fi -state="$(cat "$__object/parameter/state")" +state_should="$(cat "$__object/parameter/state")" +# Correct pre 2.1 naming - FIXME in 2.1 +case "$state_should" in + installed) + echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + state_should="present" + ;; + removed) + echo "WARNING: $state_should is deprecated, please change to present/absent (will be removed in cdist 2.1)" >&2 + state_should="absent" + ;; +esac + pkg_version="$(cat "$__object/explorer/pkg_version")" # TODO: Shouldn't be hardcoded echo export PKG_PATH=ftp://ftp.openbsd.org/pub/OpenBSD/$os_version/packages/$machine/ -case "$state" in - installed) - # Empty? Not installed. - if [ -z "$pkg_version" ]; then - # use this because pkg_add doesn't properly handle errors - cat << eof - status=\$(pkg_add "$pkgopts" "$name--$flavor") +if [ "$pkg_version" ]; then + state_is="present" +else + state_is="absent" +fi - # no error - if [ -n "\$status" ]; then - echo "Error: \$status" - exit 1 - fi -eof - fi - ;; - removed) - if [ "$pkg_version" ]; then - # use this because pkg_add doesn't properly handle errors - cat << eof - status=\$(pkg_delete "$pkgopts" "$name--$flavor") +[ "$state_is" = "$state_should" ] && exit 0 - # no error - if [ -n "\$status" ]; then - echo "Error: \$status" - exit 1 - fi +case "$state_should" in + present) + # use this because pkg_add doesn't properly handle errors + cat << eof +status=\$(pkg_add "$pkgopts" "$name--$flavor") + +# no error +if [ -n "\$status" ]; then + echo "Error: \$status" + exit 1 +fi +eof + ;; + + absent) + # use this because pkg_add doesn't properly handle errors + cat << eof +status=\$(pkg_delete "$pkgopts" "$name--$flavor") + +# no error +if [ -n "\$status" ]; then + echo "Error: \$status" + exit 1 +fi eof - fi ;; *) - echo "Unknown state: $state" >&2 + echo "Unknown state: $state_should" >&2 exit 1 ;; esac