Skip to content

Commit

Permalink
Emulate curl with wget
Browse files Browse the repository at this point in the history
  • Loading branch information
koenpunt committed Mar 26, 2014
1 parent 2d0c025 commit 5342b6a
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ if [ -z "$NVM_DIR" ]; then
NVM_DIR="$HOME/.nvm"
fi

download_file() {
# download_file source destination
if has "curl"; then
curl -s "$1" -o "$2"
elif has "wget"; then
wget -q "$1" -O "$2"
else
return 1
if ! has "curl"; then
if has "wget"; then
# Emulate curl with wget
curl() {
ARGS="$* "
ARGS=${ARGS/-s /-q }
ARGS=${ARGS/-o /-O }
wget $ARGS
}
fi
}
fi

install_from_git() {
if [ -z "$NVM_SOURCE" ]; then
Expand Down Expand Up @@ -54,7 +55,7 @@ install_as_script() {
else
echo "=> Downloading nvm as script to '$NVM_DIR'"
fi
download_file "$NVM_SOURCE" "$NVM_DIR/nvm.sh" || {
curl -s "$NVM_SOURCE" -o "$NVM_DIR/nvm.sh" || {
echo >&2 "Failed to download '$NVM_SOURCE'.."
return 1
}
Expand All @@ -64,24 +65,26 @@ if [ -z "$METHOD" ]; then
# Autodetect install method
if has "git"; then
install_from_git
elif has "curl" || has "wget"; then
elif has "curl"; then
install_as_script
else
echo >&2 "You need git, curl or wget to install nvm"
exit 1
fi
else
if [ "$METHOD" = "git" ]; then
install_from_git || {
if ! has "git"; then
echo >&2 "You need git to install nvm"
exit 1
}
fi
install_from_git
fi
if [ "$METHOD" = "script" ]; then
install_as_script || {
if ! has "curl"; then
echo >&2 "You need curl or wget to install nvm"
exit 1
}
fi
install_as_script
fi
fi

Expand Down

0 comments on commit 5342b6a

Please sign in to comment.