rustup.rs: use wget if curl is unavailable

This commit is contained in:
awiouy 2018-05-22 21:44:44 +02:00
parent 1626fdb8df
commit 352d3c1fa6

View File

@ -0,0 +1,115 @@
From 299427ade578adb04a761ebbe7aacc07367fe37a Mon Sep 17 00:00:00 2001
From: TitanSnow <sweeto@live.cn>
Date: Sat, 21 Oct 2017 13:08:33 +0800
Subject: [PATCH 1/2] 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.
---
rustup-init.sh | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/rustup-init.sh b/rustup-init.sh
index 7e089a1fb..a33a31377 100755
--- a/rustup-init.sh
+++ b/rustup-init.sh
@@ -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
@@ -41,8 +41,8 @@ EOF
}
main() {
+ downloader --check
need_cmd uname
- need_cmd curl
need_cmd mktemp
need_cmd chmod
need_cmd mkdir
@@ -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
@@ -359,4 +359,24 @@ ignore() {
"$@"
}
+# This wraps curl or wget. Try curl first, if not installed,
+# use wget instead.
+downloader() {
+ if command -v curl > /dev/null 2>&1
+ then _dld=curl
+ elif command -v wget > /dev/null 2>&1
+ 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
From faa08bd786b7282500cc4162a2f428484c891130 Mon Sep 17 00:00:00 2001
From: Tibo <delor.thibault@gmail.com>
Date: Thu, 8 Mar 2018 16:41:19 +1100
Subject: [PATCH 2/2] Avoid duplication of command -v
---
rustup-init.sh | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/rustup-init.sh b/rustup-init.sh
index a33a31377..e874aa7a3 100755
--- a/rustup-init.sh
+++ b/rustup-init.sh
@@ -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
}
@@ -362,9 +367,9 @@ ignore() {
# This wraps curl or wget. Try curl first, if not installed,
# use wget instead.
downloader() {
- if command -v curl > /dev/null 2>&1
+ if check_cmd curl
then _dld=curl
- elif command -v wget > /dev/null 2>&1
+ elif check_cmd wget
then _dld=wget
else _dld='curl or wget' # to be used in error message of need_cmd
fi