This commit is contained in:
Philipp Haidenbauer 2016-03-12 06:36:22 +00:00
commit b2ffe0e4cc
3 changed files with 53 additions and 7 deletions

View File

@ -6,6 +6,10 @@ nvm_has() {
type "$1" > /dev/null 2>&1
}
nvm_has_http_proxy() {
[ "$NVM_HTTP_PROXY" != '' ]
}
if [ -z "$NVM_DIR" ]; then
NVM_DIR="$HOME/.nvm"
fi
@ -42,7 +46,11 @@ nvm_source() {
nvm_download() {
if nvm_has "curl"; then
if nvm_has_http_proxy; then
curl -q -x $NVM_HTTP_PROXY $*
else
curl -q $*
fi
elif nvm_has "wget"; then
# Emulate curl with wget
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
@ -51,7 +59,11 @@ nvm_download() {
-e 's/-s /-q /' \
-e 's/-o /-O /' \
-e 's/-C - /-c /')
wget $ARGS
if nvm_has_http_proxy; then
eval wget -e use_proxy=yes -e http_proxy=$NVM_HTTP_PROXY $ARGS
else
eval wget $ARGS
fi
fi
}
@ -229,7 +241,11 @@ nvm_do_install() {
local NVM_PROFILE
NVM_PROFILE=$(nvm_detect_profile)
if nvm_has_http_proxy; then
SOURCE_STR="\nexport NVM_HTTP_PROXY=$NVM_HTTP_PROXY\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
else
SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm"
fi
if [ -z "$NVM_PROFILE" ] ; then
echo "=> Profile not found. Tried $NVM_PROFILE (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."

20
nvm.sh
View File

@ -22,9 +22,17 @@ nvm_is_alias() {
nvm_get_latest() {
local NVM_LATEST_URL
if nvm_has "curl"; then
if nvm_has_http_proxy; then
NVM_LATEST_URL="$(curl -q -x $NVM_HTTP_PROXY -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"
else
NVM_LATEST_URL="$(curl -q -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"
fi
elif nvm_has "wget"; then
if nvm_has_http_proxy; then
NVM_LATEST_URL="$(wget http://latest.nvm.sh -e use_proxy=yes -e http_proxy=$NVM_HTTP_PROXY --server-response -O /dev/null 2>&1 | command awk '/^ Location: /{DEST=$2} END{ print DEST }')"
else
NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | command awk '/^ Location: /{DEST=$2} END{ print DEST }')"
fi
else
>&2 echo 'nvm needs curl or wget to proceed.'
return 1
@ -39,7 +47,11 @@ nvm_get_latest() {
nvm_download() {
if nvm_has "curl"; then
if nvm_has_http_proxy; then
curl -q -x $NVM_HTTP_PROXY $*
else
curl -q $*
fi
elif nvm_has "wget"; then
# Emulate curl with wget
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
@ -48,8 +60,12 @@ nvm_download() {
-e 's/-s /-q /' \
-e 's/-o /-O /' \
-e 's/-C - /-c /')
if nvm_has_http_proxy; then
eval wget -e use_proxy=yes -e http_proxy=$NVM_HTTP_PROXY $ARGS
else
eval wget $ARGS
fi
fi
}
nvm_has_system_node() {
@ -60,6 +76,10 @@ nvm_has_system_iojs() {
[ "$(nvm deactivate >/dev/null 2>&1 && command -v iojs)" != '' ]
}
nvm_has_http_proxy() {
[ "$NVM_HTTP_PROXY" != '' ]
}
nvm_print_npm_version() {
if nvm_has "npm"; then
echo " (npm v$(npm --version 2>/dev/null))"

View File

@ -0,0 +1,10 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
! nvm_has_http_proxy || die 'nvm_has_http_proxy: no http_proxy defined'
NVM_HTTP_PROXY=127.0.0.1:1234
nvm_has_http_proxy || die 'nvm_has_http_proxy: http_proxy defined'