Last active
January 7, 2020 16:43
-
-
Save mandric/4bedb2f82ddef1d0b7950227393b481f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# https://github.com/microsoft/dotnet-framework-docker/blob/master/eng/common/pull-image.sh | |
# Stop script on NZEC | |
set -e | |
# Stop script if unbound variable found (use ${var:-} if intentional) | |
set -u | |
print_err() { | |
printf "%b\n" "Error: $1" >&2 | |
} | |
# Executes a command and retries if it fails. | |
retry() { | |
local count=0 | |
local retries=5 | |
local waitFactor=6 | |
until "$@"; do | |
local exit=$? | |
count=$(( $count + 1 )) | |
if [ $count -lt $retries ]; then | |
local wait=$(( waitFactor ** (( count - 1 )) )) | |
echo "Retry $count/$retries exited $exit, retrying in $wait seconds..." | |
sleep $wait | |
else | |
print_err "Retry $count/$retries exited $exit, no more retries left." | |
return $exit | |
fi | |
done | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment