Skip to content

Commit 76beb88

Browse files
committed
Auto merge of #1373 - thibaultdelor:wgetsupport, r=alexcrichton
Fallbacks to wget if curl not installed Tested in ubuntu docker with 1. Both curl and wget installed 2. only wget installed 3. only curl installed Console output for wget looks like this : ```shell root@845dcc4ba103:/# wget -qO- https://raw.githubusercontent.com/thibaultdelor/rustup.rs/faa08bd786b7282500cc4162a2f428484c891130/rustup-init.sh | sh info: downloading installer --2018-03-08 06:54:27-- https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init Resolving static.rust-lang.org (static.rust-lang.org)... 54.230.135.47, 54.230.135.132, 54.230.135.130, ... Connecting to static.rust-lang.org (static.rust-lang.org)|54.230.135.47|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 12984456 (12M) [application/x-sharedlib] Saving to: '/tmp/tmp.DQhaNqhC4q/rustup-init' /tmp/tmp.DQhaNqhC4q/rustu 100%[==================================>] 12.38M 11.0MB/s in 1.1s 2018-03-08 06:54:29 (11.0 MB/s) - '/tmp/tmp.DQhaNqhC4q/rustup-init' saved [12984456/12984456] Welcome to Rust! This will download and install the official compiler for the Rust programming language, and its package manager, Cargo. It will add the cargo, rustc, rustup and other commands to Cargo's bin directory, located at: /root/.cargo/bin This path will then be added to your PATH environment variable by modifying the profile file located at: /root/.profile You can uninstall at any time with rustup self uninstall and these changes will be reverted. Current installation options: default host triple: x86_64-unknown-linux-gnu default toolchain: stable modify PATH variable: yes 1) Proceed with installation (default) 2) Customize installation 3) Cancel installation ```
2 parents cc87d74 + faa08bd commit 76beb88

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

rustup-init.sh

Lines changed: 30 additions & 5 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
@@ -331,11 +331,16 @@ err() {
331331
}
332332

333333
need_cmd() {
334-
if ! command -v "$1" > /dev/null 2>&1
334+
if ! check_cmd "$1"
335335
then err "need '$1' (command not found)"
336336
fi
337337
}
338338

339+
check_cmd() {
340+
command -v "$1" > /dev/null 2>&1
341+
return $?
342+
}
343+
339344
need_ok() {
340345
if [ $? != 0 ]; then err "$1"; fi
341346
}
@@ -359,4 +364,24 @@ ignore() {
359364
"$@"
360365
}
361366

367+
# This wraps curl or wget. Try curl first, if not installed,
368+
# use wget instead.
369+
downloader() {
370+
if check_cmd curl
371+
then _dld=curl
372+
elif check_cmd wget
373+
then _dld=wget
374+
else _dld='curl or wget' # to be used in error message of need_cmd
375+
fi
376+
377+
if [ "$1" = --check ]
378+
then need_cmd "$_dld"
379+
elif [ "$_dld" = curl ]
380+
then curl -sSfL "$1" -o "$2"
381+
elif [ "$_dld" = wget ]
382+
then wget "$1" -O "$2"
383+
else err "Unknown downloader" # should not reach here
384+
fi
385+
}
386+
362387
main "$@" || exit 1

0 commit comments

Comments
 (0)