-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeploy-All.sh
More file actions
executable file
·178 lines (130 loc) · 4.44 KB
/
Deploy-All.sh
File metadata and controls
executable file
·178 lines (130 loc) · 4.44 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env bash
set -euo pipefail
########################################
# Initialization
########################################
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
cd "$SCRIPT_DIR"
PLUGIN_DIR="$SCRIPT_DIR/Deployment/Plugins"
echo "Scanning from: $SCRIPT_DIR"
DEPLOY_ROOTS=(
"$SCRIPT_DIR/Configs"
"$SCRIPT_DIR/Apps-Workarounds"
"$SCRIPT_DIR/Files"
"$SCRIPT_DIR/Tests"
)
########################################
# Recursive Processor
########################################
process_directory() {
local dir="$1"
while IFS= read -r -d '' file; do
process_file "$file"
done < <(
find "$dir" -type f -print0
)
}
########################################
# File Processor
########################################
process_file() {
local file="$1"
# Extract ALL markers anywhere in file
local markers
markers="$(grep -oE '#<--\[.*\]-->#' "$file" || true)"
[[ -z "$markers" ]] && return 0
while IFS= read -r marker; do
# Strip wrapper
local raw
raw="${marker#\#<--[}"
raw="${raw%]-->#}"
IFS='|' read -r -a parts <<< "$raw"
local target_dir="${parts[0]/#\~/$HOME}"
local chmod_value="644"
local type_value="file"
for part in "${parts[@]:1}"; do
case "$part" in
chmod=*) chmod_value="${part#chmod=}" ;;
type=*) type_value="${part#type=}" ;;
esac
done
echo "Deploying: $file"
echo " → target: $target_dir"
echo " → type: $type_value"
echo " → chmod: $chmod_value"
mkdir -p -- "$target_dir"
local BASENAME
BASENAME="$(basename -- "$file")"
local SOURCE="$file"
local TARGET="$target_dir"
local CHMOD="$chmod_value"
local TMPFILE
########################################
# Prepare file copy
########################################
if [[ "$type_value" != "deployable-archive" && \
"$type_value" != "archive" ]]; then
TMPFILE="$(mktemp)"
# Remove ALL marker lines safely
sed '/#<--\[.*\]-->#/d' -- "$SOURCE" > "$TMPFILE"
else
TMPFILE="$SOURCE"
fi
########################################
# Export environment for plugins
########################################
export SOURCE TARGET CHMOD BASENAME TMPFILE SCRIPT_DIR
export -f process_directory
local plugin_file="$PLUGIN_DIR/$type_value.json"
########################################
# Plugin execution
########################################
if [[ -f "$plugin_file" ]]; then
local plugin_script
plugin_script="$(jq -r '.script // empty' "$plugin_file")"
if [[ -n "$plugin_script" && -f "$PLUGIN_DIR/$plugin_script" ]]; then
env SOURCE="$SOURCE" \
TARGET="$TARGET" \
CHMOD="$CHMOD" \
BASENAME="$BASENAME" \
TMPFILE="$TMPFILE" \
SCRIPT_DIR="$SCRIPT_DIR" \
bash "$PLUGIN_DIR/$plugin_script"
else
local command_template
command_template="$(jq -r '.command // empty' "$plugin_file")"
if [[ -z "$command_template" ]]; then
echo "Invalid plugin definition: $plugin_file"
exit 1
fi
bash -c "$command_template"
fi
else
########################################
# Default fallback installer
########################################
echo " → plugin not found, using default installer"
install -m "$CHMOD" \
-- "$TMPFILE" \
"$TARGET/$BASENAME"
fi
########################################
# Cleanup
########################################
if [[ "$TMPFILE" != "$SOURCE" ]]; then
rm -f -- "$TMPFILE"
fi
done <<< "$markers"
}
########################################
# Initial Scan
########################################
for root in "${DEPLOY_ROOTS[@]}"; do
[[ -d "$root" ]] || continue
while IFS= read -r -d '' file; do
process_file "$file"
done < <(
find "$root" -type f -print0
)
done
echo "Deployment complete."