|
|
|
@ -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 |
|
|
|
|
|
|
|
|
|
[ "$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 |
|
|
|
|
fi |
|
|
|
|
;; |
|
|
|
|
removed) |
|
|
|
|
if [ "$pkg_version" ]; then |
|
|
|
|
# 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 |
|
|
|
|
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 |
|
|
|
|