From 323089c4f1eb40508795e3efb363569313c42518 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Thu, 28 Jan 2016 16:14:09 -0200 Subject: [PATCH] quick-start: retry apt update/upgrade up to 3 times --- script/install-dependencies/debian-jessie.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/script/install-dependencies/debian-jessie.sh b/script/install-dependencies/debian-jessie.sh index c021e96..d783f55 100644 --- a/script/install-dependencies/debian-jessie.sh +++ b/script/install-dependencies/debian-jessie.sh @@ -61,12 +61,26 @@ else sudo rm -f /etc/apt/sources.list.d/local.list fi +retry() { + local times="$1" + shift + local i=0 + local rc=0 + while [ $i -lt "$times" ]; do + echo '$' "$@" + "$@" && rc=0 || rc=$? + i=$(($i + 1)) + if [ $rc -eq 0 ]; then return 0; fi + done + return $rc +} + # update system, at most every 6h (internal between Debian mirror pushes) timestamp=/tmp/.noosfero.apt-get.update now=$(date +%s) if [ ! -f $timestamp ] || [ $(($now - $(stat --format=%Y $timestamp))) -gt 21600 ]; then - run sudo apt-get update - run sudo apt-get -qy dist-upgrade + run retry 3 sudo apt-get update + run retry 3 sudo apt-get -qy dist-upgrade touch $timestamp fi -- libgit2 0.21.2