Last active
January 1, 2017 03:30
-
-
Save Ilyes512/8335484 to your computer and use it in GitHub Desktop.
A custom NVM install.sh script for Vaprobash
This file contains 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 | |
NVM_DIR="/home/vagrant/.nvm" | |
if ! hash git 2>/dev/null; then | |
echo >&2 "!!! You need to install git" | |
exit 1 | |
fi | |
if [ -d "$NVM_DIR" ]; then | |
echo ">>> NVM is already installed in $NVM_DIR, trying to update" | |
echo -ne "\r=> " | |
cd $NVM_DIR && git pull | |
else | |
# Cloning to $NVM_DIR | |
git clone https://github.com/creationix/nvm.git $NVM_DIR | |
fi | |
PROFILE="/home/vagrant/.profile" | |
ZSHRC="/home/vagrant/.zshrc" | |
SOURCE_STR="\n# This loads NVM\n[[ -s /home/vagrant/.nvm/nvm.sh ]] && . /home/vagrant/.nvm/nvm.sh" | |
# Append NVM script to ~/.profile | |
if ! grep -qsc 'nvm.sh' $PROFILE; then | |
echo ">>> Appending source string to $PROFILE" | |
echo $SOURCE_STR >> "$PROFILE" | |
else | |
echo ">>> Source string already in $PROFILE" | |
fi | |
# Check if .zshrc exist | |
if [ -f "$ZSHRC" ]; then | |
# Append NVM script to ~/.zshrc | |
if ! grep -qsc 'nvm.sh' $ZSHRC; then | |
echo ">>> Appending source string to $ZSHRC" | |
echo $SOURCE_STR >> "$ZSHRC" | |
else | |
echo ">>> Source string already in $ZSHRC" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment