From: Frank Brehm Date: Fri, 4 Oct 2019 08:55:49 +0000 (+0200) Subject: Rewritten searching for dependencies in update-env.sh X-Git-Tag: 1.7.4~4^2~3 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=75b1c20858dc4c7b0614bcabbc8dcd6c127ebe3f;p=pixelpark%2Fpuppetmaster-webhooks.git Rewritten searching for dependencies in update-env.sh --- diff --git a/update-env.sh b/update-env.sh index 1ea1ebc..cee6295 100755 --- a/update-env.sh +++ b/update-env.sh @@ -7,7 +7,7 @@ VERBOSE="n" DEBUG="n" QUIET='n' -VERSION="2.0" +VERSION="2.1" # console colors: RED="" @@ -27,6 +27,11 @@ BASE_DIR=$( readlink -f . ) PIP_OPTIONS= export VIRTUAL_ENV_DISABLE_PROMPT=y +declare -a VALID_PY_VERSIONS=("3.8" "3.7" "3.6" "3.5") +PY_VERSION_FINAL= +PYTHON= +VENV_BIN='virtualenv' + #------------------------------------------------------------------- detect_color() { @@ -175,6 +180,9 @@ get_options() { local tmp= local short_options="dvqhV" local long_options="debug,verbose,quiet,help,version" + local venv_found="n" + local py_version= + local py_found="n" set +e tmp=$( getopt -o "${short_options}" --long "${long_options}" -n "${BASENAME}" -- "$@" ) @@ -249,12 +257,48 @@ get_options() { exit 1 fi - if type -t virtualenv >/dev/null ; then - : + py_found="n" + info "Searching for valid Python …" + for py_version in "${VALID_PY_VERSIONS[@]}" ; do + PYTHON="python${py_version}" + debug "Testing Python binary '${CYAN}${PYTHON}${NORMAL}' …" + if type -t ${PYTHON} >/dev/null ; then + py_found="y" + PY_VERSION_FINAL="${py_version}" + empty_line + info "Found '${GREEN}${PYTHON}${NORMAL}'." + break + fi + done + + if [[ "${py_found}" == "n" ]] ; then + empty_line >&2 + error "Did not found a usable Python version." >&2 + error "Usable Python versions are: ${YELOW}${VALID_PY_VERSIONS[*]}${NORMAL}." >&2 + empty_line >&2 + exit 5 + fi + + venv_found="n" + info "Searching for valid virtualenv …" + VENV_BIN="virtualenv-${PY_VERSION_FINAL}" + debug "Testing '${VENV_BIN}' …" + if type -t ${VENV_BIN} >/dev/null ; then + venv_found="y" else - error "Command '${RED}virtualenv${NORMAL}' not found, please install package '${YELLOW}python-virtualenv${NORMAL}' or appropriate." - exit 6 + VENV_BIN="virtualenv" + debug "Testing '${VENV_BIN}' …" + if type -t ${VENV_BIN} >/dev/null ; then + venv_found="y" + else + empty_line >&2 + error "Did not found a usable virtualenv." >&2 + error "Command '${RED}virtualenv${NORMAL}' not found, please install package '${YELLOW}python-virtualenv${NORMAL}' or appropriate." + empty_line >&2 + exit 6 + fi fi + info "Found '${GREEN}${VENV_BIN}${NORMAL}'." if type -t msgfmt >/dev/null ; then : @@ -274,11 +318,6 @@ get_options() { #------------------------------------------------------------------------------ init_venv() { - local -a valid_py_versions=("3.8" "3.7" "3.6" "3.5") - local py_version= - local python= - local found="n" - empty_line line info "Preparing virtual environment …" @@ -286,26 +325,14 @@ init_venv() { if [[ ! -f venv/bin/activate ]] ; then - found="n" - for py_version in "${valid_py_versions[@]}" ; do - python="python${py_version}" - debug "Testing Python binary '${CYAN}${python}${NORMAL}' …" - if type -t ${python} >/dev/null ; then - found="y" - empty_line - info "Found '${GREEN}${python}${NORMAL}'." - empty_line - virtualenv --python=${python} venv - break - fi - done - if [[ "${found}" == "n" ]] ; then - empty_line >&2 - error "Did not found a usable Python version." >&2 - error "Usable Python versions are: ${YELOW}${valid_py_versions[*]}${NORMAL}." >&2 - empty_line >&2 - exit 5 + + empty_line + if [[ "${VENV_BIN}" == 'virtualenv' ]] ; then + virtualenv --python=${PYTHON} venv + else + ${VENV_BIN} venv fi + fi . venv/bin/activate || exit 5