]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Updating update-env.sh
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 27 Jun 2019 10:34:19 +0000 (12:34 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 27 Jun 2019 10:34:19 +0000 (12:34 +0200)
update-env.sh

index 3acf7b1679f53560acdeac5c8a3f57ed82fe7cc8..f9295b1f2f92b3354b54ff49fc72f5bf22dc902a 100755 (executable)
@@ -4,12 +4,7 @@ base_dir=$( dirname $0 )
 cd ${base_dir}
 base_dir=$( readlink -f . )
 
-if type -t virtualenv >/dev/null ; then
-    :
-else
-    echo "Command 'virtualenv' not found, please install package 'python-virtualenv' or appropriate." >&2
-    exit 6
-fi
+declare -a VALID_PY_VERSIONS=("3.8" "3.7" "3.6" "3.5")
 
 if type -t msgfmt >/dev/null ; then
     :
@@ -18,33 +13,67 @@ else
     exit 6
 fi
 
-declare -a VALID_PY_VERSIONS=("3.8" "3.7" "3.6" "3.5")
-
+echo "---------------------------------------------------"
 echo "Preparing virtual environment …"
-echo
 if [[ ! -f venv/bin/activate ]] ; then
-    found="n"
+
+    py_found="n"
     for py_version in "${VALID_PY_VERSIONS[@]}" ; do
         PYTHON="python${py_version}"
         if type -t ${PYTHON} >/dev/null ; then
-            found="y"
+            py_found="y"
             echo
             echo "Found ${PYTHON}."
+            break
+        fi
+    done
+
+    venv_bin='virtualenv'
+    venv_found="n"
+    for py_version in "${VALID_PY_VERSIONS[@]}" ; do
+        venv_bin="virtualenv-${py_version}"
+        if type -t ${venv_bin} >/dev/null ; then
+            venv_found="y"
             echo
-            virtualenv --python=${PYTHON} venv
+            echo "Found ${venv_bin}."
             break
         fi
     done
-    if [[ "${found}" == "n" ]] ; then
+    if [[ "${venv_found}" == "n" ]] ; then
+        venv_bin='virtualenv'
+        if type -t ${venv_bin} >/dev/null ; then
+            venv_found="y"
+            echo
+            echo "Found ${venv_bin}."
+        fi
+    fi
+
+    if [[ "${py_found}" == "n" ]] ; then
         echo >&2
         echo "Did not found a usable Python version." >&2
         echo "Usable Python versions are: ${VALID_PY_VERSIONS[*]}" >&2
         echo >&2
         exit 5
     fi
+
+    if [[ "${venv_found}" == "n" ]] ; then
+        echo >&2
+        echo "Did not found a usable virtualenv command." >&2
+        echo >&2
+        exit 6
+    fi
+
+    echo
+    if [[ "${venv_bin}" == 'virtualenv' ]] ; then
+        virtualenv --python=${PYTHON} venv
+    else
+        ${venv_bin} venv
+    fi
+
 fi
 
 . venv/bin/activate || exit 5
+echo
 
 echo "---------------------------------------------------"
 echo "Upgrading PIP ..."
@@ -79,4 +108,4 @@ echo "-------"
 echo "Fertig."
 echo
 
-# vim: ts=4
+# vim: ts=4 list