Files
sunnypilot/scripts/retry.sh
T
github-actions[bot] ee3aa74e2d sunnypilot v2026.003.000 release
date: 2026-11-17T18:23:15
master commit: c270c7835e
2026-11-17 18:23:15 +00:00

28 lines
515 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