Added mirror option for node binaries

master
Kyle Kelley 2013-06-05 06:13:47 -05:00 committed by Kyle Kelley
parent a0a2ee4414
commit b1d0cfa77b
1 changed files with 13 additions and 8 deletions

21
nvm.sh
View File

@ -24,6 +24,11 @@ if [ ! -d "$NVM_DIR" ]; then
export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname ${BASH_SOURCE[0]:-$0}) > /dev/null && pwd) export NVM_DIR=$(cd $NVM_CD_FLAGS $(dirname ${BASH_SOURCE[0]:-$0}) > /dev/null && pwd)
fi fi
# Setup mirror location if not already set
if [ -z "$NODEJS_MIRROR" ]; then
export NODEJS_MIRROR="http://nodejs.org"
fi
nvm_set_nullglob() { nvm_set_nullglob() {
if has "setopt"; then if has "setopt"; then
# Zsh # Zsh
@ -105,7 +110,7 @@ nvm_ls_remote() {
else else
PATTERN=".*" PATTERN=".*"
fi fi
VERSIONS=`curl -s http://nodejs.org/dist/ \ VERSIONS=`curl -s $NODEJS_MIRROR/dist/ \
| \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \ | \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' \
| \grep -w "${PATTERN}" \ | \grep -w "${PATTERN}" \
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n` | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`
@ -262,8 +267,8 @@ nvm() {
esac esac
if [ $binavail -eq 1 ]; then if [ $binavail -eq 1 ]; then
t="$VERSION-$os-$arch" t="$VERSION-$os-$arch"
url="http://nodejs.org/dist/$VERSION/node-${t}.tar.gz" url="$NODEJS_MIRROR/dist/$VERSION/node-${t}.tar.gz"
sum=`curl -s http://nodejs.org/dist/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'` 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 tmpdir="$NVM_DIR/bin/node-${t}"
local tmptarball="$tmpdir/node-${t}.tar.gz" local tmptarball="$tmpdir/node-${t}.tar.gz"
if ( if (
@ -295,11 +300,11 @@ nvm() {
fi fi
local tmpdir="$NVM_DIR/src" local tmpdir="$NVM_DIR/src"
local tmptarball="$tmpdir/node-$VERSION.tar.gz" local tmptarball="$tmpdir/node-$VERSION.tar.gz"
if [ "`curl -Is "http://nodejs.org/dist/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then if [ "`curl -Is "$NODEJS_MIRROR/dist/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
tarball="http://nodejs.org/dist/$VERSION/node-$VERSION.tar.gz" tarball="$NODEJS_MIRROR/dist/$VERSION/node-$VERSION.tar.gz"
sum=`curl -s http://nodejs.org/dist/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'` sum=`curl -s $NODEJS_MIRROR/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 elif [ "`curl -Is "$NODEJS_MIRROR/dist/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
tarball="http://nodejs.org/dist/node-$VERSION.tar.gz" tarball="$NODEJS_MIRROR/dist/node-$VERSION.tar.gz"
fi fi
if ( if (
[ ! -z $tarball ] && \ [ ! -z $tarball ] && \