]> git.apps.os.sepia.ceph.com Git - ceph-build.git/commitdiff
build_utils.sh: Always remove unwanted python3.X versions aggressive
authorDavid Galloway <dgallowa@redhat.com>
Wed, 4 May 2022 15:48:20 +0000 (11:48 -0400)
committerDavid Galloway <dgallowa@redhat.com>
Wed, 4 May 2022 17:46:42 +0000 (13:46 -0400)
Signed-off-by: David Galloway <dgallowa@redhat.com>
scripts/build_utils.sh

index c2c8e250c1df2321737f132ab126e603bcee6c3f..1b49ee29e4979589c5d24606306c039054dede16 100644 (file)
@@ -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
 }