Skip to content

Instantly share code, notes, and snippets.

@Ilyes512
Last active January 1, 2017 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Ilyes512/8335484 to your computer and use it in GitHub Desktop.
Save Ilyes512/8335484 to your computer and use it in GitHub Desktop.
A custom NVM install.sh script for Vaprobash
#!/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