]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
[RM-15016] Rework the bootstrap script to properly install Python 3 on CentOS
authorOleh Prypin <oleh@pryp.in>
Thu, 16 Jun 2016 10:45:23 +0000 (13:45 +0300)
committerOleh Prypin <oleh@pryp.in>
Thu, 16 Jun 2016 10:46:28 +0000 (13:46 +0300)
Signed-off-by: Oleh Prypin <oleh@pryp.in>
bootstrap

index 51995cd65bac25d1343b92cf7dfd8d60e82e3704..deb83df224886404df899d5eca879c44d15f0731 100755 (executable)
--- a/bootstrap
+++ b/bootstrap
@@ -3,61 +3,82 @@ set -e
 
 # Use `./bootstrap 3` for Python 3
 python_executable="python$1"
-if [ "$1" = "2" ]; then
-    python_package="python"
-else
-    python_package="python$1"
-fi
 
-if command -v lsb_release >/dev/null 2>&1; then
-    case "$(lsb_release --id --short)" in
-       Ubuntu|Debian)
-           for package in "$python_package" python-virtualenv; do
-               if [ "$(dpkg --status -- "$package" 2>/dev/null|sed -n 's/^Status: //p')" != "install ok installed" ]; then
-                    # add a space after old values
-                   missing="${missing:+$missing }$package"
-               fi
-           done
-           if [ -n "$missing" ]; then
-                       echo "$0: missing required packages, please install them:" 1>&2
-                       echo "  sudo apt-get install $missing"
-                       exit 1
-           fi
-           ;;
-    esac
+if ! [ -d virtualenv ]; then
+    if command -v lsb_release >/dev/null 2>&1; then
+        if [ "$1" = "2" ]; then
+            python_package="python"
+        else
+            python_package="python$1"
+        fi
+
+        case "$(lsb_release --id --short)" in
+        Ubuntu|Debian)
+            for package in "$python_package" python-virtualenv; do
+            if [ "$(dpkg --status -- "$package" 2>/dev/null|sed -n 's/^Status: //p')" != "install ok installed" ]; then
+                # add a space after old values
+                missing="${missing:+$missing }$package"
+            fi
+            done
+            if [ -n "$missing" ]; then
+                echo "$0: missing required packages, please install them:" 1>&2
+                echo "  sudo apt-get install $missing"
+                exit 1
+            fi
+            ;;
+        esac
+
+        case "$(lsb_release --id --short | awk '{print $1}')" in
+        openSUSE|SUSE)
+            for package in "$python_package" python-virtualenv; do
+                if [ "$(rpm -qa "$package" 2>/dev/null)" == "" ]; then
+                    missing="${missing:+$missing }$package"
+                fi
+            done
+            if [ -n "$missing" ]; then
+                echo "$0: missing required packages, please install them:" 1>&2
+                echo "  sudo zypper install $missing"
+                exit 1
+            fi
+            ;;
+        esac
+    fi
+
+    if [ -f /etc/redhat-release ]; then
+        case "$(cat /etc/redhat-release | awk '{print $1}')" in
+        CentOS)
+            for package in python-virtualenv; do
+                if [ "$(rpm -qa "$package" 2>/dev/null)" == "" ]; then
+                    missing="${missing:+$missing }$package"
+                fi
+            done
+            if [ -n "$missing" ]; then
+                echo "$0: missing required packages, please install them:" 1>&2
+                echo "  sudo yum install $missing"
+                exit 1
+            fi
+
+            if [ "${1:-2}" -ge 3 ]; then
+                if ! command -v "$python_executable" >/dev/null 2>&1; then
+                    echo "$0: missing Python ($python_executable), please install it"
+                    exit 1
+                fi
 
-    case "$(lsb_release --id --short | awk '{print $1}')" in
-       openSUSE|SUSE)
-       for package in "$python_package" python-virtualenv; do
-               if [ "$(rpm -qa "$package" 2>/dev/null)" == "" ]; then
-                       missing="${missing:+$missing }$package"
-               fi
-       done
-       if [ -n "$missing" ]; then
-               echo "$0: missing required packages, please install them:" 1>&2
-               echo "  sudo zypper install $missing"
-               exit 1
-       fi
-       ;;
-    esac
+                # Make a temporary virtualenv to get a fresh version of virtualenv
+                # and use it to make a Python 3 virtualenv,
+                # because CentOS 7 has buggy old virtualenv (v1.10.1)
+                # https://github.com/pypa/virtualenv/issues/463
 
-else
-       if [ -f /etc/redhat-release ]; then
-               case "$(cat /etc/redhat-release | awk '{print $1}')" in
-                       CentOS)
-                               for package in "$python_package" python-virtualenv; do
-                               if [ "$(rpm -qa "$package" 2>/dev/null)" == "" ]; then
-                                       missing="${missing:+$missing }$package"
-                               fi
-                               done
-                               if [ -n "$missing" ]; then
-                                       echo "$0: missing required packages, please install them:" 1>&2
-                                       echo "  sudo yum install $missing"
-                               exit 1
-                               fi
-                               ;;
-               esac
-       fi
+                virtualenv virtualenv_tmp
+                virtualenv_tmp/bin/pip install --upgrade virtualenv
+                virtualenv_tmp/bin/virtualenv -p "$python_executable" virtualenv
+                rm -rf virtualenv_tmp
+            else
+                virtualenv virtualenv
+            fi
+            ;;
+        esac
+    fi
 fi
 
 test -d virtualenv || virtualenv -p "$python_executable" virtualenv