Use `nvm_curl` instead of `curl` directly, which has a `wget` fallback.
parent
25c0be1e20
commit
b9383c9016
36
nvm.sh
36
nvm.sh
|
@ -12,6 +12,20 @@ nvm_has() {
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if nvm_has "curl"; then
|
||||||
|
nvm_curl() {
|
||||||
|
curl $*
|
||||||
|
}
|
||||||
|
elif nvm_has "wget"; then
|
||||||
|
# Emulate curl with wget
|
||||||
|
nvm_curl() {
|
||||||
|
ARGS="$* "
|
||||||
|
ARGS=${ARGS/-s /-q }
|
||||||
|
ARGS=${ARGS/-o /-O }
|
||||||
|
wget "$ARGS"
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
# Make zsh glob matching behave same as bash
|
# Make zsh glob matching behave same as bash
|
||||||
# This fixes the "zsh: no matches found" errors
|
# This fixes the "zsh: no matches found" errors
|
||||||
if nvm_has "unsetopt"; then
|
if nvm_has "unsetopt"; then
|
||||||
|
@ -164,7 +178,7 @@ nvm_ls_remote() {
|
||||||
else
|
else
|
||||||
PATTERN=".*"
|
PATTERN=".*"
|
||||||
fi
|
fi
|
||||||
VERSIONS=`curl -s $NVM_NODEJS_ORG_MIRROR/ \
|
VERSIONS=`nvm_curl -s $NVM_NODEJS_ORG_MIRROR/ \
|
||||||
| \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`
|
||||||
|
@ -290,8 +304,8 @@ nvm() {
|
||||||
version_not_provided=0
|
version_not_provided=0
|
||||||
local provided_version
|
local provided_version
|
||||||
|
|
||||||
if ! nvm_has "curl"; then
|
if ! nvm_has "nvm_curl"; then
|
||||||
echo 'NVM Needs curl to proceed.' >&2;
|
echo 'nvm needs curl or wget to proceed.' >&2;
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -354,14 +368,14 @@ nvm() {
|
||||||
if nvm_binary_available "$VERSION"; then
|
if nvm_binary_available "$VERSION"; then
|
||||||
t="$VERSION-$os-$arch"
|
t="$VERSION-$os-$arch"
|
||||||
url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"
|
url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"
|
||||||
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'`
|
sum=`nvm_curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'`
|
||||||
local tmpdir
|
local tmpdir
|
||||||
tmpdir="$NVM_DIR/bin/node-${t}"
|
tmpdir="$NVM_DIR/bin/node-${t}"
|
||||||
local tmptarball
|
local tmptarball
|
||||||
tmptarball="$tmpdir/node-${t}.tar.gz"
|
tmptarball="$tmpdir/node-${t}.tar.gz"
|
||||||
if (
|
if (
|
||||||
mkdir -p "$tmpdir" && \
|
mkdir -p "$tmpdir" && \
|
||||||
curl -L -C - --progress-bar $url -o "$tmptarball" && \
|
nvm_curl -L -C - --progress-bar $url -o "$tmptarball" && \
|
||||||
nvm_checksum "$tmptarball" $sum && \
|
nvm_checksum "$tmptarball" $sum && \
|
||||||
tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
|
tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
|
||||||
rm -f "$tmptarball" && \
|
rm -f "$tmptarball" && \
|
||||||
|
@ -391,16 +405,16 @@ nvm() {
|
||||||
tmpdir="$NVM_DIR/src"
|
tmpdir="$NVM_DIR/src"
|
||||||
local tmptarball
|
local tmptarball
|
||||||
tmptarball="$tmpdir/node-$VERSION.tar.gz"
|
tmptarball="$tmpdir/node-$VERSION.tar.gz"
|
||||||
if [ "`curl -Is "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
|
if [ "`nvm_curl -Is "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
|
||||||
tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
|
tarball="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz"
|
||||||
sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'`
|
sum=`nvm_curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-$VERSION.tar.gz | awk '{print $1}'`
|
||||||
elif [ "`curl -Is "$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
|
elif [ "`nvm_curl -Is "$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz" | \grep '200 OK'`" != '' ]; then
|
||||||
tarball="$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz"
|
tarball="$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz"
|
||||||
fi
|
fi
|
||||||
if (
|
if (
|
||||||
[ -n "$tarball" ] && \
|
[ -n "$tarball" ] && \
|
||||||
mkdir -p "$tmpdir" && \
|
mkdir -p "$tmpdir" && \
|
||||||
curl -L --progress-bar $tarball -o "$tmptarball" && \
|
nvm_curl -L --progress-bar $tarball -o "$tmptarball" && \
|
||||||
nvm_checksum "$tmptarball" $sum && \
|
nvm_checksum "$tmptarball" $sum && \
|
||||||
tar -xzf "$tmptarball" -C "$tmpdir" && \
|
tar -xzf "$tmptarball" -C "$tmpdir" && \
|
||||||
cd "$tmpdir/node-$VERSION" && \
|
cd "$tmpdir/node-$VERSION" && \
|
||||||
|
@ -419,10 +433,10 @@ nvm() {
|
||||||
if [ "`expr "$VERSION" : '\(^v0\.2\.[0-2]$\)'`" != '' ]; then
|
if [ "`expr "$VERSION" : '\(^v0\.2\.[0-2]$\)'`" != '' ]; then
|
||||||
echo "npm requires node v0.2.3 or higher" >&2
|
echo "npm requires node v0.2.3 or higher" >&2
|
||||||
else
|
else
|
||||||
curl https://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh
|
nvm_curl https://npmjs.org/install.sh | clean=yes npm_install=0.2.19 sh
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
curl https://npmjs.org/install.sh | clean=yes sh
|
nvm_curl https://npmjs.org/install.sh | clean=yes sh
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue