Skip to content

Instantly share code, notes, and snippets.

@markthomas93
Created June 28, 2022 16:21
Show Gist options
  • Save markthomas93/6d47255fd1898309c9ac2b3e8228e6db to your computer and use it in GitHub Desktop.
Save markthomas93/6d47255fd1898309c9ac2b3e8228e6db to your computer and use it in GitHub Desktop.

Revisions

  1. markthomas93 created this gist Jun 28, 2022.
    65 changes: 65 additions & 0 deletions pyenv.install.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@

    #!/usr/bin/env bash

    set -e
    [ -n "$PYENV_DEBUG" ] && set -x

    if [ -z "$PYENV_ROOT" ]; then
    export PYENV_ROOT="${HOME}/.pyenv"
    fi

    colorize() {
    if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
    else echo -n "$2"
    fi
    }

    # Checks for `.pyenv` file, and suggests to remove it for installing
    if [ -d "${PYENV_ROOT}" ]; then
    { echo
    colorize 1 "WARNING"
    echo ": Can not proceed with installation. Kindly remove the '${PYENV_ROOT}' directory first."
    echo
    } >&2
    exit 1
    fi

    failed_checkout() {
    echo "Failed to git clone $1"
    exit -1
    }

    checkout() {
    [ -d "$2" ] || git -c advice.detachedHead=0 clone --branch "$3" --depth 1 "$1" "$2" || failed_checkout "$1"
    }

    if ! command -v git 1>/dev/null 2>&1; then
    echo "pyenv: Git is not installed, can't continue." >&2
    exit 1
    fi

    if [ -n "${USE_GIT_URI}" ]; then
    GITHUB="git://github.com"
    else
    GITHUB="https://github.com"
    fi

    checkout "${GITHUB}/pyenv/pyenv.git" "${PYENV_ROOT}" "${PYENV_GIT_TAG:-master}"
    checkout "${GITHUB}/pyenv/pyenv-doctor.git" "${PYENV_ROOT}/plugins/pyenv-doctor" "master"
    checkout "${GITHUB}/pyenv/pyenv-installer.git" "${PYENV_ROOT}/plugins/pyenv-installer" "master"
    checkout "${GITHUB}/pyenv/pyenv-update.git" "${PYENV_ROOT}/plugins/pyenv-update" "master"
    checkout "${GITHUB}/pyenv/pyenv-virtualenv.git" "${PYENV_ROOT}/plugins/pyenv-virtualenv" "master"
    checkout "${GITHUB}/pyenv/pyenv-which-ext.git" "${PYENV_ROOT}/plugins/pyenv-which-ext" "master"

    if ! command -v pyenv 1>/dev/null; then
    { echo
    colorize 1 "WARNING"
    echo ": seems you still have not added 'pyenv' to the load path."
    echo
    } >&2

    { # Without args, `init` commands print installation help
    "${PYENV_ROOT}/bin/pyenv" init || true
    "${PYENV_ROOT}/bin/pyenv" virtualenv-init || true
    } >&2
    fi