From: David Galloway Date: Wed, 4 May 2022 15:48:20 +0000 (-0400) Subject: build_utils.sh: Always remove unwanted python3.X versions X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fheads%2Faggressive;p=ceph-build.git build_utils.sh: Always remove unwanted python3.X versions Signed-off-by: David Galloway --- diff --git a/scripts/build_utils.sh b/scripts/build_utils.sh index c2c8e250..1b49ee29 100644 --- a/scripts/build_utils.sh +++ b/scripts/build_utils.sh @@ -1655,14 +1655,10 @@ function retrycmd_if_failure() { function set_centos_python3_version() { # This function expects $1 to be a string like "python3.9" - local CURRENT_PYTHON3_VERSION=$(sudo alternatives --display python3 | grep -e 'Current.*best.* version is' | awk '{ print $5 }' | sed 's/\.$//') local EXPECTED_PYTHON3_VERSION=$1 - if ! [[ "$CURRENT_PYTHON3_VERSION" =~ .*"$EXPECTED_PYTHON3_VERSION" ]]; then - PYTHON3_TO_REMOVE=$(rpm -qf $CURRENT_PYTHON3_VERSION | cut -d '-' -f1) - sudo dnf remove -y ${PYTHON3_TO_REMOVE}\* - sudo dnf install -y $EXPECTED_PYTHON3_VERSION || sudo dnf reinstall -y $EXPECTED_PYTHON3_VERSION - sudo alternatives --display python3 - else - echo "python3 symlink already points to $CURRENT_PYTHON3_VERSION" - fi + local EXPECTED_PYTHON3_VERSION_MASHED=$(echo $EXPECTED_PYTHON3_VERSION | tr -d '.') + for package in $(rpm -qa | grep -E '^python3[1-9]{1,3}' | grep -v $EXPECTED_PYTHON3_VERSION_MASHED); do + sudo dnf remove -y $package --noautoremove + done + sudo dnf reinstall -y $EXPECTED_PYTHON3_VERSION || sudo dnf install -y $EXPECTED_PYTHON3_VERSION }