|
9 | 9 | # option. This file may not be copied, modified, or distributed
|
10 | 10 | # except according to those terms.
|
11 | 11 |
|
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 |
14 | 14 | # and runs it.
|
15 | 15 |
|
16 | 16 | set -u
|
|
41 | 41 | }
|
42 | 42 |
|
43 | 43 | main() {
|
| 44 | + downloader --check |
44 | 45 | need_cmd uname
|
45 |
| - need_cmd curl |
46 | 46 | need_cmd mktemp
|
47 | 47 | need_cmd chmod
|
48 | 48 | need_cmd mkdir
|
@@ -100,7 +100,7 @@ main() {
|
100 | 100 | fi
|
101 | 101 |
|
102 | 102 | ensure mkdir -p "$_dir"
|
103 |
| - ensure curl -sSfL "$_url" -o "$_file" |
| 103 | + ensure downloader "$_url" "$_file" |
104 | 104 | ensure chmod u+x "$_file"
|
105 | 105 | if [ ! -x "$_file" ]; then
|
106 | 106 | printf '%s\n' "Cannot execute $_file (likely because of mounting /tmp as noexec)." 1>&2
|
@@ -359,4 +359,24 @@ ignore() {
|
359 | 359 | "$@"
|
360 | 360 | }
|
361 | 361 |
|
| 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 | + |
362 | 382 | main "$@" || exit 1
|
0 commit comments