fixup retry function, clear e flag to avoid cleanup trap during retries

This commit is contained in:
SolidHal 2020-09-07 02:33:13 -05:00
parent 6b6c76f25f
commit 5154ae90e8
1 changed files with 5 additions and 2 deletions

View File

@ -115,19 +115,22 @@ trap cleanup INT TERM EXIT
# Retry a command up to 5 times, else fail
retry_until() {
#must clear and unclear the "e" flag to avoid trapping into cleanup before retrying
set +e
command=("$@")
NUM_RETRIES=0
MAX_RETRIES=5
until [ $NUM_RETRIES -eq 5 ] || ${command[@]}; do
echo Apt failure, trying again in 5 seconds
until [ "$NUM_RETRIES" -eq 5 ] || ${command[@]}; do
echo Apt failure, NUM_RETRIES = $NUM_RETRIES, trying again in 5 seconds
((NUM_RETRIES++))
sleep 5
done
if [ "$NUM_RETRIES" -ge "$MAX_RETRIES" ]; then
exit 1
fi
set -e
}
# Download, cache externally, and optionally install the specified packages