seba: Bump retries count for att-workflow
[iec.git] / src / use_cases / seba_on_arm / install / util.sh
1 #!/bin/bash -ex
2 # shellcheck disable=SC2016
3
4 function wait_for {
5   # Execute in a subshell to prevent local variable override during recursion
6   (
7     local total_attempts=$1; shift
8     local cmdstr=$*
9     local sleep_time=2
10     echo -e "\n[wait_for] Waiting for cmd to return success: ${cmdstr}"
11     # shellcheck disable=SC2034
12     for attempt in $(seq "${total_attempts}"); do
13       echo "[wait_for] Attempt ${attempt}/${total_attempts%.*} for: ${cmdstr}"
14       # shellcheck disable=SC2015
15       eval "${cmdstr}" && echo "[wait_for] OK: ${cmdstr}" && return 0 || true
16       sleep "${sleep_time}"
17     done
18     echo "[wait_for] ERROR: Failed after max attempts: ${cmdstr}"
19     return 1
20   )
21 }
22