86 lines
2.8 KiB
Bash
86 lines
2.8 KiB
Bash
#!/usr/bin/env sh
|
|
set -euo pipefail
|
|
|
|
# Safe cleaner for local .env and config files in project/module trees.
|
|
# - DRY-RUN by default (shows actions)
|
|
# - Use --apply to actually delete
|
|
# - Never touches:
|
|
# - 4NK_modules/4NK_vault (kept)
|
|
# - blindbit-oracle (external dep images)
|
|
# - rust-silentPayments (external dep)
|
|
# - projects/lecoffre/lecoffre_node/confs (centralized confs)
|
|
|
|
ROOT="/home/debian/4NK_env"
|
|
CENTRAL_CONFS="$ROOT/projects/lecoffre/lecoffre_node/confs"
|
|
|
|
APPLY=0
|
|
[ "${1-}" = "--apply" ] && APPLY=1
|
|
|
|
info() { printf "%s\n" "$*"; }
|
|
warn() { printf "[WARN] %s\n" "$*"; }
|
|
error() { printf "[ERR] %s\n" "$*" 1>&2; }
|
|
|
|
# Candidates to remove (relative globs) in repos (non-central)
|
|
# We only remove if the corresponding central conf exists.
|
|
|
|
# Map: repo_dir|local_path|central_path
|
|
map_entry() {
|
|
repo="$1"; local_p="$2"; central_p="$3";
|
|
# Skip if repo does not exist
|
|
[ -e "$repo" ] || return 0
|
|
if [ -e "$repo/$local_p" ]; then
|
|
if [ -e "$CENTRAL_CONFS/$central_p" ]; then
|
|
if [ $APPLY -eq 1 ]; then
|
|
info "[DEL] $repo/$local_p (central: $central_p present)"
|
|
rm -f "$repo/$local_p" || true
|
|
else
|
|
info "[DRY] would delete: $repo/$local_p (central OK: $central_p)"
|
|
fi
|
|
else
|
|
warn "central missing for $repo/$local_p → expected: $CENTRAL_CONFS/$central_p"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
info "Central confs: $CENTRAL_CONFS"
|
|
[ -d "$CENTRAL_CONFS" ] || warn "central confs directory missing: $CENTRAL_CONFS"
|
|
|
|
# lecoffre-front: remove local .env if any; runtime env via compose
|
|
map_entry "$ROOT/lecoffre-front" ".env" "lecoffre-front/.env"
|
|
|
|
# ihm_client: remove local .env
|
|
map_entry "$ROOT/ihm_client" ".env" "ihm_client/.env"
|
|
|
|
# sdk_relay: remove local .env and sdk_relay.conf (use central)
|
|
map_entry "$ROOT/sdk_relay" ".env" "sdk_relay/.env"
|
|
map_entry "$ROOT/sdk_relay" "sdk_relay.conf" "relay/sdk_relay.conf"
|
|
|
|
# sdk_storage: remove local .env
|
|
map_entry "$ROOT/sdk_storage" ".env" "sdk_storage/.env"
|
|
|
|
# 4NK_certificator: remove local config.toml (keep example)
|
|
map_entry "$ROOT/4NK_certificator" "config.toml" "4nk_certificator/certificator.toml"
|
|
|
|
# 4NK_web_status: remove local .env if any (status API reads env at runtime)
|
|
map_entry "$ROOT/4NK_modules/4NK_web_status" ".env" "monitoring/.env"
|
|
|
|
# 4NK_miner: remove local .env if any (already cleaned miner.env earlier)
|
|
map_entry "$ROOT/4NK_modules/4NK_miner" ".env" "lecoffre_node/.env"
|
|
|
|
# Projects nested: avoid touching central confs; warn only
|
|
for f in "$ROOT"/projects/lecoffre/lecoffre_node/*/*.env; do
|
|
[ -e "$f" ] || continue
|
|
warn "local env in projects tree: $f (not deleting; central expected in $CENTRAL_CONFS)"
|
|
done
|
|
|
|
if [ $APPLY -eq 0 ]; then
|
|
info "\nRun with --apply to delete the [DRY] listed files."
|
|
else
|
|
info "\n[OK] Deletions applied."
|
|
fi
|
|
}
|
|
|
|
main "$@"
|
|
|