-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·89 lines (76 loc) · 2.86 KB
/
bootstrap.sh
File metadata and controls
executable file
·89 lines (76 loc) · 2.86 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
set -euo pipefail
cd /opt/media-control-box
# 0) Ensure library dir exists (you already added libs earlier)
mkdir -p scripts/lib
# 1) Create service folders
mkdir -p scripts/{dns,certs,turn,proxy,prometheus,grafana}
# 2) Helper: make a 4-file stub set for a service
mk_service_stubs() {
svc="$1"
dir="scripts/$svc"
for f in plan apply remove status; do
cat > "$dir/$f.sh" <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
# SERVICE_NAME will be injected by sed below
# Load shared libs
. "$(cd "$(dirname "$0")/../.." && pwd)/scripts/lib/core.sh"
env_load "$SERVICE_NAME"
# Optional: pick libs you need; they can be safely sourced even if unused
. "$(cd "$(dirname "$0")/../.." && pwd)/scripts/lib/dns_cf.sh" || true
. "$(cd "$(dirname "$0")/../.." && pwd)/scripts/lib/cert_cf.sh" || true
. "$(cd "$(dirname "$0")/../.." && pwd)/scripts/lib/sys_pkg.sh" || true
. "$(cd "$(dirname "$0")/../.." && pwd)/scripts/lib/docker.sh" || true
. "$(cd "$(dirname "$0")/../.." && pwd)/scripts/lib/net.sh" || true
log_file="$(today_log_path "$SERVICE_NAME")"
logln(){ printf "%s\n" "$*" | tee -a "$log_file"; }
cmd="$(basename "$0")"
case "$cmd" in
plan.sh)
logln "PLAN: $SERVICE_NAME — describe what would change (no side-effects)"
# Example: validate required env here (no secrets printed)
# require_vars EXAMPLE_VAR
;;
apply.sh)
logln "APPLY: $SERVICE_NAME — performing idempotent changes"
# Example scaffold:
# if is_dry_run; then logln "DRY-RUN: would do X"; exit 0; fi
# ... do work with libs ...
;;
remove.sh)
logln "REMOVE: $SERVICE_NAME — stopping/removing only this service's artifacts"
# ... stop containers, remove firewall rules owned by this service (idempotent) ...
;;
status.sh)
logln "STATUS: $SERVICE_NAME — quick health summary"
# ... show ports, container status, version, endpoints ...
;;
*)
err "Unknown command"; exit 1;;
esac
EOF
done
# Inject SERVICE_NAME into each file
sed -i "1i SERVICE_NAME=\"$svc\"" "$dir/"*.sh
chmod +x "$dir/"*.sh
}
# 3) Generate stubs for each service
for svc in dns certs turn proxy prometheus grafana; do
mk_service_stubs "$svc"
done
# 4) Add brief README markers per service (optional, helps navigation)
for svc in dns certs turn proxy prometheus grafana; do
cat > "scripts/$svc/README.md" <<EOF
# $svc service scripts
- plan.sh — dry-run; prints what would happen
- apply.sh — idempotent apply
- remove.sh — clean removal of only this service
- status.sh — quick health summary
These scripts read: env/global.env, env/${svc}.env (+ *.local.env).
They write logs to var/logs/${svc}/ and state to var/state/${svc}/.
EOF
done
# 5) Commit
git add scripts/dns scripts/certs scripts/turn scripts/proxy scripts/prometheus scripts/grafana
git commit -m "chore(scripts): adopt service folders with uniform plan/apply/remove/status stubs"
git push