From b1d0cfa77b1c59afa5a9aa0764ef7cee47a08c45 Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Wed, 5 Jun 2013 06:13:47 -0500 Subject: [PATCH 1/2] Added mirror option for node binaries --- nvm.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/nvm.sh b/nvm.sh index b1d061a..2f611c7 100755 --- a/nvm.sh +++ b/nvm.sh @@ -24,6 +24,11 @@ if [ ! -d "$NVM_DIR" ]; then export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname ${BASH_SOURCE[0]:-$0}) > /dev/null && pwd) fi +# Setup mirror location if not already set +if [ -z "$NODEJS_MIRROR" ]; then + export NODEJS_MIRROR="http://nodejs.org" +fi + nvm_set_nullglob() { if has "setopt"; then # Zsh @@ -105,7 +110,7 @@ nvm_ls_remote() { else PATTERN=".*" fi - VERSIONS=`curl -s http://nodejs.org/dist/ \ + VERSIONS=`curl -s $NODEJS_MIRROR/dist/ \ | \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \ | \grep -w "${PATTERN}" \ | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n` @@ -262,8 +267,8 @@ nvm() { esac if [ $binavail -eq 1 ]; then t="$VERSION-$os-$arch" - url="http://nodejs.org/dist/$VERSION/node-${t}.tar.gz" - sum=`curl -s http://nodejs.org/dist/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'` + url="$NODEJS_MIRROR/dist/$VERSION/node-${t}.tar.gz" + sum=`curl -s $NODEJS_MIRROR/dist/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'` local tmpdir="$NVM_DIR/bin/node-${t}" local tmptarball="$tmpdir/node-${t}.tar.gz" if ( @@ -295,11 +300,11 @@ nvm() { fi local tmpdir="$NVM_DIR/src" local tmptarball="$tmpdir/node-$VERSION.tar.gz" - if [ "`curl -Is "http://nodejs.org/dist/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then - tarball="http://nodejs.org/dist/$VERSION/node-$VERSION.tar.gz" - sum=`curl -s http://nodejs.org/dist/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'` - elif [ "`curl -Is "http://nodejs.org/dist/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then - tarball="http://nodejs.org/dist/node-$VERSION.tar.gz" + if [ "`curl -Is "$NODEJS_MIRROR/dist/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then + tarball="$NODEJS_MIRROR/dist/$VERSION/node-$VERSION.tar.gz" + sum=`curl -s $NODEJS_MIRROR/dist/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'` + elif [ "`curl -Is "$NODEJS_MIRROR/dist/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then + tarball="$NODEJS_MIRROR/dist/node-$VERSION.tar.gz" fi if ( [ ! -z $tarball ] && \ From 8599ea29f939ac455c4a912df546bab2b352c345 Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Thu, 30 Jan 2014 19:22:44 -0800 Subject: [PATCH 2/2] Add dist to path, add docs --- README.markdown | 5 +++++ nvm.sh | 18 +++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.markdown b/README.markdown index 135e8e5..cf96406 100644 --- a/README.markdown +++ b/README.markdown @@ -66,6 +66,11 @@ To set a default Node version to be used in any new shell, use the alias 'defaul nvm alias default 0.10 +To use a mirror of the node binaries, set `$NODEJS_MIRROR`: + + export NODEJS_MIRROR=http://nodejs.org/dist + nvm install 0.10 + ## License nvm is released under the MIT license. diff --git a/nvm.sh b/nvm.sh index 2f611c7..cdb8641 100755 --- a/nvm.sh +++ b/nvm.sh @@ -26,7 +26,7 @@ fi # Setup mirror location if not already set if [ -z "$NODEJS_MIRROR" ]; then - export NODEJS_MIRROR="http://nodejs.org" + export NODEJS_MIRROR="http://nodejs.org/dist" fi nvm_set_nullglob() { @@ -110,7 +110,7 @@ nvm_ls_remote() { else PATTERN=".*" fi - VERSIONS=`curl -s $NODEJS_MIRROR/dist/ \ + VERSIONS=`curl -s $NODEJS_MIRROR/ \ | \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \ | \grep -w "${PATTERN}" \ | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n` @@ -267,8 +267,8 @@ nvm() { esac if [ $binavail -eq 1 ]; then t="$VERSION-$os-$arch" - url="$NODEJS_MIRROR/dist/$VERSION/node-${t}.tar.gz" - sum=`curl -s $NODEJS_MIRROR/dist/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'` + url="$NODEJS_MIRROR/$VERSION/node-${t}.tar.gz" + sum=`curl -s $NODEJS_MIRROR/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'` local tmpdir="$NVM_DIR/bin/node-${t}" local tmptarball="$tmpdir/node-${t}.tar.gz" if ( @@ -300,11 +300,11 @@ nvm() { fi local tmpdir="$NVM_DIR/src" local tmptarball="$tmpdir/node-$VERSION.tar.gz" - if [ "`curl -Is "$NODEJS_MIRROR/dist/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then - tarball="$NODEJS_MIRROR/dist/$VERSION/node-$VERSION.tar.gz" - sum=`curl -s $NODEJS_MIRROR/dist/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'` - elif [ "`curl -Is "$NODEJS_MIRROR/dist/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then - tarball="$NODEJS_MIRROR/dist/node-$VERSION.tar.gz" + if [ "`curl -Is "$NODEJS_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then + tarball="$NODEJS_MIRROR/$VERSION/node-$VERSION.tar.gz" + sum=`curl -s $NODEJS_MIRROR/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'` + elif [ "`curl -Is "$NODEJS_MIRROR/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then + tarball="$NODEJS_MIRROR/node-$VERSION.tar.gz" fi if ( [ ! -z $tarball ] && \