Files
onepilot/scripts/retry.sh
T
github-actions[bot] 3bd5475499 sunnypilot v2026.002.000
version: sunnypilot v2026.002.000 (staging)
date: 2026-06-05T03:53:22
master commit: 46b9253729193e47a8be99154bae41c35359a373
2026-06-05 03:53:22 +00: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