Last active
January 7, 2017 22:59
-
-
Save puckbag/2e8b3c68bd21ed895ee793d8bc97f04d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Installation | |
# | |
# $ bash <(curl -s https://gist.githubusercontent.com/puckbag/2e8b3c68bd21ed895ee793d8bc97f04d/raw/install-nodenv.sh) | |
# | |
# Reference | |
# | |
# https://github.com/nodenv/nodenv | |
# https://github.com/nodenv/node-build | |
# https://github.com/nodenv/nodenv-update | |
# | |
echo_error () { | |
echo; echo "$(tput setaf 1)$@$(tput sgr0)"; echo | |
} | |
echo_info () { | |
echo; echo "$(tput setaf 2)$@$(tput sgr0)"; echo | |
} | |
echo_alert () { | |
echo; echo "$(tput setaf 3)$@$(tput sgr0)"; echo | |
} | |
if [ -d ~/.nodenv ]; then | |
echo_error 'Nodenv already installed' | |
exit 1 | |
fi | |
PROFILE_FILE='' | |
if [ -f "$HOME/.bash_profile" ]; then | |
PROFILE_FILE="$HOME/.bash_profile" | |
elif [ -f "$HOME/.bash_login" ]; then | |
PROFILE_FILE="$HOME/.bash_login" | |
elif [ -f "$HOME/.profile" ]; then | |
PROFILE_FILE="$HOME/.profile" | |
fi | |
CWD=`pwd` | |
# Install nodenv/nodenv | |
echo_info 'Install nodenv/nodenv' | |
git clone https://github.com/nodenv/nodenv.git ~/.nodenv | |
cd ~/.nodenv && src/configure && make -C src | |
cd $CWD | |
# Inject nodenv into this environment | |
echo_info 'Inject nodenv into this environment' | |
export PATH="$HOME/.nodenv/bin:$PATH" | |
eval "$(nodenv init -)" | |
# Save nodenv into environment scripts | |
if [[ -z "$PROFILE_FILE" ]]; then | |
echo_alert 'BASH profile file could not be established.' | |
else | |
echo_info "Save nodenv into profile file: $PROFILE_FILE" | |
if ! grep -q '.nodenv/bin' "$PROFILE_FILE"; then | |
echo 'export PATH="$HOME/.nodenv/bin:$PATH"' >> "$PROFILE_FILE" | |
fi | |
if ! grep -q 'nodenv init' "$PROFILE_FILE"; then | |
echo 'eval "$(nodenv init -)"' >> "$PROFILE_FILE" | |
fi | |
fi | |
# Install nodenv plugin: node-build | |
echo_info 'Install nodenv plugin: node-build' | |
git clone https://github.com/nodenv/node-build.git $(nodenv root)/plugins/node-build | |
# Install nodenv plugin: node-update | |
echo_info 'Install nodenv plugin: node-update' | |
git clone https://github.com/nodenv/nodenv-update.git "$(nodenv root)"/plugins/nodenv-update | |
# Update nodenv and plugins | |
echo_info 'Update nodenv and plugins' | |
nodenv update | |
# Note about shell environment | |
echo_alert 'You must restart your shell or run the following:' | |
echo ' $ export PATH="$HOME/.nodenv/bin:$PATH" && eval "$(nodenv init -)"' | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment