-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·90 lines (68 loc) · 2.13 KB
/
setup.sh
File metadata and controls
executable file
·90 lines (68 loc) · 2.13 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WORKBENCH_DIR="$SCRIPT_DIR/workbench"
UTILS_FILE="$SCRIPT_DIR/setup-utils/utils.sh"
manifest_file="${1:-}"
if [ -z "$manifest_file" ]; then
echo "Usage: setup.sh <manifest.json>"
exit 1
fi
if [ ! -f "$manifest_file" ]; then
echo "Error: manifest file not found: $manifest_file"
exit 1
fi
manifest_file="$(cd "$(dirname "$manifest_file")" && pwd)/$(basename "$manifest_file")"
# Cache sudo credentials upfront on Mac so steps can call runElevated without prompting mid-run
if [[ $OSTYPE == darwin* ]]; then
sudo -v
fi
exec > >(tee "$SCRIPT_DIR/workbench.log") 2>&1
# Export env vars from manifest so all steps can access them
while IFS= read -r line; do
key=$(echo "$line" | grep -o '"[^"]*"' | sed -n '1p' | tr -d '"')
value=$(echo "$line" | grep -o '"[^"]*"' | sed -n '2p' | tr -d '"')
if [ -n "$key" ]; then
expanded=$(eval echo "$value")
export "${key}=${expanded}"
fi
done < <(sed -n '/"env"/,/\}/p' "$manifest_file" | grep ':')
export MANIFEST_FILE="$manifest_file"
# shellcheck source=setup-utils/utils.sh
source "$UTILS_FILE"
# Clear all devtools-managed bashrc blocks so steps re-add them in the correct order
if [ -f ~/.bashrc ]; then
tmpfile=$(mktemp)
sed '/# BEGIN devtools:/,/# END devtools:/d' ~/.bashrc > "$tmpfile"
mv "$tmpfile" ~/.bashrc
fi
# Parse steps array from manifest
steps=$(sed -n '/"steps"/,/\]/p' "$manifest_file" | grep -o '"[^"]*"' | tr -d '"' | grep -v '^steps$' | grep -v '^$')
while IFS= read -r step; do
step_dir="$WORKBENCH_DIR/$step"
step_script="$step_dir/index.sh"
if [ ! -d "$step_dir" ]; then
echo "Error: step directory not found: $step_dir"
exit 1
fi
if [ ! -f "$step_script" ]; then
echo "Error: index.sh not found in step directory: $step_dir"
exit 1
fi
echo ""
echo "==> $step"
(
cd "$step_dir"
# shellcheck source=setup-utils/utils.sh
source "$UTILS_FILE"
source ./index.sh
) || {
echo ""
echo "Error: step '$step' failed. Aborting."
exit 1
}
refreshEnv
done <<< "$steps"
refreshEnv
echo ""
echo "Setup complete."