Skip to content

Commit 299427a

Browse files
ruihe774t-botz
authored andcommitted
fallbacks to wget if curl not installed
modify 'rustup-init.sh' to support wget if curl not installed. This situation often happens on some linux distribution.
1 parent cc87d74 commit 299427a

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

rustup-init.sh

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
# option. This file may not be copied, modified, or distributed
1010
# except according to those terms.
1111

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

1616
set -u
@@ -41,8 +41,8 @@ EOF
4141
}
4242

4343
main() {
44+
downloader --check
4445
need_cmd uname
45-
need_cmd curl
4646
need_cmd mktemp
4747
need_cmd chmod
4848
need_cmd mkdir
@@ -100,7 +100,7 @@ main() {
100100
fi
101101

102102
ensure mkdir -p "$_dir"
103-
ensure curl -sSfL "$_url" -o "$_file"
103+
ensure downloader "$_url" "$_file"
104104
ensure chmod u+x "$_file"
105105
if [ ! -x "$_file" ]; then
106106
printf '%s\n' "Cannot execute $_file (likely because of mounting /tmp as noexec)." 1>&2
@@ -359,4 +359,24 @@ ignore() {
359359
"$@"
360360
}
361361

362+
# This wraps curl or wget. Try curl first, if not installed,
363+
# use wget instead.
364+
downloader() {
365+
if command -v curl > /dev/null 2>&1
366+
then _dld=curl
367+
elif command -v wget > /dev/null 2>&1
368+
then _dld=wget
369+
else _dld='curl or wget' # to be used in error message of need_cmd
370+
fi
371+
372+
if [ "$1" = --check ]
373+
then need_cmd "$_dld"
374+
elif [ "$_dld" = curl ]
375+
then curl -sSfL "$1" -o "$2"
376+
elif [ "$_dld" = wget ]
377+
then wget "$1" -O "$2"
378+
else err "Unknown downloader" # should not reach here
379+
fi
380+
}
381+
362382
main "$@" || exit 1

0 commit comments

Comments
 (0)