This commit is contained in:
Ketan Padegaonkar 2015-04-03 03:46:33 +00:00
commit f949844a10
1 changed files with 55 additions and 15 deletions

70
nvm.sh
View File

@ -41,6 +41,7 @@ nvm_download() {
elif nvm_has "wget"; then elif nvm_has "wget"; then
# Emulate curl with wget # Emulate curl with wget
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \ ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
-e 's/--silent /--quiet /'
-e 's/-L //' \ -e 's/-L //' \
-e 's/-I /--server-response /' \ -e 's/-I /--server-response /' \
-e 's/-s /-q /' \ -e 's/-s /-q /' \
@ -871,12 +872,20 @@ nvm_install_iojs_binary() {
PREFIXED_VERSION="$1" PREFIXED_VERSION="$1"
local REINSTALL_PACKAGES_FROM local REINSTALL_PACKAGES_FROM
REINSTALL_PACKAGES_FROM="$2" REINSTALL_PACKAGES_FROM="$2"
local QUIET
QUIET="$3"
local PROGRESS_BAR
PROGRESS_BAR="--progress-bar "
if ! nvm_is_iojs_version "$PREFIXED_VERSION"; then if ! nvm_is_iojs_version "$PREFIXED_VERSION"; then
echo 'nvm_install_iojs_binary requires an iojs-prefixed version.' >&2 echo 'nvm_install_iojs_binary requires an iojs-prefixed version.' >&2
return 10 return 10
fi fi
if [ "$QUIET" == '1' ]; then
PROGRESS_BAR="--silent "
fi
local VERSION local VERSION
VERSION="$(nvm_strip_iojs_prefix "$PREFIXED_VERSION")" VERSION="$(nvm_strip_iojs_prefix "$PREFIXED_VERSION")"
local VERSION_PATH local VERSION_PATH
@ -898,7 +907,7 @@ nvm_install_iojs_binary() {
tmptarball="$tmpdir/iojs-${t}.tar.gz" tmptarball="$tmpdir/iojs-${t}.tar.gz"
if ( if (
command mkdir -p "$tmpdir" && \ command mkdir -p "$tmpdir" && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \ nvm_download -L -C - "$PROGRESS_BAR" $url -o "$tmptarball" && \
echo "WARNING: checksums are currently disabled for io.js" >&2 && \ echo "WARNING: checksums are currently disabled for io.js" >&2 && \
# nvm_checksum "$tmptarball" $sum && \ # nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \ command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
@ -922,12 +931,20 @@ nvm_install_node_binary() {
VERSION="$1" VERSION="$1"
local REINSTALL_PACKAGES_FROM local REINSTALL_PACKAGES_FROM
REINSTALL_PACKAGES_FROM="$2" REINSTALL_PACKAGES_FROM="$2"
local QUIET
QUIET="$3"
local PROGRESS_BAR
PROGRESS_BAR="--progress-bar "
if nvm_is_iojs_version "$PREFIXED_VERSION"; then if nvm_is_iojs_version "$PREFIXED_VERSION"; then
echo 'nvm_install_node_binary does not allow an iojs-prefixed version.' >&2 echo 'nvm_install_node_binary does not allow an iojs-prefixed version.' >&2
return 10 return 10
fi fi
if [ "$QUIET" == '1' ]; then
PROGRESS_BAR="--silent "
fi
local VERSION_PATH local VERSION_PATH
VERSION_PATH="$(nvm_version_path "$VERSION")" VERSION_PATH="$(nvm_version_path "$VERSION")"
local NVM_OS local NVM_OS
@ -952,7 +969,7 @@ nvm_install_node_binary() {
tmptarball="$tmpdir/node-${t}.tar.gz" tmptarball="$tmpdir/node-${t}.tar.gz"
if ( if (
command mkdir -p "$tmpdir" && \ command mkdir -p "$tmpdir" && \
nvm_download -L -C - --progress-bar $url -o "$tmptarball" && \ nvm_download -L -C - "$PROGRESS_BAR" $url -o "$tmptarball" && \
nvm_checksum "$tmptarball" $sum && \ nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \ command tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command rm -f "$tmptarball" && \ command rm -f "$tmptarball" && \
@ -977,11 +994,29 @@ nvm_install_node_source() {
REINSTALL_PACKAGES_FROM="$2" REINSTALL_PACKAGES_FROM="$2"
local ADDITIONAL_PARAMETERS local ADDITIONAL_PARAMETERS
ADDITIONAL_PARAMETERS="$3" ADDITIONAL_PARAMETERS="$3"
local QUIET
QUIET="$4"
local PROGRESS_BAR
PROGRESS_BAR="--progress-bar "
local REDIRECT_OUTPUT
REDIRECT_OUTPUT=""
local LOGS_DIR
LOGS_DIR="$NVM_DIR/logs"
local LOG_FILE
LOG_FILE="$LOGS_DIR/$VERSION.log"
if [ -n "$ADDITIONAL_PARAMETERS" ]; then if [ -n "$ADDITIONAL_PARAMETERS" ]; then
echo "Additional options while compiling: $ADDITIONAL_PARAMETERS" echo "Additional options while compiling: $ADDITIONAL_PARAMETERS"
fi fi
if [ "$QUIET" == '1' ]; then
PROGRESS_BAR="--silent "
mkdir -p "$LOGS_DIR"
rm -rf "$LOG_FILE"
REDIRECT_OUTPUT=">> $LOG_FILE 2>&1"
fi
local VERSION_PATH local VERSION_PATH
VERSION_PATH="$(nvm_version_path "$VERSION")" VERSION_PATH="$(nvm_version_path "$VERSION")"
local NVM_OS local NVM_OS
@ -1012,14 +1047,14 @@ nvm_install_node_source() {
if ( if (
[ -n "$tarball" ] && \ [ -n "$tarball" ] && \
command mkdir -p "$tmpdir" && \ command mkdir -p "$tmpdir" && \
nvm_download -L --progress-bar $tarball -o "$tmptarball" && \ nvm_download -L "$PROGRESS_BAR" $tarball -o "$tmptarball" && \
nvm_checksum "$tmptarball" $sum && \ nvm_checksum "$tmptarball" $sum && \
command tar -xzf "$tmptarball" -C "$tmpdir" && \ command tar -xzf "$tmptarball" -C "$tmpdir" && \
cd "$tmpdir/node-$VERSION" && \ cd "$tmpdir/node-$VERSION" && \
./configure --prefix="$VERSION_PATH" $ADDITIONAL_PARAMETERS && \ eval ./configure --prefix="$VERSION_PATH" $ADDITIONAL_PARAMETERS ${REDIRECT_OUTPUT} && \
$make $MAKE_CXX && \ eval $make $MAKE_CXX ${REDIRECT_OUTPUT} && \
command rm -f "$VERSION_PATH" 2>/dev/null && \ command rm -f "$VERSION_PATH" 2>/dev/null && \
$make $MAKE_CXX install eval $make $MAKE_CXX install ${REDIRECT_OUTPUT}
) )
then then
if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then
@ -1069,7 +1104,7 @@ nvm() {
echo "Usage:" echo "Usage:"
echo " nvm help Show this message" echo " nvm help Show this message"
echo " nvm --version Print out the latest released version of nvm" echo " nvm --version Print out the latest released version of nvm"
echo " nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available" echo " nvm install [-s] [-q] <version> Download and install a <version>, [-s] from source, [-q] for quiet. Uses .nvmrc if available"
echo " nvm uninstall <version> Uninstall a version" echo " nvm uninstall <version> Uninstall a version"
echo " nvm use <version> Modify PATH to use <version>. Uses .nvmrc if available" echo " nvm use <version> Modify PATH to use <version>. Uses .nvmrc if available"
echo " nvm run <version> [<args>] Run <version> with <args> as arguments. Uses .nvmrc if available for <version>" echo " nvm run <version> [<args>] Run <version> with <args> as arguments. Uses .nvmrc if available for <version>"
@ -1099,6 +1134,7 @@ nvm() {
"install" | "i" ) "install" | "i" )
local nobinary local nobinary
local quiet
local version_not_provided local version_not_provided
version_not_provided=0 version_not_provided=0
local provided_version local provided_version
@ -1122,12 +1158,16 @@ nvm() {
shift shift
nobinary=0 nobinary=0
if [ "_$1" = "_-s" ]; then quiet=0
nobinary=1
shift
fi
provided_version="$1" while [[ "$#" -gt 0 ]]; do
case $1 in
-s) nobinary=1;;
-q) quiet=1;;
*) provided_version="$1"
esac
shift
done
if [ -z "$provided_version" ]; then if [ -z "$provided_version" ]; then
if [ $version_not_provided -ne 1 ]; then if [ $version_not_provided -ne 1 ]; then
@ -1196,9 +1236,9 @@ nvm() {
# skip binary install if "nobinary" option specified. # skip binary install if "nobinary" option specified.
if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then
local NVM_INSTALL_SUCCESS local NVM_INSTALL_SUCCESS
if [ "$NVM_IOJS" = true ] && nvm_install_iojs_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then if [ "$NVM_IOJS" = true ] && nvm_install_iojs_binary "$VERSION" "$REINSTALL_PACKAGES_FROM" "$quiet"; then
NVM_INSTALL_SUCCESS=true NVM_INSTALL_SUCCESS=true
elif [ "$NVM_IOJS" != true ] && nvm_install_node_binary "$VERSION" "$REINSTALL_PACKAGES_FROM"; then elif [ "$NVM_IOJS" != true ] && nvm_install_node_binary "$VERSION" "$REINSTALL_PACKAGES_FROM" "$quiet"; then
NVM_INSTALL_SUCCESS=true NVM_INSTALL_SUCCESS=true
fi fi
@ -1216,7 +1256,7 @@ nvm() {
echo "Installing iojs from source is not currently supported" >&2 echo "Installing iojs from source is not currently supported" >&2
return 105 return 105
else else
nvm_install_node_source "$VERSION" "$REINSTALL_PACKAGES_FROM" "$ADDITIONAL_PARAMETERS" nvm_install_node_source "$VERSION" "$REINSTALL_PACKAGES_FROM" "$ADDITIONAL_PARAMETERS" "$quiet"
fi fi
;; ;;
"uninstall" ) "uninstall" )