Files
sunnypilot/scripts/retry.sh
T
Jason Wen 167ef31602 sunnypilot v2024.11.16-3490
version: sunnypilot v0.9.8.0 release
  date: 2024-11-16T19:13:50
  master commit: fa9234afa0
2024-11-16 19:13:50 +00:00

28 lines
503 B
Bash
Executable File

#!/bin/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