Files
onepilot/scripts/retry.sh
T
github-actions[bot] 6f34f74e9b sunnypilot v2026.001.000 release
date: 2026-04-10T22:07:44
master commit: 4ba0c4b574bff994e9a8f7266b4969b39380a8b1
2026-04-10 22:07:52 +08:00

28 lines
511 B
Bash
Executable File

#!/usr/bin/env bash
function fail {
echo $1 >&2
exit 1
}
function retry {
local n=1
local max=3 # 3 retries before failure
local delay=5 # delay between retries, 5 seconds
while true; do
echo "Running command '$@' with retry, attempt $n/$max"
"$@" && break || {
if [[ $n -lt $max ]]; then
((n++))
sleep $delay;
else
fail "The command has failed after $n attempts."
fi
}
done
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
retry "$@"
fi