commit
cf5bfecec4
22
install.sh
22
install.sh
|
@ -11,17 +11,21 @@ if [ -z "$NVM_DIR" ]; then
|
||||||
NVM_DIR="$HOME/.nvm"
|
NVM_DIR="$HOME/.nvm"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! nvm_has "curl"; then
|
nvm_curl() {
|
||||||
if nvm_has "wget"; then
|
if nvm_has "curl"; then
|
||||||
|
curl $*
|
||||||
|
elif nvm_has "wget"; then
|
||||||
# Emulate curl with wget
|
# Emulate curl with wget
|
||||||
curl() {
|
|
||||||
ARGS="$*"
|
ARGS="$*"
|
||||||
|
ARGS=${ARGS/--progress-bar /--progress=bar }
|
||||||
|
ARGS=${ARGS/-L /}
|
||||||
|
ARGS=${ARGS/-I /}
|
||||||
ARGS=${ARGS/-s /-q }
|
ARGS=${ARGS/-s /-q }
|
||||||
ARGS=${ARGS/-o /-O }
|
ARGS=${ARGS/-o /-O }
|
||||||
wget "$ARGS"
|
ARGS=${ARGS/-C /-c }
|
||||||
|
wget $ARGS
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
install_nvm_from_git() {
|
install_nvm_from_git() {
|
||||||
if [ -z "$NVM_SOURCE" ]; then
|
if [ -z "$NVM_SOURCE" ]; then
|
||||||
|
@ -55,7 +59,7 @@ install_nvm_as_script() {
|
||||||
else
|
else
|
||||||
echo "=> Downloading nvm as script to '$NVM_DIR'"
|
echo "=> Downloading nvm as script to '$NVM_DIR'"
|
||||||
fi
|
fi
|
||||||
curl -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || {
|
nvm_curl -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || {
|
||||||
echo >&2 "Failed to download '$NVM_SOURCE'.."
|
echo >&2 "Failed to download '$NVM_SOURCE'.."
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
@ -65,7 +69,7 @@ if [ -z "$METHOD" ]; then
|
||||||
# Autodetect install method
|
# Autodetect install method
|
||||||
if nvm_has "git"; then
|
if nvm_has "git"; then
|
||||||
install_nvm_from_git
|
install_nvm_from_git
|
||||||
elif nvm_has "curl"; then
|
elif nvm_has "nvm_curl"; then
|
||||||
install_nvm_as_script
|
install_nvm_as_script
|
||||||
else
|
else
|
||||||
echo >&2 "You need git, curl, or wget to install nvm"
|
echo >&2 "You need git, curl, or wget to install nvm"
|
||||||
|
@ -80,7 +84,7 @@ else
|
||||||
install_nvm_from_git
|
install_nvm_from_git
|
||||||
fi
|
fi
|
||||||
if [ "$METHOD" = "script" ]; then
|
if [ "$METHOD" = "script" ]; then
|
||||||
if ! nvm_has "curl"; then
|
if ! nvm_has "nvm_curl"; then
|
||||||
echo >&2 "You need curl or wget to install nvm"
|
echo >&2 "You need curl or wget to install nvm"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
38
nvm.sh
38
nvm.sh
|
@ -12,6 +12,22 @@ nvm_has() {
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_curl() {
|
||||||
|
if nvm_has "curl"; then
|
||||||
|
curl $*
|
||||||
|
elif nvm_has "wget"; then
|
||||||
|
# Emulate curl with wget
|
||||||
|
ARGS="$*"
|
||||||
|
ARGS=${ARGS/--progress-bar /--progress=bar }
|
||||||
|
ARGS=${ARGS/-L /}
|
||||||
|
ARGS=${ARGS/-I /}
|
||||||
|
ARGS=${ARGS/-s /-q }
|
||||||
|
ARGS=${ARGS/-o /-O }
|
||||||
|
ARGS=${ARGS/-C /-c }
|
||||||
|
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 +180,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/ -o - \
|
||||||
| \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 +306,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 +370,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 -o - | \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 +407,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 -s -I "$NVM_NODEJS_ORG_MIRROR/$VERSION/node-$VERSION.tar.gz" -o - | \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 -o - | \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 -s -I "$NVM_NODEJS_ORG_MIRROR/node-$VERSION.tar.gz" -o - | \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 +435,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 -o - | 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 -o - | clean=yes sh
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue