From 2ce2b004deff32c9016afd7f8cdffff0059b981f Mon Sep 17 00:00:00 2001 From: beierlm Date: Tue, 7 Dec 2021 16:02:22 -0500 Subject: [PATCH] Bug 1531: Check for packages Fixes logic to check for packages. Originally based on dpkg -l, which could return packages that were once installed, then removed. Instead a new function has been created that takes a list of packages to check and uses dpkg -L, which will return an error if a package is not, or no longer, installed Fixes bug 1531 Change-Id: Id096cf969aacca62dc7783b803e7925c796e325d Signed-off-by: beierlm --- installers/full_install_osm.sh | 38 +++++++++++++++------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index 3447de1f..27e487f4 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -139,6 +139,20 @@ function generate_secret() { [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function } +function check_packages() { + NEEDED_PACKAGES="$1" + echo -e "Checking required packages: ${NEEDED_PACKAGES}" + for PACKAGE in ${NEEDED_PACKAGES} ; do + dpkg -L ${PACKAGE} &>/dev/null + if [ $? -ne 0 ]; then + echo -e "Package ${PACKAGE} is not installed. Updating apt" + sudo apt-get update + sudo apt-get install -y ${PACKAGE} || FATAL "failed to install ${PACKAGE}" + fi + done + echo -e "Required packages are present: ${NEEDED_PACKAGES}" +} + function install_lxd() { [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function # Apply sysctl production values for optimal performance @@ -641,16 +655,7 @@ function install_osm() { # if no host is passed in, we need to install lxd/juju, unless explicilty asked not to if [ -z "$OSM_VCA_HOST" ] && [ -z "$INSTALL_NOLXD" ] && [ -z "$LXD_CLOUD_FILE" ]; then - need_packages_lw="snapd" - echo -e "Checking required packages: $need_packages_lw" - dpkg -l $need_packages_lw &>/dev/null \ - || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \ - || sudo apt-get update \ - || FATAL "failed to run apt-get update" - dpkg -l $need_packages_lw &>/dev/null \ - || ! echo -e "Installing $need_packages_lw requires root privileges." \ - || sudo apt-get install -y $need_packages_lw \ - || FATAL "failed to install $need_packages_lw" + check_packages "snapd" install_lxd fi @@ -1138,17 +1143,8 @@ fi # if develop, we force master [ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master" -need_packages="git wget curl tar" - -echo -e "Checking required packages: $need_packages" -dpkg -l $need_packages &>/dev/null \ - || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \ - || sudo apt-get update \ - || FATAL "failed to run apt-get update" -dpkg -l $need_packages &>/dev/null \ - || ! echo -e "Installing $need_packages requires root privileges." \ - || sudo apt-get install -y $need_packages \ - || FATAL "failed to install $need_packages" +check_packages "git wget curl tar" + sudo snap install jq if [ -z "$OSM_DEVOPS" ]; then if [ -n "$TEST_INSTALLER" ]; then -- 2.25.1