-
Notifications
You must be signed in to change notification settings - Fork 0
/
CloneStuff.sh
56 lines (49 loc) · 1.19 KB
/
CloneStuff.sh
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env bash
# Set default value for __retries
__retries=5
__command=""
while :
do
if [ $# -le 0 ]; then
break
fi
lowerI="$(echo $1 | awk '{print tolower($0)}')"
case $lowerI in
command|-command)
if [ -n "$2" ]; then
__command="$2"
shift
else
echo "ERROR: 'command' requires a non-empty option argument"
exit 1
fi
;;
retries|-retries)
if [ -n "$2" ]; then
__retries="$2"
shift
else
echo "ERROR: 'retries' requires a non-empty option argument"
exit 1
fi
;;
*)
esac
shift
done
if [[ -z "$__command" ]]; then
echo "ERROR: Please supply a value for '-command'"
exit 2
fi
exit_code=1
__retryCount=0
until [ $exit_code -eq 0 ] || [ $__retryCount -ge $__retries ]; do
eval $__command
exit_code=$?
__retryCount=$((__retryCount+1))
if [ $exit_code -ne 0 ]; then
echo "$__command exited with $exit_code, retrying"
fi
done
echo "$__command exited with $exit_code"
exit $exit_code