--- trunk/mage/usr/lib/mage/mage4.functions.sh 2005/12/01 12:38:45 286 +++ trunk/mage/usr/lib/mage/mage4.functions.sh 2005/12/04 11:54:15 294 @@ -1,6 +1,6 @@ #!/bin/bash # Magellan Linux Installer Functions (mage.functions.sh) -# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.10 2005-12-01 12:38:45 niro Exp $ +# $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mage4.functions.sh,v 1.11 2005-12-04 11:54:15 niro Exp $ mage_setup() { @@ -556,14 +556,18 @@ # abort if mage file not exists [ ! -f ${magefile} ] && die "remove_database_entry() ${magefile} not exist." - # first unregister virtuals - provide="$(get_value_from_magefile PROVIDE ${magefile})" - if [ -n "${provide}" ] + # remove virtuals only if no other exist + if [[ $(count_installed_pkgs --pcat ${pcat} --pname ${pname}) -le 1 ]] then - for i in ${provide} - do - virtuals_del "${i}" "${pcat}/${pname}" - done + # first unregister virtuals + provide="$(get_value_from_magefile PROVIDE ${magefile})" + if [ -n "${provide}" ] + then + for i in ${provide} + do + virtuals_del "${i}" "${pcat}/${pname}" + done + fi fi # removes database entry @@ -573,6 +577,39 @@ fi } +# get the number of installed packages +count_installed_pkgs() +{ + local pcat + local pname + local pkg + local i + + # very basic getops + for i in $* + do + case $1 in + --pcat|-c) shift; pcat="$1" ;; + --pname|-n) shift; pname="$1" ;; + esac + shift + done + + # sanity checks; abort if not given + [ -z "${pcat}" ] && die "pkg_count() \$pcat not given." + [ -z "${pname}" ] && die "pkg_count() \$pname not given." + + declare -i i=0 + for pkg in $(get_uninstall_candidates --pcat ${pcat} --pname ${pname}) + do + (( i++ )) + #echo "$i ${pkg}" + done + + # return the value + echo "${i}" +} + ################################################### # function compare_mtime #