From 0787a55999b7dca9357ecec1b91b07f0c57f88f2 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 22 Dec 2013 17:46:26 +0100 Subject: [PATCH 01/14] replaced fatalExit function for 'inline' exit exit on errors (set -e) simplified if for NVM_DIR and NVM_SOURCE, corrected indentation --- install-gitless.sh | 11 ++++++----- install.sh | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/install-gitless.sh b/install-gitless.sh index d4b96b4..6bdede1 100755 --- a/install-gitless.sh +++ b/install-gitless.sh @@ -1,15 +1,16 @@ #!/bin/bash +set -e + fatalExit (){ echo "$@" && exit 1; } -# an alternative URL that could be used: https://github.com/creationix/nvm/tarball/master -if [ "$NVM_SOURCE" = "" ]; then +if [ ! "$NVM_SOURCE" ]; then NVM_SOURCE="https://raw.github.com/creationix/nvm/master/nvm.sh" fi -if [ "$NVM_DIR" = "" ]; then +if [ ! "$NVM_DIR" ]; then NVM_DIR="$HOME/.nvm" fi @@ -20,9 +21,9 @@ echo -ne "=> Downloading... " # Detect if curl or wget is installed to download NVM_SOURCE if type curl > /dev/null 2>&1; then - curl --silent "$NVM_SOURCE" -o nvm.sh || fatalExit "Failed"; + curl --silent "$NVM_SOURCE" -o nvm.sh || fatalExit "Failed downloading $NVM_SOURCE"; elif type wget > /dev/null 2>&1; then - wget --quiet "$NVM_SOURCE" -O nvm.sh || fatalExit "Failed"; + wget --quiet "$NVM_SOURCE" -O nvm.sh || fatalExit "Failed downloading $NVM_SOURCE"; else fatalExit "Must have curl or wget to install nvm"; fi diff --git a/install.sh b/install.sh index e76fcd5..a65db46 100755 --- a/install.sh +++ b/install.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + NVM_DIR="$HOME/.nvm" if ! hash git 2>/dev/null; then From fcc00b22b74f549ee410c03ca85d716e49bcb195 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 22 Dec 2013 17:48:10 +0100 Subject: [PATCH 02/14] don't make use of pushd and popd as they are not universal --- install-gitless.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install-gitless.sh b/install-gitless.sh index 6bdede1..2603ad9 100755 --- a/install-gitless.sh +++ b/install-gitless.sh @@ -16,20 +16,20 @@ fi # Downloading to $NVM_DIR mkdir -p "$NVM_DIR" -pushd "$NVM_DIR" > /dev/null -echo -ne "=> Downloading... " +echo -e "\r=> Downloading... \c" # Detect if curl or wget is installed to download NVM_SOURCE if type curl > /dev/null 2>&1; then - curl --silent "$NVM_SOURCE" -o nvm.sh || fatalExit "Failed downloading $NVM_SOURCE"; + curl --silent "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || fatalExit "Failed downloading $NVM_SOURCE"; elif type wget > /dev/null 2>&1; then - wget --quiet "$NVM_SOURCE" -O nvm.sh || fatalExit "Failed downloading $NVM_SOURCE"; + wget --quiet "$NVM_SOURCE" -O "$NVM_DIR/nvm.sh" || fatalExit "Failed downloading $NVM_SOURCE"; else fatalExit "Must have curl or wget to install nvm"; fi echo "Downloaded" -popd > /dev/null + +echo # Detect profile file, .bash_profile has precedence over .profile if [ ! -z "$1" ]; then From d2422a623a1fbb90b5152f422a7583d1ca852f87 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 22 Dec 2013 18:23:59 +0100 Subject: [PATCH 03/14] made NVM_DIR and NVM_SOURCE configurable using environment variables --- install.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/install.sh b/install.sh index a65db46..c69c149 100755 --- a/install.sh +++ b/install.sh @@ -2,7 +2,13 @@ set -e -NVM_DIR="$HOME/.nvm" +if [ ! "$NVM_SOURCE" ]; then + NVM_SOURCE="https://github.com/creationix/nvm.git" +fi + +if [ ! "$NVM_DIR" ]; then + NVM_DIR="$HOME/.nvm" +fi if ! hash git 2>/dev/null; then echo >&2 "You need to install git - visit http://git-scm.com/downloads" @@ -12,11 +18,12 @@ 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 + echo -e "\r=> \c" + cd "$NVM_DIR" && git pull else # Cloning to $NVM_DIR - git clone https://github.com/creationix/nvm.git $NVM_DIR + mkdir -p "$NVM_DIR" + git clone "$NVM_SOURCE" "$NVM_DIR" fi echo From 1fac49f887596b242c06eabd90884baadf412821 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 22 Dec 2013 17:56:42 +0100 Subject: [PATCH 04/14] replaced undocumented option for specifying the profile as first argument to specifying it as a environment variable (eg: PROFILE=~/.myprofile ./install-gitless.sh) also; fixed indentation and added .zshrc as possible profile --- install-gitless.sh | 8 ++++---- install.sh | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/install-gitless.sh b/install-gitless.sh index 2603ad9..a0e524b 100755 --- a/install-gitless.sh +++ b/install-gitless.sh @@ -31,12 +31,12 @@ echo "Downloaded" echo -# Detect profile file, .bash_profile has precedence over .profile -if [ ! -z "$1" ]; then - PROFILE="$1" -else +# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile). +if [ -z "$PROFILE" ]; then if [ -f "$HOME/.bash_profile" ]; then PROFILE="$HOME/.bash_profile" + elif [ -f "$HOME/.zshrc" ]; then + PROFILE="$HOME/.zshrc" elif [ -f "$HOME/.profile" ]; then PROFILE="$HOME/.profile" fi diff --git a/install.sh b/install.sh index c69c149..d9c4579 100755 --- a/install.sh +++ b/install.sh @@ -28,16 +28,14 @@ fi echo -# Detect profile file, .bash_profile has precedence over .profile -if [ ! -z "$1" ]; then - PROFILE="$1" -else +# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile). +if [ ! "$PROFILE" ]; then if [ -f "$HOME/.bash_profile" ]; then - PROFILE="$HOME/.bash_profile" + PROFILE="$HOME/.bash_profile" elif [ -f "$HOME/.zshrc" ]; then - PROFILE="$HOME/.zshrc" + PROFILE="$HOME/.zshrc" elif [ -f "$HOME/.profile" ]; then - PROFILE="$HOME/.profile" + PROFILE="$HOME/.profile" fi fi From 246caa858174baa1d5955dd3995fd9386d244bfd Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 22 Dec 2013 18:03:06 +0100 Subject: [PATCH 05/14] Updated source string, use hard path as NVM is not always installed in `$HOME/.nvm` --- install-gitless.sh | 2 +- install.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/install-gitless.sh b/install-gitless.sh index a0e524b..a2bd9cc 100755 --- a/install-gitless.sh +++ b/install-gitless.sh @@ -42,7 +42,7 @@ if [ -z "$PROFILE" ]; then fi fi -SOURCE_STR="[[ -s "$NVM_DIR/nvm.sh" ]] && . "$NVM_DIR/nvm.sh" # This loads NVM" +SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads NVM" if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then if [ -z $PROFILE ]; then diff --git a/install.sh b/install.sh index d9c4579..dee3a0f 100755 --- a/install.sh +++ b/install.sh @@ -39,7 +39,7 @@ if [ ! "$PROFILE" ]; then fi fi -SOURCE_STR="[[ -s \$HOME/.nvm/nvm.sh ]] && . \$HOME/.nvm/nvm.sh # This loads NVM" +SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads NVM" if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then if [ -z $PROFILE ]; then From 7211c9ee2956b848951fe7036bc73d562717741d Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 22 Dec 2013 18:05:20 +0100 Subject: [PATCH 06/14] updated output without special characters (tab; \t) Omit duplicate 'finish line' normalized indentation --- install-gitless.sh | 25 +++++++++++++------------ install.sh | 33 ++++++++++++++------------------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/install-gitless.sh b/install-gitless.sh index a2bd9cc..c24d25b 100755 --- a/install-gitless.sh +++ b/install-gitless.sh @@ -46,24 +46,25 @@ SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads NV if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then if [ -z $PROFILE ]; then - echo "=> Profile not found" + echo "=> Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile." + echo "=> Create one of them and run this script again" else echo "=> Profile $PROFILE not found" + echo "=> Create it (touch $PROFILE) and run this script again" fi - echo "=> Append the following line to the correct file yourself" + echo " OR" + echo "=> Append the following line to the correct file yourself:" echo - echo "\t$SOURCE_STR" + echo " $SOURCE_STR" echo - echo "=> Close and reopen your terminal to start using NVM" - exit -fi - -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" + 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 fi echo "=> Close and reopen your terminal to start using NVM" diff --git a/install.sh b/install.sh index dee3a0f..2804803 100755 --- a/install.sh +++ b/install.sh @@ -43,30 +43,25 @@ SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads NV if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then if [ -z $PROFILE ]; then - echo "=> Profile not found. Tried $HOME/.bash_profile and $HOME/.profile" + echo "=> Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile." + echo "=> Create one of them and run this script again" else - echo "=> Profile $PROFILE not found" + echo "=> Profile $PROFILE not found" + echo "=> Create it (touch $PROFILE) and run this script again" fi - echo "=> Run this script again after running the following:" + echo " OR" + echo "=> Append the following line to the correct file yourself:" echo - echo "\ttouch $HOME/.profile" + echo " $SOURCE_STR" echo - echo "-- OR --" - echo - echo "=> Append the following line to the correct file yourself" - echo - echo "\t$SOURCE_STR" - echo - echo "=> Close and reopen your terminal afterwards to start using NVM" - exit -fi - -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" + 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 fi echo "=> Close and reopen your terminal to start using NVM" From 9f6280265a5aba213ad0c97393d74de43c3cc482 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 22 Dec 2013 18:37:08 +0100 Subject: [PATCH 07/14] updated README --- README.markdown | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index f93f8f7..3ed58d8 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,7 @@ First you'll need to make sure your system has a c++ compiler. For OSX, XCode w ### Install script -To install you could use the [install script](https://github.com/creationix/nvm/blob/v0.3.0/install.sh) (requires Git) using cURL: +To install you could use the [install script](https://github.com/creationix/nvm/blob/v0.3.0/install.sh) using cURL: curl https://raw.github.com/creationix/nvm/v0.3.0/install.sh | sh @@ -14,8 +14,11 @@ or Wget: wget -qO- https://raw.github.com/creationix/nvm/v0.3.0/install.sh | sh -The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile` or `~/.profile`). +The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`). +You can customize the install source, directory and profile using the `NVM_SOURCE`, `NVM_DIR` and `NVM_PROFILE` variables. Eg: `curl ... | NVM_DIR=/usr/local/nvm sh` for a global install. + +*NB. The installer can use Git, cURL or Wget to download NVM, whatever is available.* ### Manual install From bce3abaa4bc0c060cf747db8459beab1a6195258 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Fri, 14 Mar 2014 22:41:43 +0100 Subject: [PATCH 08/14] use comparison opts --- install-gitless.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install-gitless.sh b/install-gitless.sh index c24d25b..53d40a2 100755 --- a/install-gitless.sh +++ b/install-gitless.sh @@ -6,11 +6,11 @@ fatalExit (){ echo "$@" && exit 1; } -if [ ! "$NVM_SOURCE" ]; then +if [ -z "$NVM_SOURCE" ]; then NVM_SOURCE="https://raw.github.com/creationix/nvm/master/nvm.sh" fi -if [ ! "$NVM_DIR" ]; then +if [ -z "$NVM_DIR" ]; then NVM_DIR="$HOME/.nvm" fi From 300022642aca488d0fa33f1e1f65756613054a0b Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sat, 15 Mar 2014 04:32:35 +0100 Subject: [PATCH 09/14] git, curl and wget now all in one installer --- install-gitless.sh | 71 -------------------------------------------- install.sh | 73 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 56 insertions(+), 88 deletions(-) delete mode 100755 install-gitless.sh diff --git a/install-gitless.sh b/install-gitless.sh deleted file mode 100755 index 53d40a2..0000000 --- a/install-gitless.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash - -set -e - -fatalExit (){ - echo "$@" && exit 1; -} - -if [ -z "$NVM_SOURCE" ]; then - NVM_SOURCE="https://raw.github.com/creationix/nvm/master/nvm.sh" -fi - -if [ -z "$NVM_DIR" ]; then - NVM_DIR="$HOME/.nvm" -fi - -# Downloading to $NVM_DIR -mkdir -p "$NVM_DIR" -echo -e "\r=> Downloading... \c" - -# Detect if curl or wget is installed to download NVM_SOURCE -if type curl > /dev/null 2>&1; then - curl --silent "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || fatalExit "Failed downloading $NVM_SOURCE"; -elif type wget > /dev/null 2>&1; then - wget --quiet "$NVM_SOURCE" -O "$NVM_DIR/nvm.sh" || fatalExit "Failed downloading $NVM_SOURCE"; -else - fatalExit "Must have curl or wget to install nvm"; -fi - -echo "Downloaded" - -echo - -# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile). -if [ -z "$PROFILE" ]; then - if [ -f "$HOME/.bash_profile" ]; then - PROFILE="$HOME/.bash_profile" - elif [ -f "$HOME/.zshrc" ]; then - PROFILE="$HOME/.zshrc" - elif [ -f "$HOME/.profile" ]; then - PROFILE="$HOME/.profile" - fi -fi - -SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads NVM" - -if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then - if [ -z $PROFILE ]; then - echo "=> Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile." - echo "=> Create one of them and run this script again" - else - echo "=> Profile $PROFILE not found" - echo "=> Create it (touch $PROFILE) and run this script again" - fi - echo " OR" - echo "=> Append the following line to the correct file yourself:" - echo - echo " $SOURCE_STR" - echo -else - 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 -fi - -echo "=> Close and reopen your terminal to start using NVM" - diff --git a/install.sh b/install.sh index 2804803..68fce91 100755 --- a/install.sh +++ b/install.sh @@ -2,34 +2,73 @@ set -e -if [ ! "$NVM_SOURCE" ]; then - NVM_SOURCE="https://github.com/creationix/nvm.git" -fi +has() { + type "$1" > /dev/null 2>&1 + return $? +} -if [ ! "$NVM_DIR" ]; then +if [ -z "$NVM_DIR" ]; then NVM_DIR="$HOME/.nvm" fi -if ! hash git 2>/dev/null; then - echo >&2 "You need to install git - visit http://git-scm.com/downloads" - echo >&2 "or, use install-gitless.sh instead." - exit 1 -fi +download_file() { + # download_file source destination + if has "curl"; then + curl --silent "$1" -o "$2" + elif has "wget"; then + wget --quiet "$1" -O "$2" + else + return 1 + fi +} -if [ -d "$NVM_DIR" ]; then - echo "=> NVM is already installed in $NVM_DIR, trying to update" - echo -e "\r=> \c" - cd "$NVM_DIR" && git pull -else - # Cloning to $NVM_DIR +install_from_git() { + if [ -z "$NVM_SOURCE" ]; then + NVM_SOURCE="https://github.com/creationix/nvm.git" + fi + + if [ -d "$NVM_DIR/.git" ]; then + echo "=> NVM is already installed in $NVM_DIR, trying to update" + echo -e "\r=> \c" + cd "$NVM_DIR" && git pull + else + # Cloning to $NVM_DIR + mkdir -p "$NVM_DIR" + git clone "$NVM_SOURCE" "$NVM_DIR" + fi +} + +install_as_script() { + if [ -z "$NVM_SOURCE" ]; then + NVM_SOURCE="https://raw.github.com/creationix/nvm/master/nvm.sh" + fi + + # Downloading to $NVM_DIR mkdir -p "$NVM_DIR" - git clone "$NVM_SOURCE" "$NVM_DIR" + if [ -d "$NVM_DIR/nvm.sh" ]; then + echo "=> NVM is already installed in $NVM_DIR, trying to update" + else + echo "=> Downloading NVM to '$NVM_DIR'" + fi + download_file "$NVM_SOURCE" "$NVM_DIR/nvm.sh" || { + echo >&2 "Failed.." + return 1 + } +} + +if has "git"; then + install_from_git +else + install_as_script || { + echo >&2 -e "You need git, curl or wget to install NVM" + exit 1 + } fi echo # Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile). -if [ ! "$PROFILE" ]; then +if [ -z "$PROFILE" ]; then if [ -f "$HOME/.bash_profile" ]; then PROFILE="$HOME/.bash_profile" elif [ -f "$HOME/.zshrc" ]; then From c47f03f9969922174e05564d6604f4de652904b4 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Wed, 26 Mar 2014 08:36:41 +0100 Subject: [PATCH 10/14] Display error when unable to update --- install.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 68fce91..be81d9c 100755 --- a/install.sh +++ b/install.sh @@ -30,7 +30,10 @@ install_from_git() { if [ -d "$NVM_DIR/.git" ]; then echo "=> NVM is already installed in $NVM_DIR, trying to update" echo -e "\r=> \c" - cd "$NVM_DIR" && git pull + cd "$NVM_DIR" && git pull 2> /dev/null || { + echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.." + return 0 + } else # Cloning to $NVM_DIR mkdir -p "$NVM_DIR" From 3c2719a85e81c8fba88ca6350f72c702aab201eb Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Wed, 26 Mar 2014 11:14:00 +0100 Subject: [PATCH 11/14] fix --- install.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/install.sh b/install.sh index be81d9c..4f294b4 100755 --- a/install.sh +++ b/install.sh @@ -32,7 +32,6 @@ install_from_git() { echo -e "\r=> \c" cd "$NVM_DIR" && git pull 2> /dev/null || { echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.." - return 0 } else # Cloning to $NVM_DIR From 6ed93f4c010eaf63ece41617cdf27c17f5c17d3a Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Wed, 26 Mar 2014 09:08:37 +0100 Subject: [PATCH 12/14] Force install method by setting METHOD=git/script --- install.sh | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/install.sh b/install.sh index 4f294b4..a414160 100755 --- a/install.sh +++ b/install.sh @@ -14,9 +14,9 @@ fi download_file() { # download_file source destination if has "curl"; then - curl --silent "$1" -o "$2" + curl -s "$1" -o "$2" elif has "wget"; then - wget --quiet "$1" -O "$2" + wget -q "$1" -O "$2" else return 1 fi @@ -28,13 +28,15 @@ install_from_git() { fi if [ -d "$NVM_DIR/.git" ]; then - echo "=> NVM is already installed in $NVM_DIR, trying to update" + echo "=> nvm is already installed in $NVM_DIR, trying to update" echo -e "\r=> \c" cd "$NVM_DIR" && git pull 2> /dev/null || { echo >&2 "Failed to update nvm, run 'git pull' in $NVM_DIR yourself.." } else # Cloning to $NVM_DIR + echo "=> Downloading nvm from git to '$NVM_DIR'" + echo -e "\r=> \c" mkdir -p "$NVM_DIR" git clone "$NVM_SOURCE" "$NVM_DIR" fi @@ -48,23 +50,37 @@ install_as_script() { # Downloading to $NVM_DIR mkdir -p "$NVM_DIR" if [ -d "$NVM_DIR/nvm.sh" ]; then - echo "=> NVM is already installed in $NVM_DIR, trying to update" + echo "=> nvm is already installed in $NVM_DIR, trying to update" else - echo "=> Downloading NVM to '$NVM_DIR'" + echo "=> Downloading nvm as script to '$NVM_DIR'" fi download_file "$NVM_SOURCE" "$NVM_DIR/nvm.sh" || { - echo >&2 "Failed.." + echo >&2 "Failed to download '$NVM_SOURCE'.." return 1 } } -if has "git"; then - install_from_git +if [ -z "$METHOD" ]; then + install_from_git || { + echo >&2 "Install using git failed, falling to back to script" + install_as_script || { + echo >&2 "You need git, curl or wget to install nvm" + exit 1 + } + } else - install_as_script || { - echo >&2 -e "You need git, curl or wget to install NVM" - exit 1 - } + if [ "$METHOD" = "git" ]; then + install_from_git || { + echo >&2 "You need git to install nvm" + exit 1 + } + fi + if [ "$METHOD" = "script" ]; then + install_as_script || { + echo >&2 "You need curl or wget to install nvm" + exit 1 + } + fi fi echo @@ -80,7 +96,7 @@ if [ -z "$PROFILE" ]; then fi fi -SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads NVM" +SOURCE_STR="[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\" # This loads nvm" if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then if [ -z $PROFILE ]; then @@ -105,5 +121,5 @@ else fi fi -echo "=> Close and reopen your terminal to start using NVM" +echo "=> Close and reopen your terminal to start using nvm" From 2d0c025c499e7c592b356b9cb659f2f2b663ccb5 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Wed, 26 Mar 2014 09:16:26 +0100 Subject: [PATCH 13/14] Prevent fallback --- install.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index a414160..e272305 100755 --- a/install.sh +++ b/install.sh @@ -61,13 +61,15 @@ install_as_script() { } if [ -z "$METHOD" ]; then - install_from_git || { - echo >&2 "Install using git failed, falling to back to script" - install_as_script || { - echo >&2 "You need git, curl or wget to install nvm" - exit 1 - } - } + # Autodetect install method + if has "git"; then + install_from_git + elif has "curl" || has "wget"; then + install_as_script + else + echo >&2 "You need git, curl or wget to install nvm" + exit 1 + fi else if [ "$METHOD" = "git" ]; then install_from_git || { From 5342b6a04ce25e8b5f4b316b0c4b4bd3ea33ea34 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Wed, 26 Mar 2014 09:29:05 +0100 Subject: [PATCH 14/14] Emulate curl with wget --- install.sh | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/install.sh b/install.sh index e272305..17b97bb 100755 --- a/install.sh +++ b/install.sh @@ -11,16 +11,17 @@ if [ -z "$NVM_DIR" ]; then NVM_DIR="$HOME/.nvm" fi -download_file() { - # download_file source destination - if has "curl"; then - curl -s "$1" -o "$2" - elif has "wget"; then - wget -q "$1" -O "$2" - else - return 1 +if ! has "curl"; then + if has "wget"; then + # Emulate curl with wget + curl() { + ARGS="$* " + ARGS=${ARGS/-s /-q } + ARGS=${ARGS/-o /-O } + wget $ARGS + } fi -} +fi install_from_git() { if [ -z "$NVM_SOURCE" ]; then @@ -54,7 +55,7 @@ install_as_script() { else echo "=> Downloading nvm as script to '$NVM_DIR'" fi - download_file "$NVM_SOURCE" "$NVM_DIR/nvm.sh" || { + curl -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || { echo >&2 "Failed to download '$NVM_SOURCE'.." return 1 } @@ -64,7 +65,7 @@ if [ -z "$METHOD" ]; then # Autodetect install method if has "git"; then install_from_git - elif has "curl" || has "wget"; then + elif has "curl"; then install_as_script else echo >&2 "You need git, curl or wget to install nvm" @@ -72,16 +73,18 @@ if [ -z "$METHOD" ]; then fi else if [ "$METHOD" = "git" ]; then - install_from_git || { + if ! has "git"; then echo >&2 "You need git to install nvm" exit 1 - } + fi + install_from_git fi if [ "$METHOD" = "script" ]; then - install_as_script || { + if ! has "curl"; then echo >&2 "You need curl or wget to install nvm" exit 1 - } + fi + install_as_script fi fi