implemented some sugestions from nico

This commit is contained in:
Daniel Heule 2014-09-29 17:28:45 +02:00
parent 9bac6da6c9
commit c70834eaff
3 changed files with 12 additions and 14 deletions

View file

@ -27,36 +27,32 @@ else
name="$__object_id" name="$__object_id"
fi fi
if [ -f "$__object/parameter/state" ]; then state_should="$(cat "$__object/parameter/state")"
state_should="$(cat "$__object/parameter/state")"
else
state_should="present"
fi
if [ -f "$__object/parameter/version" ]; then version="$(cat "$__object/parameter/version")"
version="$(cat "$__object/parameter/version")"
else
version=""
fi
if [ ! -z "$version" ]; then if [ -n "$version" ]; then
name="=$name-$version" name="=$name-$version"
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"
elif [ ! -z "$version" -a $(echo "$pkg_version" | wc -l) -gt 1 ]; then elif [ -z "$version" -a $(echo "$pkg_version" | wc -l) -gt 1 ]; then
echo "Package name is not unique! The following packages are installed:" echo "Package name is not unique! The following packages are installed:"
echo "$pkg_version" echo "$pkg_version"
exit 1 exit 1
elif [ -z "$version" -a $(echo "$pkg_version" | cut -d " " -f 1 | sort | uniq | wc -l) -gt 1 ]; then elif [ -n "$version" -a $(echo "$pkg_version" | cut -d " " -f 1 | sort | uniq | wc -l) -gt 1 ]; then
echo "Package name is not unique! The following packages are installed:" echo "Package name is not unique! The following packages are installed:"
echo "$pkg_version" echo "$pkg_version"
exit 1 exit 1
else else
state_is="present" state_is="present"
if [ -n "$version" ] && echo "$pkg_version" | cut -d " " -f 2 | grep -q -x "$version"; then
installed_version="$(echo "$pkg_version" | cut -d " " -f 2 | grep -x "$version")"
else
installed_version="$(echo "$pkg_version" | cut -d " " -f 2 | tail -n 1)" installed_version="$(echo "$pkg_version" | cut -d " " -f 2 | tail -n 1)"
fi
fi fi
@ -64,6 +60,7 @@ fi
[ "$state_is" = "$state_should" ] && ( [ -z "$version" ] || [ "$installed_version" = "$version" ] ) && exit 0 [ "$state_is" = "$state_should" ] && ( [ -z "$version" ] || [ "$installed_version" = "$version" ] ) && exit 0
[ "$state_should" = "absent" ] && [ ! -z "$version" ] && [ "$installed_version" != "$version" ] && exit 0 [ "$state_should" = "absent" ] && [ ! -z "$version" ] && [ "$installed_version" != "$version" ] && exit 0
case "$state_should" in case "$state_should" in
present) present)
echo "emerge \"$name\" &>/dev/null || exit 1" echo "emerge \"$name\" &>/dev/null || exit 1"

View file

@ -0,0 +1 @@
present