blob: 9105c9cc6af6607ee022e58bba173edcff5097b1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#!/bin/bash
# vim: set sts=4 sw=4 et :
set -o pipefail
ERRORS=(
"Warning: An error occurred while preparing SDK package Android SDK Tools: Connection reset."
"The Xcode build system has crashed. Build again to continue."
)
RETRIES=3
LOGFILE="/tmp/logfile.txt"
while true; do
spurious_error=
"$@" | tee "$LOGFILE" 2>&1
ret=$?
[[ $ret == 0 ]] && break
while read line; do
for error in "${ERRORS[@]}"; do
if [[ $line =~ $error ]]; then
spurious_error=$line
break 2
fi
done
done < "$LOGFILE"
rm -f "$LOGFILE"
if [[ $spurious_error == '' ]] || [[ $RETRIES == 0 ]]; then
exit $ret
fi
RETRIES=$((RETRIES-1))
echo "Retrying, caught spurious failure: $spurious_error"
done
|