From f21499f4498634110d649ed10acdd7f6fb5ef3e2 Mon Sep 17 00:00:00 2001 From: mateon1 Date: Wed, 15 Feb 2017 21:54:54 +0100 Subject: [PATCH 1/3] Make dist_get fallback to other downloaders if one fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Mateusz Naściszewski --- bin/dist_get | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/bin/dist_get b/bin/dist_get index df3164f44..4b06e7a49 100755 --- a/bin/dist_get +++ b/bin/dist_get @@ -25,17 +25,26 @@ download() { if have_binary wget; then printf '==> Using wget to download "%s" to "%s"\n' "$dl_url" "$dl_output" - wget "$dl_url" -O "$dl_output" || return - elif have_binary curl; then - printf '==> Using curl to download "%s" to "%s"\n' "$dl_url" "$dl_output" - curl --silent "$dl_url" > "$dl_output" || return - elif have_binary fetch; then - printf '==> Using fetch to download "%s" to "%s"\n' "$dl_url" "$dl_output" - fetch "$dl_url" -o "$dl_output" || return - else - die "no binary found to download $dl_url. exiting." + if wget "$dl_url" -O "$dl_output"; then + echo "==> download complete!" + return + fi fi - echo "==> download complete!" + if have_binary curl; then + printf '==> Using curl to download "%s" to "%s"\n' "$dl_url" "$dl_output" + if curl --silent "$dl_url" > "$dl_output"; then + echo "==> download complete!" + return + fi + fi + if have_binary fetch; then + printf '==> Using fetch to download "%s" to "%s"\n' "$dl_url" "$dl_output" + if fetch "$dl_url" -o "$dl_output"; then + echo "==> download complete!" + return + fi + fi + die "Unable to download $dl_url. exiting." } unarchive() { From 6b078158993466384187e7ea0b8a0090d378199d Mon Sep 17 00:00:00 2001 From: mateon1 Date: Wed, 15 Feb 2017 22:52:20 +0100 Subject: [PATCH 2/3] Refactor download, add httpie support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Mateusz Naściszewski --- bin/dist_get | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/bin/dist_get b/bin/dist_get index 4b06e7a49..95e982d0b 100755 --- a/bin/dist_get +++ b/bin/dist_get @@ -13,6 +13,26 @@ check_writeable() { printf "" > "$1" && rm "$1" } +try_download() { + url="$1" + output="$2" + command="$3" + util_name=$(set -- $3; echo $1) + + if ! have_binary $util_name; then + return 1 + fi + + printf '==> Using %s to download "%s" to "%s"\n' "$util_name" "$url" "$output" + if eval "$command"; then + echo "==> Download complete!" + return + else + echo "error: couldn't download with $util_name ($?)" + return 1 + fi +} + download() { dl_url="$1" dl_output="$2" @@ -23,27 +43,11 @@ download() { die "download error: cannot write to $dl_output" fi - if have_binary wget; then - printf '==> Using wget to download "%s" to "%s"\n' "$dl_url" "$dl_output" - if wget "$dl_url" -O "$dl_output"; then - echo "==> download complete!" - return - fi - fi - if have_binary curl; then - printf '==> Using curl to download "%s" to "%s"\n' "$dl_url" "$dl_output" - if curl --silent "$dl_url" > "$dl_output"; then - echo "==> download complete!" - return - fi - fi - if have_binary fetch; then - printf '==> Using fetch to download "%s" to "%s"\n' "$dl_url" "$dl_output" - if fetch "$dl_url" -o "$dl_output"; then - echo "==> download complete!" - return - fi - fi + try_download "$dl_url" "$dl_output" "wget '$dl_url' -O '$dl_output'" && return + try_download "$dl_url" "$dl_output" "curl --silent '$dl_url' > '$dl_output'" && return + try_download "$dl_url" "$dl_output" "fetch '$dl_url' -o '$dl_output'" && return + try_download "$dl_url" "$dl_output" "http '$dl_url' > '$dl_output'" && return + die "Unable to download $dl_url. exiting." } From 4ae80d69339ec021336501e57e15d9d38a9d133f Mon Sep 17 00:00:00 2001 From: mateon1 Date: Thu, 16 Feb 2017 14:03:40 +0100 Subject: [PATCH 3/3] Use quotes to fix some shellcheck warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Mateusz Naściszewski --- bin/dist_get | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/dist_get b/bin/dist_get index 95e982d0b..a21208bf9 100755 --- a/bin/dist_get +++ b/bin/dist_get @@ -17,9 +17,9 @@ try_download() { url="$1" output="$2" command="$3" - util_name=$(set -- $3; echo $1) + util_name="$(set -- $command; echo "$1")" - if ! have_binary $util_name; then + if ! have_binary "$util_name"; then return 1 fi