-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·91 lines (74 loc) · 1.45 KB
/
run.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
set -e
source constants.sh
# ---------------------------------------
# Argument parsing
# ---------------------------------------
declare -a args
declare -i from=0 to=100
# Parse flags and named arguments
while (("$#" > 0)); do
case $1 in
--from)
from="$2"
shift 2
;;
--to)
to="$2"
shift 2
;;
-* | --*)
echo "Unknown option $1"
exit 1
;;
*)
args+=("$1")
shift
;;
esac
done
# Restore positional arguments
set -- "${args[@]}"
# Parse position arguments
declare arg1="${args[0]}"
if [[ -n "$arg1" ]]; then
from="10#$arg1"
to="$((from + 1))"
fi
# Error on extra arguments
if (( "$#" > 1 )); then
echo "Unknown extra positional arguments ${@:1}"
exit 1
fi
# ---------------------------------------
# Setup
# ---------------------------------------
# Code to signal an early but normal exit
export STOP_CODE=99
# ---------------------------------------
# Main logic
# ---------------------------------------
declare -i index
echo "Run started on $(date)..."
echo
for script in scripts/??-*.sh; do
[[ "$script" =~ ([0-9]{2})-.*\.sh ]]
index="10#${BASH_REMATCH[1]}"
if (( index < from )); then
continue
elif (( index >= to )); then
break
fi
echo "Running $script..."
if time bash "$script"; then
echo
elif [[ "$?" == "$STOP_CODE" ]]; then
echo
echo "Early exit signaled from $script"
break
else
exit "$?"
fi
done
echo
echo "Run completed on $(date)"