From 8a47814c91828a2f1541b99b58c8ee2eb085cb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Thu, 22 Feb 2018 15:00:47 +0100 Subject: Simplify DownloadURL The script was over-engineered. The new version provides the same functionality while removing uninteresting postmortem messages. In addition try_catch.sh has a bug that injects set +e to a sourcing script which was propagating through DownloadURL.sh to almost all provisioning scripts. So it is good to avoid using it. Change-Id: If191a0dcf52a29c4bec580a254e8e58a00130f6d Reviewed-by: Oliver Wolff Reviewed-by: Frederik Gladhorn --- coin/provisioning/common/unix/DownloadURL.sh | 46 +++++----------------------- 1 file changed, 8 insertions(+), 38 deletions(-) (limited to 'coin/provisioning/common') diff --git a/coin/provisioning/common/unix/DownloadURL.sh b/coin/provisioning/common/unix/DownloadURL.sh index d3a8a7d0..c1e1d6cc 100755 --- a/coin/provisioning/common/unix/DownloadURL.sh +++ b/coin/provisioning/common/unix/DownloadURL.sh @@ -40,51 +40,21 @@ # If called directly from another script, it will exit the parent script # as well, if not called in its own subshell with parentheses. -# shellcheck source=try_catch.sh -source "${BASH_SOURCE%/*}/try_catch.sh" - -ExceptionDownloadPrimaryUrl=100 -ExceptionDownloadAltUrl=101 -ExceptionSHA1=102 - function DownloadURL { url=$1 url_alt=$2 expectedSha1=$3 targetFile=$4 - try - ( - try - ( - echo "Downloading from primary URL '$url'" - curl --fail -L --retry 5 --retry-delay 5 -o "$targetFile" "$url" || throw $ExceptionDownloadPrimaryUrl - ) - catch || { - case $ex_code in - $ExceptionDownloadPrimaryUrl) - echo "Failed to download '$url' multiple times" - echo "Downloading tar.gz from alternative URL '$url_alt'" - curl --fail -L --retry 5 --retry-delay 5 -o "$targetFile" "$url_alt" || throw $ExceptionDownloadAltUrl - ;; - esac - } - echo "Checking SHA1 on PKG '$targetFile'" - echo "$expectedSha1 *$targetFile" > $targetFile.sha1 - sha1sum --check $targetFile.sha1 || throw $ExceptionSHA1 + echo "Downloading from primary URL '$url'" + curl --fail -L --retry 5 --retry-delay 5 -o "$targetFile" "$url" || ( + echo "Failed to download '$url' multiple times" + echo "Downloading from alternative URL '$url_alt'" + curl --fail -L --retry 5 --retry-delay 5 -o "$targetFile" "$url_alt" ) - catch || { - case $ex_code in - $ExceptionDownloadAltUrl) - echo "Failed downloading PKG from primary and alternative URLs" - exit 1; - ;; - $ExceptionSHA1) - echo "Failed checksum on $targetFile." - exit 1; - ;; - esac - } + echo "Checking SHA1 on PKG '$targetFile'" + echo "$expectedSha1 *$targetFile" > $targetFile.sha1 + sha1sum --check $targetFile.sha1 } -- cgit v1.2.3