From 330e62af9dc6e6d5f54c65b31ed4ff1871b5499b Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 29 May 2020 12:27:33 +0000 Subject: [PATCH] Add download retry helper on Ubuntu (#955) * Add download retry helper --- images/linux/scripts/helpers/install.sh | 30 +++++++++++++++++++++++++ images/linux/scripts/installers/pypy.sh | 28 +++++------------------ 2 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 images/linux/scripts/helpers/install.sh diff --git a/images/linux/scripts/helpers/install.sh b/images/linux/scripts/helpers/install.sh new file mode 100644 index 00000000..15c2e1a0 --- /dev/null +++ b/images/linux/scripts/helpers/install.sh @@ -0,0 +1,30 @@ +#!/bin/bash +################################################################################ +## File: install.sh +## Desc: Helper functions for installing tools +################################################################################ + +download_with_retries() { +# Due to restrictions of bash functions, positional arguments are used here. +# In case if you using latest argument NAME, you should also set value to all previous parameters. +# Example: download_with_retries $ANDROID_SDK_URL "." "android_sdk.zip" + local URL="$1" + local DEST="${2:-.}" + local NAME="${3:-${URL##*/}}" + + echo "Downloading $URL..." + i=20 + while [ $i -gt 0 ]; do + ((i--)) + wget $URL --output-document="$DEST/$NAME" \ + --no-verbose + if [ $? != 0 ]; then + sleep 30 + else + return 0 + fi + done + + echo "Could not download $URL" + return 1 +} \ No newline at end of file diff --git a/images/linux/scripts/installers/pypy.sh b/images/linux/scripts/installers/pypy.sh index 117a927b..cfb097bd 100644 --- a/images/linux/scripts/installers/pypy.sh +++ b/images/linux/scripts/installers/pypy.sh @@ -6,6 +6,7 @@ # Source the helpers for use with the script source $HELPER_SCRIPTS/document.sh +source $HELPER_SCRIPTS/install.sh # This function installs PyPy using the specified arguments: # $1=PACKAGE_URL @@ -16,7 +17,7 @@ function InstallPyPy PACKAGE_TAR_NAME=$(echo $PACKAGE_URL | awk -F/ '{print $NF}') echo "Downloading tar archive '$PACKAGE_TAR_NAME' - '$PACKAGE_URL'" PACKAGE_TAR_TEMP_PATH="/tmp/$PACKAGE_TAR_NAME" - wget -q -O $PACKAGE_TAR_TEMP_PATH $PACKAGE_URL + download_with_retries $PACKAGE_URL "/tmp" $PACKAGE_TAR_NAME echo "Expand '$PACKAGE_TAR_NAME' to the /tmp folder" tar xf $PACKAGE_TAR_TEMP_PATH -C /tmp @@ -69,28 +70,11 @@ function InstallPyPy rm -f $PACKAGE_TAR_TEMP_PATH } -function getPyPyVersions -{ - uri="https://downloads.python.org/pypy/" - i=20 - - while [ $i -gt 0 ]; do - ((i--)) - result="$(curl -4 -s --compressed $uri | grep 'linux64' | awk -v uri="$uri" -F'>|<' '{print uri$5}')" - if [ -z "$result" ]; then - sleep 30 - else - echo "$result" - return - fi - done - - echo "There are no more attempts to retrive PyPy version" - exit 1 -} - # Installation PyPy -pypyVersions=$(getPyPyVersions) +uri="https://downloads.python.org/pypy/" +download_with_retries $uri "/tmp" "pypyUrls.html" +pypyVersions="$(cat /tmp/pypyUrls.html | grep 'linux64' | awk -v uri="$uri" -F'>|<' '{print uri$5}')" + toolsetJson="$INSTALLER_SCRIPT_FOLDER/toolset.json" toolsetVersions=$(cat $toolsetJson | jq -r '.toolcache[] | select(.name | contains("PyPy")) | .versions[]')