Fix is_package_installed() check with dpkg

is_package_installed() incorrectly returned '0' for packages that
had 'un' status in the dpkg database.

Change-Id: I81b77486c2ed7717ed81cb2c2572fe6c4b394ffc
This commit is contained in:
Dean Troyer 2013-08-27 17:06:14 -05:00
parent 8db8f38c65
commit 04762cd823
2 changed files with 46 additions and 4 deletions

View File

@ -317,16 +317,36 @@ function get_packages() {
continue
fi
# Assume we want this package
package=${line%#*}
inst_pkg=1
# Look for # dist:xxx in comment
if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then
# We are using BASH regexp matching feature.
package=${BASH_REMATCH[1]}
distros=${BASH_REMATCH[2]}
# In bash ${VAR,,} will lowecase VAR
[[ ${distros,,} =~ ${DISTRO,,} ]] && echo $package
continue
# Look for a match in the distro list
if [[ ! ${distros,,} =~ ${DISTRO,,} ]]; then
# If no match then skip this package
inst_pkg=0
fi
fi
echo ${line%#*}
# Look for # testonly in comment
if [[ $line =~ (.*)#.*testonly.* ]]; then
package=${BASH_REMATCH[1]}
# Are we installing test packages? (test for the default value)
if [[ $INSTALL_TESTONLY_PACKAGES = "False" ]]; then
# If not installing test packages the skip this package
inst_pkg=0
fi
fi
if [[ $inst_pkg = 1 ]]; then
echo $package
fi
done
IFS=$OIFS
done
@ -912,7 +932,7 @@ function is_package_installed() {
fi
if [[ "$os_PACKAGE" = "deb" ]]; then
dpkg -l "$@" > /dev/null 2> /dev/null
dpkg -s "$@" > /dev/null 2> /dev/null
elif [[ "$os_PACKAGE" = "rpm" ]]; then
rpm --quiet -q "$@"
else

View File

@ -367,3 +367,25 @@ if [[ "$VAL" -ne 0 ]]; then
else
echo "is_package_installed() on non-existing package failed"
fi
# test against removed package...was a bug on Ubuntu
if is_ubuntu; then
PKG=cowsay
if ! (dpkg -s $PKG >/dev/null 2>&1); then
# it was never installed...set up the condition
sudo apt-get install -y cowsay >/dev/null 2>&1
fi
if (dpkg -s $PKG >/dev/null 2>&1); then
# remove it to create the 'un' status
sudo dpkg -P $PKG >/dev/null 2>&1
fi
# now test the installed check on a deleted package
is_package_installed $PKG
VAL=$?
if [[ "$VAL" -ne 0 ]]; then
echo "OK"
else
echo "is_package_installed() on deleted package failed"
fi
fi