__package_zypper can now handle the version parameter

This commit is contained in:
Daniel Heule 2013-12-11 17:11:22 +01:00
parent 785e54b311
commit aaa142d76b
4 changed files with 50 additions and 23 deletions

View file

@ -19,7 +19,7 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>. # along with cdist. If not, see <http://www.gnu.org/licenses/>.
# #
# #
# Retrieve the status of a package off different types # Retrieve the status of a package of different types
# #
if [ -f "$__object/parameter/name" ]; then if [ -f "$__object/parameter/name" ]; then

View file

@ -29,42 +29,59 @@
globalopts="--quiet --non-interactive" globalopts="--quiet --non-interactive"
if [ -f "$__object/parameter/name" ]; then if [ -f "$__object/parameter/name" ]; then
name="$__object/parameter/name" name="$__object/parameter/name"
else else
name="$__object_id" name="$__object_id"
fi fi
if [ -f "$__object/parameter/state" ]; then if [ -f "$__object/parameter/state" ]; then
state_should="$(cat "$__object/parameter/state")" state_should="$(cat "$__object/parameter/state")"
else else
state_should="present" state_should="present"
fi fi
if [ -f "$__object/parameter/ptype" ]; then if [ -f "$__object/parameter/ptype" ]; then
ptype="$(cat "$__object/parameter/ptype")" ptype="$(cat "$__object/parameter/ptype")"
else else
ptype="package" ptype="package"
fi
if [ -f "$__object/parameter/version" ]; then
version_should="$(cat "$__object/parameter/version")"
if [ "$ptype" != "package" ]; then
echo "version support only for type package implemented" >&2
exit 2
fi
else
version_should=""
fi fi
pkg_version="$(cat "$__object/explorer/pkg_version")" pkg_version="$(cat "$__object/explorer/pkg_version")"
if [ -z "$pkg_version" ]; then if [ -z "$pkg_version" ]; then
state_is="absent" state_is="absent"
version_is=""
else else
state_is="present" state_is="present"
version_is=${pkg_version##* }
fi fi
# Exit if nothing is needed to be done
[ "$state_is" = "$state_should" ] && exit 0
case "$state_should" in case "$state_should" in
present) present)
echo zypper $globalopts install --type \"$ptype\" --auto-agree-with-licenses \"$name\" ">/dev/null" if [ -z "$version_should" ]; then
;; [ "$state_is" = "present" ] && exit 0 # if state is present, we dont need to do anything
absent) echo zypper $globalopts install --type \"$ptype\" --auto-agree-with-licenses \"$name\" ">/dev/null"
echo zypper $globalopts remove --type \"$ptype\" \"$name\" ">/dev/null" else
;; [ "$state_is" = "present" ] && [ "$version_should" = "$version_is" ] && exit 0 # if state is present and version is correct, we dont need to do anything
*) echo zypper $globalopts install --oldpackage --type \"$ptype\" --auto-agree-with-licenses \"$name\" = \"$version_should\" ">/dev/null"
echo "Unknown state: $state_should" >&2 fi
exit 1 ;;
;; absent)
[ "$state_is" = "absent" ] && exit 0 # if state is absent, we dont need to do anything
echo zypper $globalopts remove --type \"$ptype\" \"$name\" ">/dev/null"
;;
*)
echo "Unknown state: $state_should" >&2
exit 1
;;
esac esac

View file

@ -1,6 +1,6 @@
cdist-type__package_zypper(7) cdist-type__package_zypper(7)
============================= =============================
Nico Schottelius <nico-cdist--@--schottelius.org> Daniel Heule <hda--@--sfs.biz>
NAME NAME
@ -26,6 +26,11 @@ name::
state:: state::
Either "present" or "absent", defaults to "present" Either "present" or "absent", defaults to "present"
version::
The version of the package to install. Default is to install the version
choosen by the local package manager. For a list of version have a look to
the output of "zypper se -s packagename"
ptype:: ptype::
Either "package", "patch", "pattern", "product" or "srcpackage", defaults to "package". For a description see man zypper. Either "package", "patch", "pattern", "product" or "srcpackage", defaults to "package". For a description see man zypper.
@ -34,12 +39,15 @@ EXAMPLES
-------- --------
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
# Ensure zsh in installed # Ensure zsh is installed
__package_zypper zsh --state present __package_zypper zsh --state present
# If you don't want to follow pythonX packages, but always use python # If you don't want to follow pythonX packages, but always use python
__package_zypper python --state present --name python2 __package_zypper python --state present --name python2
# Ensure binutils is installed and the version is forced to be 2.23.1-0.19.2
__package_zypper binutils --state present --version 2.23.1-0.19.2
# Remove package # Remove package
__package_zypper cfengine --state absent __package_zypper cfengine --state absent
@ -56,5 +64,6 @@ SEE ALSO
COPYING COPYING
------- -------
Copyright \(C) 2012 Nico Schottelius. Free use of this software is Copyright \(C) 2012 Nico Schottelius.
granted under the terms of the GNU General Public License version 3 (GPLv3). Copyright \(C) 2013 Daniel Heule.
Free use of this software is granted under the terms of the GNU General Public License version 3 (GPLv3).

View file

@ -1,3 +1,4 @@
name name
state state
ptype ptype
version