Commit 323089c4f1eb40508795e3efb363569313c42518
1 parent
ac1747b4
Exists in
master
and in
15 other branches
quick-start: retry apt update/upgrade up to 3 times
This will avoid, or at least reduce the chances of, having the CI builds falling over on temporary network failures.
Showing
1 changed file
with
16 additions
and
2 deletions
Show diff stats
script/install-dependencies/debian-jessie.sh
@@ -61,12 +61,26 @@ else | @@ -61,12 +61,26 @@ else | ||
61 | sudo rm -f /etc/apt/sources.list.d/local.list | 61 | sudo rm -f /etc/apt/sources.list.d/local.list |
62 | fi | 62 | fi |
63 | 63 | ||
64 | +retry() { | ||
65 | + local times="$1" | ||
66 | + shift | ||
67 | + local i=0 | ||
68 | + local rc=0 | ||
69 | + while [ $i -lt "$times" ]; do | ||
70 | + echo '$' "$@" | ||
71 | + "$@" && rc=0 || rc=$? | ||
72 | + i=$(($i + 1)) | ||
73 | + if [ $rc -eq 0 ]; then return 0; fi | ||
74 | + done | ||
75 | + return $rc | ||
76 | +} | ||
77 | + | ||
64 | # update system, at most every 6h (internal between Debian mirror pushes) | 78 | # update system, at most every 6h (internal between Debian mirror pushes) |
65 | timestamp=/tmp/.noosfero.apt-get.update | 79 | timestamp=/tmp/.noosfero.apt-get.update |
66 | now=$(date +%s) | 80 | now=$(date +%s) |
67 | if [ ! -f $timestamp ] || [ $(($now - $(stat --format=%Y $timestamp))) -gt 21600 ]; then | 81 | if [ ! -f $timestamp ] || [ $(($now - $(stat --format=%Y $timestamp))) -gt 21600 ]; then |
68 | - run sudo apt-get update | ||
69 | - run sudo apt-get -qy dist-upgrade | 82 | + run retry 3 sudo apt-get update |
83 | + run retry 3 sudo apt-get -qy dist-upgrade | ||
70 | touch $timestamp | 84 | touch $timestamp |
71 | fi | 85 | fi |
72 | 86 |