Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallbacks to wget if curl not installed #1373

Merged
merged 2 commits into from
Mar 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions rustup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# option. This file may not be copied, modified, or distributed
# except according to those terms.

# This is just a little script that can be curled from the internet to
# install rustup. It just does platform detection, curls the installer
# This is just a little script that can be downloaded from the internet to
# install rustup. It just does platform detection, downloads the installer
# and runs it.

set -u
Expand Down Expand Up @@ -41,8 +41,8 @@ EOF
}

main() {
downloader --check
need_cmd uname
need_cmd curl
need_cmd mktemp
need_cmd chmod
need_cmd mkdir
Expand Down Expand Up @@ -100,7 +100,7 @@ main() {
fi

ensure mkdir -p "$_dir"
ensure curl -sSfL "$_url" -o "$_file"
ensure downloader "$_url" "$_file"
ensure chmod u+x "$_file"
if [ ! -x "$_file" ]; then
printf '%s\n' "Cannot execute $_file (likely because of mounting /tmp as noexec)." 1>&2
Expand Down Expand Up @@ -331,11 +331,16 @@ err() {
}

need_cmd() {
if ! command -v "$1" > /dev/null 2>&1
if ! check_cmd "$1"
then err "need '$1' (command not found)"
fi
}

check_cmd() {
command -v "$1" > /dev/null 2>&1
return $?
}

need_ok() {
if [ $? != 0 ]; then err "$1"; fi
}
Expand All @@ -359,4 +364,24 @@ ignore() {
"$@"
}

# This wraps curl or wget. Try curl first, if not installed,
# use wget instead.
downloader() {
if check_cmd curl
then _dld=curl
elif check_cmd wget
then _dld=wget
else _dld='curl or wget' # to be used in error message of need_cmd
fi

if [ "$1" = --check ]
then need_cmd "$_dld"
elif [ "$_dld" = curl ]
then curl -sSfL "$1" -o "$2"
elif [ "$_dld" = wget ]
then wget "$1" -O "$2"
else err "Unknown downloader" # should not reach here
fi
}

main "$@" || exit 1