]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-build.git/commitdiff
build_utils.sh: Remove python3 versions we don't want 1996/head
authorDavid Galloway <dgallowa@redhat.com>
Mon, 2 May 2022 18:31:12 +0000 (14:31 -0400)
committerDavid Galloway <dgallowa@redhat.com>
Mon, 2 May 2022 18:31:12 +0000 (14:31 -0400)
@guits and I think there's either a bug in `alternatives` or we just can't figure out how it's supposed to work.  Even with setting `alternatives --set python3 /usr/bin/python3.9`, python3.6 was still the "best" version according to `alternatives --display`.

So we'll just remove the other version entirely.

Signed-off-by: David Galloway <dgallowa@redhat.com>
scripts/build_utils.sh

index dfe56372509651b916e46c5a6890c0b3c759f319..c2c8e250c1df2321737f132ab126e603bcee6c3f 100644 (file)
@@ -1655,11 +1655,13 @@ 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 --list | grep -e '^python3' | awk '{ print $3 }')
+    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
-        sudo dnf install -y $EXPECTED_PYTHON3_VERSION
-        sudo alternatives --set python3 /usr/bin/$EXPECTED_PYTHON3_VERSION
+        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