Merge pull request #567 from xcambar/nvm_source
Before adoption: this commit came in with the history the project adopted, so no landing records it.
[install script] Refactors NVM_SOURCE
authored by Jordan Harband · committed by Jordan Harband · parents e28a257, 516e553 · Browse files · 2 files·+69 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+69 added−10 removed
- tests:+37 added−0 removed
- other:+32 added−10 removed
Provenance
- Commit
ce82109- Tree
ae24a2f- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent 1
e28a257- Parent 2
516e553
2 files changed+69 added−10 removed
added:test/install_script/nvm_source+37 added
1+#!/bin/sh2+3+cleanup () {4+ unset -f die cleanup5+ unset NVM_SOURCE out6+}7+die () { echo $@ ; cleanup ; exit 1; }8+9+NVM_ENV=testing . ../../install.sh10+11+# nvm_source with no parameter returns the git endpoint12+echo $(nvm_source) | grep "nvm.git$" > /dev/null || die "nvm_source without arguments should return the location of the git repo" 13+14+# nvm_source with git parameter returns the location of the nvm repo15+echo $(nvm_source "git") | grep "nvm.git$" > /dev/null || die "nvm_source without arguments should return the location of the git repo" 16+17+# nvm_source with script parameter returns the location of nvm.sh18+echo $(nvm_source "script") | grep "nvm.sh$" > /dev/null || die "nvm_source \"script\" should return the location of nvm.sh"19+20+# nvm_source with any other parameter errors out and exits21+nvm_source "anything" 2> /dev/null && die "nvm_source with invalid parameter should exit"22+out=$(nvm_source "anything" 2>&1 >/dev/null) || : #Saving the process here23+[ -z "$out" ] && die "nvm_source with invalid parameter should error out"24+25+#nvm_source should always return NVM_SOURCE no matter the parameters26+NVM_SOURCE="my_location"27+out=$(nvm_source)28+[ "_$out" = "_my_location" ] || die "nvm_source without arguments should have returned \$NVM_SOURCE. Got \"$out\""29+out=$(nvm_source "git")30+[ "_$out" = "_my_location" ] || die "nvm_source git should have returned \$NVM_SOURCE. Got \"$out\""31+out=$(nvm_source "script")32+[ "_$out" = "_my_location" ] || die "nvm_source script should have returned \$NVM_SOURCE. Got \"$out\""33+out=$(nvm_source "anything")34+[ "_$out" = "_my_location" ] || die "nvm_source script should have returned \$NVM_SOURCE. Got \"$out\""35+36+cleanup37+modified:install.sh+32 added-10 removed
9 unmodified lines10111213141516171819202122232425262728293031323334353637383940414243448 unmodified lines5354555630313233575859603 unmodified lines64656667456869707172737452535475767778798081828384636485868788899082 unmodified lines9 unmodified linesif [ -z "$NVM_DIR" ]; then NVM_DIR="$HOME/.nvm"fi
## Outputs the location to NVM depending on:# * The availability of $NVM_SOURCE# * The method used ("script" or "git" in the script, defaults to "git")# NVM_SOURCE always takes precedence#nvm_source() { local NVM_METHOD NVM_METHOD="$1" if [ -z "$NVM_SOURCE" ]; then local NVM_SOURCE else echo "$NVM_SOURCE" return 0 fi if [ "_$NVM_METHOD" = "_script" ]; then NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.18.0/nvm.sh" elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then NVM_SOURCE="https://github.com/creationix/nvm.git" else echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD" return 1 fi echo "$NVM_SOURCE" return 0}
nvm_download() { if nvm_has "curl"; then curl $* elif nvm_has "wget"; then8 unmodified lines fi}
install_nvm_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" printf "\r=> " cd "$NVM_DIR" && (git fetch 2> /dev/null || {3 unmodified lines # Cloning to $NVM_DIR echo "=> Downloading nvm from git to '$NVM_DIR'" printf "\r=> " mkdir -p "$NVM_DIR" git clone "$NVM_SOURCE" "$NVM_DIR" git clone "$(nvm_source "git")" "$NVM_DIR" fi cd "$NVM_DIR" && git checkout v0.18.0 && git branch -D master >/dev/null 2>&1 return}
install_nvm_as_script() { if [ -z "$NVM_SOURCE" ]; then NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.18.0/nvm.sh" fi local NVM_SOURCE NVM_SOURCE=$(nvm_source "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" else echo "=> Downloading nvm as script to '$NVM_DIR'" fi nvm_download -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || { echo >&2 "Failed to download '$NVM_SOURCE'.." nvm_download -s "$_source" -o "$NVM_DIR/nvm.sh" || { echo >&2 "Failed to download '$_source'.." return 1 }}
82 unmodified lines