mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-31 13:13:44 +08:00
eefc084302
version: sunnypilot v2025.003.000 (dev) date: 2025-12-18T05:48:43 master commit: 16c052af0835f049a67b80251d8cc1114fc08bb4
28 lines
511 B
Bash
Executable File
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
|