From a28f0c2826bc37feea328666c469cd63eb98736b Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Wed, 9 Sep 2015 08:48:36 +0200 Subject: make 'apt-get install' more robust against network failures --- bin/schroot-create.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'bin/schroot-create.sh') diff --git a/bin/schroot-create.sh b/bin/schroot-create.sh index 8e902cd0..93648e3e 100755 --- a/bin/schroot-create.sh +++ b/bin/schroot-create.sh @@ -110,6 +110,20 @@ robust_chroot_apt_update() { rm -f $TMPLOG } +robust_chroot_apt_install() { + set +e + sudo chroot $CHROOT_TARGET apt-get install $@ | tee $TMPLOG + RESULT=$(egrep 'Failed to fetch.*(Unable to connect to|Connection failed|Size mismatch|Cannot initiate the connection to|Bad Gateway)' $TMPLOG) + set -e + if [ -z "$RESULT" ] ; then + echo "$(date -u) - apt-get install failed, sleeping 5min before retrying..." + sleep 5m + sudo chroot $CHROOT_TARGET apt-get install $@ + fi + rm -f $TMPLOG +} + + bootstrap() { mkdir -p "$CHROOT_TARGET/etc/dpkg/dpkg.cfg.d" echo force-unsafe-io > "$CHROOT_TARGET/etc/dpkg/dpkg.cfg.d/02dpkg-unsafe-io" @@ -152,12 +166,12 @@ bootstrap() { done set -x robust_chroot_apt_update - # install diffoscope with all recommends... + # first, (if), install diffoscope with all recommends... if [ "$1" = "diffoscope" ] ; then - sudo chroot $CHROOT_TARGET apt-get install -y --install-recommends diffoscope + robust_chroot_apt_install -y --install-recommends diffoscope fi - sudo chroot $CHROOT_TARGET apt-get install -y --no-install-recommends "$@" - # always use diffoscope from unstable + robust_chroot_apt_install -y --no-install-recommends "$@" + # always try to use diffoscope from unstable if [ "$SUITE" = "testing" ] && [ "$1" = "diffoscope" ] ; then echo "deb $MIRROR unstable main" | sudo tee -a $CHROOT_TARGET/etc/apt/sources.list > /dev/null robust_chroot_apt_update -- cgit v1.2.3-54-g00ecf