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 | 61 | sudo rm -f /etc/apt/sources.list.d/local.list |
62 | 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 | 78 | # update system, at most every 6h (internal between Debian mirror pushes) |
65 | 79 | timestamp=/tmp/.noosfero.apt-get.update |
66 | 80 | now=$(date +%s) |
67 | 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 | 84 | touch $timestamp |
71 | 85 | fi |
72 | 86 | ... | ... |