From d1dd644b809bc0c8fc934d67f26807d352bb3e99 Mon Sep 17 00:00:00 2001 From: BtbN Date: Wed, 13 Jul 2022 01:46:13 +0200 Subject: [PATCH] Make retry tool generic --- images/base/git-mini-clone.sh | 12 +----------- images/base/retry-tool.sh | 14 ++++++++++++++ scripts.d/50-libmp3lame.sh | 2 +- scripts.d/50-openmpt.sh | 2 +- scripts.d/50-xvid.sh | 2 +- scripts.d/50-zvbi.sh | 2 +- 6 files changed, 19 insertions(+), 15 deletions(-) create mode 100755 images/base/retry-tool.sh diff --git a/images/base/git-mini-clone.sh b/images/base/git-mini-clone.sh index b924ada..e483802 100755 --- a/images/base/git-mini-clone.sh +++ b/images/base/git-mini-clone.sh @@ -6,17 +6,7 @@ DEST="$3" git init "$DEST" git -C "$DEST" remote add origin "$REPO" -RETRY_COUNTER=0 -MAX_RETRY=15 -while [[ $RETRY_COUNTER -lt $MAX_RETRY ]]; do - timeout 120 git -C "$DEST" fetch --depth=1 origin "$REF" && break || sleep 10 - RETRY_COUNTER=$(( $RETRY_COUNTER + 1 )) - echo "Retry $RETRY_COUNTER..." -done -if [[ $RETRY_COUNTER -ge $MAX_RETRY ]]; then - echo "Max retry count exceeded." - exit 1 -fi +retry-tool git -C "$DEST" fetch --depth=1 origin "$REF" git -C "$DEST" config advice.detachedHead false git -C "$DEST" checkout FETCH_HEAD diff --git a/images/base/retry-tool.sh b/images/base/retry-tool.sh new file mode 100755 index 0000000..548e2e4 --- /dev/null +++ b/images/base/retry-tool.sh @@ -0,0 +1,14 @@ +#!/bin/bash +set -xe + +RETRY_COUNTER=0 +MAX_RETRY=15 +while [[ $RETRY_COUNTER -lt $MAX_RETRY ]]; do + timeout 120 "$@" && break || sleep 10 + RETRY_COUNTER=$(( $RETRY_COUNTER + 1 )) + echo "Retry $RETRY_COUNTER..." +done +if [[ $RETRY_COUNTER -ge $MAX_RETRY ]]; then + echo "Max retry count exceeded." + exit 1 +fi diff --git a/scripts.d/50-libmp3lame.sh b/scripts.d/50-libmp3lame.sh index 2daf818..c9ed783 100755 --- a/scripts.d/50-libmp3lame.sh +++ b/scripts.d/50-libmp3lame.sh @@ -8,7 +8,7 @@ ffbuild_enabled() { } ffbuild_dockerbuild() { - svn checkout "${SCRIPT_REPO}@${SCRIPT_REV}" lame + retry-tool sh -c "rm -rf lame && svn checkout '${SCRIPT_REPO}@${SCRIPT_REV}' lame" cd lame autoreconf -i diff --git a/scripts.d/50-openmpt.sh b/scripts.d/50-openmpt.sh index d06442c..1f0481b 100755 --- a/scripts.d/50-openmpt.sh +++ b/scripts.d/50-openmpt.sh @@ -8,7 +8,7 @@ ffbuild_enabled() { } ffbuild_dockerbuild() { - svn checkout "${SCRIPT_REPO}@${SCRIPT}" openmpt + retry-tool sh -c "rm -rf openmpt && svn checkout '${SCRIPT_REPO}@${SCRIPT}' openmpt" cd openmpt local myconf=( diff --git a/scripts.d/50-xvid.sh b/scripts.d/50-xvid.sh index 73f74a0..25ab076 100755 --- a/scripts.d/50-xvid.sh +++ b/scripts.d/50-xvid.sh @@ -9,7 +9,7 @@ ffbuild_enabled() { } ffbuild_dockerbuild() { - svn checkout --username "anonymous" --password "" "${SCRIPT_REPO}@${SCRIPT_REV}" xvid + retry-tool sh -c "rm -rf xvid && svn checkout --username 'anonymous' --password '' '${SCRIPT_REPO}@${SCRIPT_REV}' xvid" cd xvid cd build/generic diff --git a/scripts.d/50-zvbi.sh b/scripts.d/50-zvbi.sh index 20f3586..d0c8031 100755 --- a/scripts.d/50-zvbi.sh +++ b/scripts.d/50-zvbi.sh @@ -12,7 +12,7 @@ ffbuild_dockerstage() { } ffbuild_dockerbuild() { - svn checkout "${SCRIPT_REPO}@${SCRIPT_REV}" zvbi + retry-tool sh -c "rm -rf zvbi && svn checkout '${SCRIPT_REPO}@${SCRIPT_REV}' zvbi" cd zvbi for patch in /patches/*.patch; do