From f199ca54bd5ade10f2baf84a1a84c3b7623ecddd Mon Sep 17 00:00:00 2001 From: Pierre Kancir Date: Sat, 23 May 2020 17:40:50 +0200 Subject: [PATCH] Tools: fix install-prereqs-ubuntu make a function to return 1 if a dpkg find that a package is installed, O otherwise --- Tools/environment_install/install-prereqs-ubuntu.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Tools/environment_install/install-prereqs-ubuntu.sh b/Tools/environment_install/install-prereqs-ubuntu.sh index f9caabd6b6..d14312585e 100755 --- a/Tools/environment_install/install-prereqs-ubuntu.sh +++ b/Tools/environment_install/install-prereqs-ubuntu.sh @@ -40,8 +40,12 @@ fi # update apt package list $APT_GET update +function package_is_installed() { + return $(dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed") +} + # Install lsb-release as it is needed to check Ubuntu version -if ! dpkg-query -l "lsb-release"; then +if package_is_installed "lsb-release" -ne 1; then echo "$sep" echo "Installing lsb-release" echo "$sep" @@ -150,7 +154,7 @@ echo "Done!" echo "$sep" echo "Removing modemmanager package that could conflict with firmware uploading" echo "$sep" -if dpkg-query -l "modemmanager"; then +if package_is_installed "modemmanager" -ne 1; then $APT_GET remove modemmanager fi echo "Done!"