2012-10-30 00:03:01 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2013-12-22 17:46:26 +01:00
|
|
|
set -e
|
|
|
|
|
|
2013-12-22 18:23:59 +01:00
|
|
|
if [ ! "$NVM_SOURCE" ]; then
|
|
|
|
|
NVM_SOURCE="https://github.com/creationix/nvm.git"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [ ! "$NVM_DIR" ]; then
|
|
|
|
|
NVM_DIR="$HOME/.nvm"
|
|
|
|
|
fi
|
2012-10-30 00:03:01 +01:00
|
|
|
|
2013-06-07 23:42:28 +01:00
|
|
|
if ! hash git 2>/dev/null; then
|
2013-09-21 12:58:01 -07:00
|
|
|
echo >&2 "You need to install git - visit http://git-scm.com/downloads"
|
|
|
|
|
echo >&2 "or, use install-gitless.sh instead."
|
2013-06-07 23:42:28 +01:00
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2013-06-14 16:20:36 +09:00
|
|
|
if [ -d "$NVM_DIR" ]; then
|
|
|
|
|
echo "=> NVM is already installed in $NVM_DIR, trying to update"
|
2013-12-22 18:23:59 +01:00
|
|
|
echo -e "\r=> \c"
|
|
|
|
|
cd "$NVM_DIR" && git pull
|
2013-07-26 14:58:47 +03:00
|
|
|
else
|
|
|
|
|
# Cloning to $NVM_DIR
|
2013-12-22 18:23:59 +01:00
|
|
|
mkdir -p "$NVM_DIR"
|
|
|
|
|
git clone "$NVM_SOURCE" "$NVM_DIR"
|
2012-10-30 00:03:01 +01:00
|
|
|
fi
|
|
|
|
|
|
2013-02-27 11:50:08 +02:00
|
|
|
echo
|
2012-10-30 00:03:01 +01:00
|
|
|
|
2013-12-22 17:56:42 +01:00
|
|
|
# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile).
|
|
|
|
|
if [ ! "$PROFILE" ]; then
|
2012-10-30 00:03:01 +01:00
|
|
|
if [ -f "$HOME/.bash_profile" ]; then
|
2013-12-22 17:56:42 +01:00
|
|
|
PROFILE="$HOME/.bash_profile"
|
2013-10-10 14:30:53 -03:00
|
|
|
elif [ -f "$HOME/.zshrc" ]; then
|
2013-12-22 17:56:42 +01:00
|
|
|
PROFILE="$HOME/.zshrc"
|
2012-10-30 00:03:01 +01:00
|
|
|
elif [ -f "$HOME/.profile" ]; then
|
2013-12-22 17:56:42 +01:00
|
|
|
PROFILE="$HOME/.profile"
|
2012-10-30 00:03:01 +01:00
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2013-12-22 18:03:06 +01:00
|
|
|
SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads NVM"
|
2012-10-30 00:03:01 +01:00
|
|
|
|
|
|
|
|
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
|
2013-02-27 11:50:08 +02:00
|
|
|
if [ -z $PROFILE ]; then
|
2013-12-22 18:05:20 +01:00
|
|
|
echo "=> Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile."
|
|
|
|
|
echo "=> Create one of them and run this script again"
|
2012-10-30 00:03:01 +01:00
|
|
|
else
|
2013-12-22 18:05:20 +01:00
|
|
|
echo "=> Profile $PROFILE not found"
|
|
|
|
|
echo "=> Create it (touch $PROFILE) and run this script again"
|
2012-10-30 00:03:01 +01:00
|
|
|
fi
|
2013-12-22 18:05:20 +01:00
|
|
|
echo " OR"
|
|
|
|
|
echo "=> Append the following line to the correct file yourself:"
|
2013-07-26 14:58:47 +03:00
|
|
|
echo
|
2013-12-22 18:05:20 +01:00
|
|
|
echo " $SOURCE_STR"
|
2013-07-26 14:58:47 +03:00
|
|
|
echo
|
2012-10-30 00:03:01 +01:00
|
|
|
else
|
2013-12-22 18:05:20 +01:00
|
|
|
if ! grep -qc 'nvm.sh' $PROFILE; then
|
|
|
|
|
echo "=> Appending source string to $PROFILE"
|
|
|
|
|
echo "" >> "$PROFILE"
|
|
|
|
|
echo $SOURCE_STR >> "$PROFILE"
|
|
|
|
|
else
|
|
|
|
|
echo "=> Source string already in $PROFILE"
|
|
|
|
|
fi
|
2012-10-30 00:03:01 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "=> Close and reopen your terminal to start using NVM"
|
2014-03-15 11:41:50 -07:00
|
|
|
|