is_package_installed() incorrectly returned '0' for packages that
had 'un' status in the dpkg database.
Change-Id: I81b77486c2ed7717ed81cb2c2572fe6c4b394ffc
... | ... |
@@ -317,16 +317,36 @@ function get_packages() { |
317 | 317 |
continue |
318 | 318 |
fi |
319 | 319 |
|
320 |
+ # Assume we want this package |
|
321 |
+ package=${line%#*} |
|
322 |
+ inst_pkg=1 |
|
323 |
+ |
|
324 |
+ # Look for # dist:xxx in comment |
|
320 | 325 |
if [[ $line =~ (.*)#.*dist:([^ ]*) ]]; then |
321 | 326 |
# We are using BASH regexp matching feature. |
322 | 327 |
package=${BASH_REMATCH[1]} |
323 | 328 |
distros=${BASH_REMATCH[2]} |
324 | 329 |
# In bash ${VAR,,} will lowecase VAR |
325 |
- [[ ${distros,,} =~ ${DISTRO,,} ]] && echo $package |
|
326 |
- continue |
|
330 |
+ # Look for a match in the distro list |
|
331 |
+ if [[ ! ${distros,,} =~ ${DISTRO,,} ]]; then |
|
332 |
+ # If no match then skip this package |
|
333 |
+ inst_pkg=0 |
|
334 |
+ fi |
|
335 |
+ fi |
|
336 |
+ |
|
337 |
+ # Look for # testonly in comment |
|
338 |
+ if [[ $line =~ (.*)#.*testonly.* ]]; then |
|
339 |
+ package=${BASH_REMATCH[1]} |
|
340 |
+ # Are we installing test packages? (test for the default value) |
|
341 |
+ if [[ $INSTALL_TESTONLY_PACKAGES = "False" ]]; then |
|
342 |
+ # If not installing test packages the skip this package |
|
343 |
+ inst_pkg=0 |
|
344 |
+ fi |
|
327 | 345 |
fi |
328 | 346 |
|
329 |
- echo ${line%#*} |
|
347 |
+ if [[ $inst_pkg = 1 ]]; then |
|
348 |
+ echo $package |
|
349 |
+ fi |
|
330 | 350 |
done |
331 | 351 |
IFS=$OIFS |
332 | 352 |
done |
... | ... |
@@ -912,7 +932,7 @@ function is_package_installed() { |
912 | 912 |
fi |
913 | 913 |
|
914 | 914 |
if [[ "$os_PACKAGE" = "deb" ]]; then |
915 |
- dpkg -l "$@" > /dev/null 2> /dev/null |
|
915 |
+ dpkg -s "$@" > /dev/null 2> /dev/null |
|
916 | 916 |
elif [[ "$os_PACKAGE" = "rpm" ]]; then |
917 | 917 |
rpm --quiet -q "$@" |
918 | 918 |
else |
... | ... |
@@ -367,3 +367,25 @@ if [[ "$VAL" -ne 0 ]]; then |
367 | 367 |
else |
368 | 368 |
echo "is_package_installed() on non-existing package failed" |
369 | 369 |
fi |
370 |
+ |
|
371 |
+# test against removed package...was a bug on Ubuntu |
|
372 |
+if is_ubuntu; then |
|
373 |
+ PKG=cowsay |
|
374 |
+ if ! (dpkg -s $PKG >/dev/null 2>&1); then |
|
375 |
+ # it was never installed...set up the condition |
|
376 |
+ sudo apt-get install -y cowsay >/dev/null 2>&1 |
|
377 |
+ fi |
|
378 |
+ if (dpkg -s $PKG >/dev/null 2>&1); then |
|
379 |
+ # remove it to create the 'un' status |
|
380 |
+ sudo dpkg -P $PKG >/dev/null 2>&1 |
|
381 |
+ fi |
|
382 |
+ |
|
383 |
+ # now test the installed check on a deleted package |
|
384 |
+ is_package_installed $PKG |
|
385 |
+ VAL=$? |
|
386 |
+ if [[ "$VAL" -ne 0 ]]; then |
|
387 |
+ echo "OK" |
|
388 |
+ else |
|
389 |
+ echo "is_package_installed() on deleted package failed" |
|
390 |
+ fi |
|
391 |
+fi |