Last active
May 16, 2019 20:09
-
-
Save u8sand/44dacefb8a8e0202fd6a51959aa9603f to your computer and use it in GitHub Desktop.
Script for installing a suite of local version managers for python, node, and ruby (pyenv, rbenv, nodenv)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| HOME="/home/${USER}" | |
| PROFILE="${HOME}/.profile" | |
| install_env() { | |
| ENV_CMD="$1" | |
| ENV_URL="$2" | |
| ENV_ROOT="${HOME}/.${ENV_CMD}" | |
| ENV_CMD_ROOT="$(echo ${ENV_CMD} | tr /a-z/ /A-Z/)_ROOT" | |
| if [ ! -d "${ENV_ROOT}" ]; then | |
| git clone "${ENV_URL}" "${ENV_ROOT}" | |
| cd "${ENV_ROOT}" && src/configure && make -C src | |
| echo "export ${ENV_CMD_ROOT}/\"\$HOME/.${ENV_CMD}\"" >> ${PROFILE} | |
| echo "export PATH=\"\$${ENV_CMD_ROOT}/bin:\$PATH\"" >> ${PROFILE} | |
| echo "eval \"\$(${ENV_CMD} init -)\"" >> ${PROFILE} | |
| else | |
| echo "${ENV_CMD} already installed at ${ENV_ROOT}; skipping." | |
| fi | |
| } | |
| install_env_plugin() { | |
| ENV_CMD="$1" | |
| ENV_PLUGIN="$2" | |
| ENV_PLUGIN_URL="$3" | |
| ENV_PLUGIN_EXTRA="$4" | |
| ENV_PLUGIN_ROOT="$(${ENV_CMD} root)/plugins/${ENV_PLUGIN}" | |
| if [ ! -d "${ENV_PLUGIN_ROOT}" ]; then | |
| git clone "${ENV_PLUGIN_URL}" "$ENV_PLUGIN_ROOT" | |
| if [ ! -z "${ENV_PLUGIN_EXTRA}" ]; then | |
| echo "${ENV_PLUGIN_EXTRA}" >> ${PROFILE} | |
| fi | |
| else | |
| echo "${ENV_PLUGIN} already installed at ${ENV_PLUGIN_ROOT}; skipping." | |
| fi | |
| } | |
| if [ -z "$1" ]; then | |
| set -- pyenv pyenv-virtualenv rbenv ruby-build nodenv node-build | |
| fi | |
| ENV="$1" | |
| while [ ! -z "${ENV}" ]; do | |
| if [ "${ENV}" == "pyenv" ]; then | |
| install_env pyenv \ | |
| https://github.com/pyenv/pyenv.git | |
| elif [ "${ENV}" == "pyenv-virtualenv" ]; then | |
| install_env_plugin pyenv pyenv-virtualenv \ | |
| https://github.com/pyenv/pyenv-virtualenv.git \ | |
| 'eval "$(pyenv virtualenv-init -)"' | |
| elif [ "${ENV}" == "rbenv" ]; then | |
| install_env rbenv \ | |
| https://github.com/rbenv/rbenv.git | |
| elif [ "${ENV}" == "ruby-build" ]; then | |
| install_env_plugin rbenv ruby-build \ | |
| https://github.com/rbenv/rbenv-build.git | |
| elif [ "${ENV}" == "nodenv" ]; then | |
| install_env nodenv \ | |
| https://github.com/nodenv/nodenv.git | |
| elif [ "${ENV}" == "node-build" ]; then | |
| install_env_plugin nodenv node-build \ | |
| https://github.com/nodenv/nodenv-build.git | |
| else | |
| echo "${ENV} not recognized." | |
| fi | |
| source "${PROFILE}" | |
| shift 1 | |
| ENV="$1" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment