added -s (install from source) option.
parent
881178db01
commit
7013372867
76
nvm.sh
76
nvm.sh
|
@ -151,7 +151,7 @@ nvm()
|
||||||
echo
|
echo
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo " nvm help Show this message"
|
echo " nvm help Show this message"
|
||||||
echo " nvm install <version> Download and install a <version>"
|
echo " nvm install [-s] <version> Download and install a <version>"
|
||||||
echo " nvm uninstall <version> Uninstall a version"
|
echo " nvm uninstall <version> Uninstall a version"
|
||||||
echo " nvm use <version> Modify PATH to use <version>"
|
echo " nvm use <version> Modify PATH to use <version>"
|
||||||
echo " nvm run <version> [<args>] Run <version> with <args> as arguments"
|
echo " nvm run <version> [<args>] Run <version> with <args> as arguments"
|
||||||
|
@ -180,6 +180,7 @@ nvm()
|
||||||
local sum
|
local sum
|
||||||
local tarball
|
local tarball
|
||||||
local shasum='shasum'
|
local shasum='shasum'
|
||||||
|
local nobinary
|
||||||
|
|
||||||
if [ ! `which curl` ]; then
|
if [ ! `which curl` ]; then
|
||||||
echo 'NVM Needs curl to proceed.' >&2;
|
echo 'NVM Needs curl to proceed.' >&2;
|
||||||
|
@ -193,10 +194,20 @@ nvm()
|
||||||
nvm help
|
nvm help
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
VERSION=`nvm_remote_version $2`
|
|
||||||
|
shift
|
||||||
|
|
||||||
|
nobinary=0
|
||||||
|
if [ "$1" = "-s" ]; then
|
||||||
|
nobinary=1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
VERSION=`nvm_remote_version $1`
|
||||||
ADDITIONAL_PARAMETERS=''
|
ADDITIONAL_PARAMETERS=''
|
||||||
|
|
||||||
shift
|
shift
|
||||||
shift
|
|
||||||
while [ $# -ne 0 ]
|
while [ $# -ne 0 ]
|
||||||
do
|
do
|
||||||
ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1"
|
ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1"
|
||||||
|
@ -205,34 +216,37 @@ nvm()
|
||||||
|
|
||||||
[ -d "$NVM_DIR/$VERSION" ] && echo "$VERSION is already installed." && return
|
[ -d "$NVM_DIR/$VERSION" ] && echo "$VERSION is already installed." && return
|
||||||
|
|
||||||
# shortcut - try the binary if possible.
|
# skip binary install if no binary option specified.
|
||||||
if [ -n "$os" ]; then
|
if [ $nobinary -ne 1 ]; then
|
||||||
binavail=
|
# shortcut - try the binary if possible.
|
||||||
# binaries started with node 0.8.6
|
if [ -n "$os" ]; then
|
||||||
case "$VERSION" in
|
binavail=
|
||||||
v0.8.[012345]) binavail=0 ;;
|
# binaries started with node 0.8.6
|
||||||
v0.[1234567]) binavail=0 ;;
|
case "$VERSION" in
|
||||||
*) binavail=1 ;;
|
v0.8.[012345]) binavail=0 ;;
|
||||||
esac
|
v0.[1234567]) binavail=0 ;;
|
||||||
if [ $binavail -eq 1 ]; then
|
*) binavail=1 ;;
|
||||||
t="$VERSION-$os-$arch"
|
esac
|
||||||
url="http://nodejs.org/dist/$VERSION/node-${t}.tar.gz"
|
if [ $binavail -eq 1 ]; then
|
||||||
sum=`curl -s http://nodejs.org/dist/$VERSION/SHASUMS.txt.asc | grep node-${t}.tar.gz | awk '{print $1}'`
|
t="$VERSION-$os-$arch"
|
||||||
if (
|
url="http://nodejs.org/dist/$VERSION/node-${t}.tar.gz"
|
||||||
mkdir -p "$NVM_DIR/bin/node-${t}" && \
|
sum=`curl -s http://nodejs.org/dist/$VERSION/SHASUMS.txt.asc | grep node-${t}.tar.gz | awk '{print $1}'`
|
||||||
cd "$NVM_DIR/bin" && \
|
if (
|
||||||
curl -C - --progress-bar $url -o "node-${t}.tar.gz" && \
|
mkdir -p "$NVM_DIR/bin/node-${t}" && \
|
||||||
nvm_checksum `${shasum} node-${t}.tar.gz | awk '{print $1}'` $sum && \
|
cd "$NVM_DIR/bin" && \
|
||||||
tar -xzf "node-${t}.tar.gz" -C "node-${t}" --strip-components 1 && \
|
curl -C - --progress-bar $url -o "node-${t}.tar.gz" && \
|
||||||
mv "node-${t}" "../$VERSION" && \
|
nvm_checksum `${shasum} node-${t}.tar.gz | awk '{print $1}'` $sum && \
|
||||||
rm -f "node-${t}.tar.gz"
|
tar -xzf "node-${t}.tar.gz" -C "node-${t}" --strip-components 1 && \
|
||||||
)
|
mv "node-${t}" "../$VERSION" && \
|
||||||
then
|
rm -f "node-${t}.tar.gz"
|
||||||
nvm use $VERSION
|
)
|
||||||
return;
|
then
|
||||||
else
|
nvm use $VERSION
|
||||||
echo "Binary download failed, trying source." >&2
|
return;
|
||||||
cd "$NVM_DIR/bin" && rm -rf "node-${t}.tar.gz" "node-${t}"
|
else
|
||||||
|
echo "Binary download failed, trying source." >&2
|
||||||
|
cd "$NVM_DIR/bin" && rm -rf "node-${t}.tar.gz" "node-${t}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue