diff --git a/install.sh b/install.sh index 3c33289..73d3ed2 100755 --- a/install.sh +++ b/install.sh @@ -42,19 +42,23 @@ nvm_profile_is_bash_or_zsh() { # NVM_SOURCE always takes precedence unless the method is "script-nvm-exec" # nvm_source() { + local NVM_GITHUB_REPO + NVM_GITHUB_REPO="${NVM_INSTALL_GITHUB_REPO:-nvm-sh/nvm}" + local NVM_VERSION + NVM_VERSION="${NVM_INSTALL_VERSION:-$(nvm_latest_version)}" local NVM_METHOD NVM_METHOD="$1" local NVM_SOURCE_URL NVM_SOURCE_URL="$NVM_SOURCE" if [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then - NVM_SOURCE_URL="https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/nvm-exec" + NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/nvm-exec" elif [ "_$NVM_METHOD" = "_script-nvm-bash-completion" ]; then - NVM_SOURCE_URL="https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/bash_completion" + NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/bash_completion" elif [ -z "$NVM_SOURCE_URL" ]; then if [ "_$NVM_METHOD" = "_script" ]; then - NVM_SOURCE_URL="https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/nvm.sh" + NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_REPO}/${NVM_VERSION}/nvm.sh" elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then - NVM_SOURCE_URL="https://github.com/nvm-sh/nvm.git" + NVM_SOURCE_URL="https://github.com/${NVM_GITHUB_REPO}.git" else echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD" return 1 diff --git a/test/install_script/nvm_install_with_aliased_dot b/test/install_script/nvm_install_with_aliased_dot index b8f05a5..e1b19a1 100755 --- a/test/install_script/nvm_install_with_aliased_dot +++ b/test/install_script/nvm_install_with_aliased_dot @@ -1,6 +1,8 @@ #!/bin/sh -setup () { +setup() { + # Needed to avoid to checkout the repo to the latest nvm version, losing the commits of the current PR + unset NVM_DIR shopt -s expand_aliases alias .=':' NVM_ENV=testing \. ../../install.sh > /dev/null @@ -12,7 +14,7 @@ cleanup () { shopt -u expand_aliases } -die () { echo "$@"; exit 1; } +die () { echo "$@"; cleanup; exit 1; } setup diff --git a/test/install_script/nvm_install_with_node_version b/test/install_script/nvm_install_with_node_version index 5f5208f..aef4f0e 100755 --- a/test/install_script/nvm_install_with_node_version +++ b/test/install_script/nvm_install_with_node_version @@ -2,6 +2,8 @@ die () { echo "$@" ; exit 1; } +# Needed to avoid to checkout the repo to the latest nvm version, losing the commits of the current PR +unset NVM_DIR NODE_VERSION=8 \. ../../install.sh # nvm installed node 8 diff --git a/test/install_script/nvm_source b/test/install_script/nvm_source index 9c1ec08..140afd5 100755 --- a/test/install_script/nvm_source +++ b/test/install_script/nvm_source @@ -9,16 +9,20 @@ die () { echo "$@" ; cleanup ; exit 1; } NVM_ENV=testing \. ../../install.sh # nvm_source with no parameter returns the git endpoint -echo $(nvm_source) | grep "nvm.git$" > /dev/null || die "nvm_source without arguments should return the location of the git repo" +[ "$(nvm_source)" = "https://github.com/nvm-sh/nvm.git" ] || die "nvm_source without arguments should return the location of the git repo" +NVM_INSTALL_GITHUB_REPO="other-user/other-nvm" nvm_source | grep "https://github.com/other-user/other-nvm.git$" > /dev/null || die "NVM_INSTALL_GITHUB_REPO=... nvm_source without arguments should return the location of the given git repo" # nvm_source with git parameter returns the location of the nvm repo -echo $(nvm_source "git") | grep "nvm.git$" > /dev/null || die "nvm_source without arguments should return the location of the git repo" +[ "$(nvm_source "git")" = "https://github.com/nvm-sh/nvm.git" ] || die "nvm_source \"git\" should return the location of the git repo" +NVM_INSTALL_GITHUB_REPO="other-user/other-nvm" nvm_source "git" | grep "https://github.com/other-user/other-nvm.git$" > /dev/null || die "NVM_INSTALL_GITHUB_REPO=... nvm_source \"git\" should return the location of the given git repo" # nvm_source with script parameter returns the location of nvm.sh -echo $(nvm_source "script") | grep "nvm.sh$" > /dev/null || die "nvm_source \"script\" should return the location of nvm.sh" +[ "$(nvm_source "script")" = "https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/nvm.sh" ] || die "nvm_source \"script\" should return the location of nvm.sh" +NVM_INSTALL_GITHUB_REPO="other-user/other-nvm" NVM_INSTALL_VERSION="v0.37.0" nvm_source "script" | grep "https://raw.githubusercontent.com/other-user/other-nvm/v0.37.0/nvm.sh$" > /dev/null || die "NVM_INSTALL_GITHUB_REPO=... NVM_INSTALL_VERSION=... nvm_source \"script\" should return the location of nvm.sh" # nvm_source with script-nvm-exec parameter returns the location of nvm-exec -echo $(nvm_source "script-nvm-exec") | grep "nvm-exec$" > /dev/null || die "nvm_source \"script-nvm-exec\" should return the location of nvm.sh" +[ "$(nvm_source "script-nvm-exec")" = "https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/nvm-exec" ] || die "nvm_source \"script-nvm-exec\" should return the location of nvm.sh" +NVM_INSTALL_GITHUB_REPO="other-user/other-nvm" NVM_INSTALL_VERSION="v0.37.0" nvm_source "script-nvm-exec" | grep "https://raw.githubusercontent.com/other-user/other-nvm/v0.37.0/nvm-exec$" > /dev/null || die "NVM_INSTALL_GITHUB_REPO=... NVM_INSTALL_VERSION=... nvm_source \"script-nvm-exec\" should return the location of nvm.sh" # nvm_source with any other parameter errors out and exits nvm_source "anything" 2> /dev/null && die "nvm_source with invalid parameter should exit"