-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexport-all-from-saas.sh
More file actions
executable file
·100 lines (88 loc) · 2.69 KB
/
export-all-from-saas.sh
File metadata and controls
executable file
·100 lines (88 loc) · 2.69 KB
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
92
93
94
95
96
97
98
99
100
#!/bin/bash
set -euo pipefail
# Simple runner to execute scripts 002 through 030 in order.
# Usage:
# ./export-all-from-saas.sh # stop on first error
# ./export-all-from-saas.sh --continue-on-error
#
# Notes:
# - Assumes prerequisites are met (e.g., 001-base-saas_stack-connect.sh already run).
# - Stops on first failure by default. Use --continue-on-error to keep going.
CONTINUE_ON_ERROR=false
if [[ "${1:-}" == "--continue-on-error" ]]; then
CONTINUE_ON_ERROR=true
fi
shopt -s nullglob
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd "$SCRIPT_DIR"
# Initialize arrays explicitly to avoid unbound with set -u on some shells
SUCCESS_LIST=()
FAIL_LIST=()
MISSING_LIST=()
print_summary() {
echo "Summary:"
echo " Success: ${#SUCCESS_LIST[@]}"
if ((${#SUCCESS_LIST[@]})); then
for s in "${SUCCESS_LIST[@]}"; do echo " - $s"; done
fi
echo " Failed: ${#FAIL_LIST[@]}"
if ((${#FAIL_LIST[@]})); then
for f in "${FAIL_LIST[@]}"; do echo " - $f"; done
fi
echo " Skipped (not found): ${#MISSING_LIST[@]}"
if ((${#MISSING_LIST[@]})); then
for m in "${MISSING_LIST[@]}"; do echo " - $m"; done
fi
}
start_ts=$(date +%s)
echo "Running scripts 002..030"
for i in $(seq -w 002 030); do
pattern="${i}-*.sh"
scripts=(./$pattern)
# Ensure deterministic order when multiple scripts match the same prefix
IFS=$'\n' scripts=($(printf '%s\n' "${scripts[@]}" | sort))
if [[ ${#scripts[@]} -eq 0 ]]; then
echo "[$i] No script found matching $pattern, skipping"
MISSING_LIST+=("$pattern")
continue
fi
for script in "${scripts[@]}"; do
echo "[$i] >>> $script"
ts=$(date +%s)
if $CONTINUE_ON_ERROR; then
set +e
bash "$script"
exit_code=$?
set -e
if [[ $exit_code -ne 0 ]]; then
echo "[$i] !!! $script exited with code $exit_code (continuing)"
FAIL_LIST+=("$script (code $exit_code)")
else
echo "[$i] <<< Completed in $(( $(date +%s) - ts ))s"
SUCCESS_LIST+=("$script")
fi
else
set +e
bash "$script"
exit_code=$?
set -e
if [[ $exit_code -ne 0 ]]; then
echo "[$i] !!! $script exited with code $exit_code"
FAIL_LIST+=("$script (code $exit_code)")
echo
print_summary
echo "All done (stopped on error) in $(( $(date +%s) - start_ts ))s"
exit $exit_code
fi
echo "[$i] <<< Completed in $(( $(date +%s) - ts ))s"
SUCCESS_LIST+=("$script")
fi
done
done
echo
print_summary
echo "All done in $(( $(date +%s) - start_ts ))s"
# In continue-on-error mode, return non-zero if any failures occurred
if $CONTINUE_ON_ERROR && [[ ${#FAIL_LIST[@]} -gt 0 ]]; then
exit 1
fi