Merge pull request #566 from xcambar/nvm_install_dir
Before adoption: this commit came in with the history the project adopted, so no landing records it.
[install script] Refactors NVM_DIR; adds tests
authored by Jordan Harband · committed by GitHub · parents c4be39b, 6cee20a · Browse files · 2 files·+55 added−22 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+55 added−22 removed
- tests:+25 added−0 removed
- other:+30 added−22 removed
Provenance
- Commit
39c119c- Tree
ea5470c- Author
Jordan Harband <ljharb@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
c4be39b- Parent 2
6cee20a
2 files changed+55 added−22 removed
added:test/install_script/nvm_install_dir+25 added
1+#!/bin/sh2+3+cleanup () {4+ unset -f die cleanup5+ unset install_dir6+}7+die () { echo $@ ; cleanup ; exit 1; }8+9+NVM_ENV=testing . ../../install.sh10+HOME="__home__"11+12+13+# NVM_DIR is set14+NVM_DIR="some_dir" 15+install_dir=$(nvm_install_dir)16+[ "_$install_dir" = "_$NVM_DIR" ] || die "nvm_install_dir should use \$NVM_DIR if it exists. Current output: $install_dir"17+18+unset NVM_DIR19+20+# NVM_DIR is not set21+install_dir=$(nvm_install_dir)22+[ "_$install_dir" = "_$HOME/.nvm" ] || die "nvm_install_dir should default to \$HOME/.nvm. Current output: $install_dir"23+24+cleanup25+modified:install.sh+30 added-22 removed
4 unmodified lines5 nvm_has() {6 type "$1" > /dev/null 2>&17 }8 9-if [ -z "$NVM_DIR" ]; then10- NVM_DIR="$HOME/.nvm"11-fi9+nvm_install_dir() {10+ echo ${NVM_DIR:-"$HOME/.nvm"}11+}12 13 nvm_latest_version() {14 echo "v0.31.2"15 }39 unmodified lines55 fi56 }57 58 install_nvm_from_git() {59+ local INSTALL_DIR60+ INSTALL_DIR="$(nvm_install_dir)"61+59- if [ -d "$NVM_DIR/.git" ]; then60- echo "=> nvm is already installed in $NVM_DIR, trying to update using git"62+ if [ -d "$INSTALL_DIR/.git" ]; then63+ echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"64 printf "\r=> "62- cd "$NVM_DIR" && (command git fetch 2> /dev/null || {63- echo >&2 "Failed to update nvm, run 'git fetch' in $NVM_DIR yourself." && exit 165+ cd "$INSTALL_DIR" && (git fetch 2> /dev/null || {66+ echo >&2 "Failed to update nvm, run 'git fetch' in $INSTALL_DIR yourself." && exit 167 })68 else69 # Cloning to $NVM_DIR67- echo "=> Downloading nvm from git to '$NVM_DIR'"70+ echo "=> Downloading nvm from git to '$INSTALL_DIR'"71 printf "\r=> "69- mkdir -p "$NVM_DIR"70- command git clone "$(nvm_source git)" "$NVM_DIR"72+ mkdir -p "$INSTALL_DIR"73+ git clone "$(nvm_source)" "$INSTALL_DIR"74 fi72- cd "$NVM_DIR" && command git checkout --quiet "$(nvm_latest_version)"73- if [ ! -z "$(cd "$NVM_DIR" && git show-ref refs/heads/master)" ]; then75+ cd "$INSTALL_DIR" && command git checkout --quiet "$(nvm_latest_version)"76+ if [ ! -z "$(cd "$INSTALL_DIR" && git show-ref refs/heads/master)" ]; then77 if git branch --quiet 2>/dev/null; then75- cd "$NVM_DIR" && command git branch --quiet -D master >/dev/null 2>&178+ cd "$INSTALL_DIR" && command git branch --quiet -D master >/dev/null 2>&179 else80 echo >&2 "Your version of git is out of date. Please update it!"78- cd "$NVM_DIR" && command git branch -D master >/dev/null 2>&181+ cd "$INSTALL_DIR" && command git branch -D master >/dev/null 2>&182 fi83 fi84 return85 }86 87 install_nvm_as_script() {88+ local INSTALL_DIR89+ INSTALL_DIR="$(nvm_install_dir)"90 local NVM_SOURCE_LOCAL91 NVM_SOURCE_LOCAL=$(nvm_source script)92 local NVM_EXEC_SOURCE93 NVM_EXEC_SOURCE=$(nvm_source script-nvm-exec)94 90- # Downloading to $NVM_DIR91- mkdir -p "$NVM_DIR"92- if [ -f "$NVM_DIR/nvm.sh" ]; then93- echo "=> nvm is already installed in $NVM_DIR, trying to update the script"95+ # Downloading to $INSTALL_DIR96+ mkdir -p "$INSTALL_DIR"97+ if [ -f "$INSTALL_DIR/nvm.sh" ]; then98+ echo "=> nvm is already installed in $INSTALL_DIR, trying to update the script"99 else95- echo "=> Downloading nvm as script to '$NVM_DIR'"100+ echo "=> Downloading nvm as script to '$INSTALL_DIR'"101 fi97- nvm_download -s "$NVM_SOURCE_LOCAL" -o "$NVM_DIR/nvm.sh" || {102+ nvm_download -s "$NVM_SOURCE_LOCAL" -o "$INSTALL_DIR/nvm.sh" || {103 echo >&2 "Failed to download '$NVM_SOURCE_LOCAL'"104 return 1105 }106 nvm_download -s "$NVM_EXEC_SOURCE" -o "$NVM_DIR/nvm-exec" || {125 unmodified lines232 echo233 234 local NVM_PROFILE235 NVM_PROFILE=$(nvm_detect_profile)236+ local INSTALL_DIR237+ INSTALL_DIR="$(nvm_install_dir)"238 232- SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"239+ SOURCE_STR="\nexport NVM_DIR=\"$INSTALL_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"240 241 if [ -z "$NVM_PROFILE" ] ; then242 echo "=> Profile not found. Tried $NVM_PROFILE (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."243 echo "=> Create one of them and run this script again"23 unmodified lines267 #268 nvm_reset() {269 unset -f nvm_reset nvm_has nvm_latest_version \270 nvm_source nvm_download install_nvm_as_script install_nvm_from_git \264- nvm_detect_profile nvm_check_global_modules nvm_do_install271+ nvm_detect_profile nvm_check_global_modules nvm_do_install \272+ nvm_install_dir273 }274 275 [ "_$NVM_ENV" = "_testing" ] || nvm_do_install276 1 unmodified line