2011-03-02 17:37:15 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2012-02-08 21:23:49 +00:00
|
|
|
# 2011-2012 Nico Schottelius (nico-cdist at schottelius.org)
|
2011-03-02 17:37:15 +00:00
|
|
|
#
|
|
|
|
# This file is part of cdist.
|
|
|
|
#
|
|
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# cdist is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Manage packages on Debian and co.
|
|
|
|
#
|
|
|
|
|
2011-03-02 17:54:31 +00:00
|
|
|
if [ -f "$__object/parameter/name" ]; then
|
2011-03-03 07:28:24 +00:00
|
|
|
name="$(cat "$__object/parameter/name")"
|
2011-03-02 17:54:31 +00:00
|
|
|
else
|
|
|
|
name="$__object_id"
|
|
|
|
fi
|
|
|
|
|
2012-01-16 17:04:15 +00:00
|
|
|
state_should="$(cat "$__object/parameter/state")"
|
2012-02-08 21:23:49 +00:00
|
|
|
|
|
|
|
# Correct pre 2.1 naming - FIXME in 2.1
|
|
|
|
case "$state_should" in
|
|
|
|
installed) state_should="present" ;;
|
|
|
|
removed) state_should="absent" ;;
|
|
|
|
esac
|
|
|
|
|
2012-01-16 17:04:15 +00:00
|
|
|
state_is="$(cat "$__object/explorer/pkg_status")"
|
|
|
|
case "$state_is" in
|
2012-02-08 21:23:49 +00:00
|
|
|
present*)
|
2012-01-16 17:04:15 +00:00
|
|
|
name="$(echo "$state_is" | cut -d ' ' -f 2)"
|
2012-02-08 21:23:49 +00:00
|
|
|
state_is="present"
|
2012-01-16 17:04:15 +00:00
|
|
|
;;
|
|
|
|
esac
|
2011-03-03 08:12:55 +00:00
|
|
|
|
2011-04-01 11:12:00 +00:00
|
|
|
aptget="DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes"
|
|
|
|
|
2012-01-16 17:04:15 +00:00
|
|
|
if [ "$state_is" != "$state_should" ]; then
|
|
|
|
case "$state_should" in
|
2012-02-08 21:23:49 +00:00
|
|
|
present)
|
2011-04-01 11:12:00 +00:00
|
|
|
echo $aptget install \"$name\"
|
2012-01-16 17:04:15 +00:00
|
|
|
;;
|
2012-02-08 21:23:49 +00:00
|
|
|
absent)
|
2011-04-01 11:12:00 +00:00
|
|
|
echo $aptget remove \"$name\"
|
2012-01-16 17:04:15 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown state: $state" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|