#!/usr/bin/env bash set -euo pipefail DIR="/opt/hx-ki/com2-stack" COMPOSE="$DIR/docker-compose.yml" ENVF="$DIR/.env" MA_CONTAINER="hxki-mautic" echo "=== COM2 ยท MAUTIC RECREATE (service-resolve, no guessing) ===" [ -f "$COMPOSE" ] || { echo "FAIL: missing $COMPOSE"; exit 1; } [ -f "$ENVF" ] || { echo "FAIL: missing $ENVF"; exit 1; } # 1) Find service name that owns container_name: hxki-mautic (authority: compose) SVC="$( python3 - <<'PY' import re, pathlib p = pathlib.Path("/opt/hx-ki/com2-stack/docker-compose.yml") s = p.read_text() m = re.search(r'(?ms)^services:\s*\n(.*?)(?=^\S|\Z)', s) if not m: print("") raise SystemExit(0) blk = m.group(1) # parse services by 2-space indentation services = [] cur = None cur_lines = [] for line in blk.splitlines(True): m2 = re.match(r'^ ([A-Za-z0-9_.-]+):\s*$', line) if m2: if cur: services.append((cur, "".join(cur_lines))) cur = m2.group(1) cur_lines = [] else: if cur is not None: cur_lines.append(line) if cur: services.append((cur, "".join(cur_lines))) # priority 1: container_name match for name, body in services: if re.search(r'(?m)^\s{4}container_name:\s*hxki-mautic\s*$', body): print(name); raise SystemExit(0) # priority 2: image contains mautic for name, body in services: if re.search(r'(?m)^\s{4}image:\s*.*mautic.*$', body, re.I): print(name); raise SystemExit(0) print("") PY )" if [ -z "$SVC" ]; then echo "FAIL: Konnte Mautic-Service-Namen in $COMPOSE nicht finden." echo "Check: grep -n 'container_name: hxki-mautic' $COMPOSE" exit 1 fi echo "OK: Mautic service name in compose = $SVC" # 2) Ensure admin vars exist in .env (no guessing; generate if missing) - safe charset (no tr range bug) set -a # shellcheck disable=SC1090 . "$ENVF" || true set +a gen_pw() { tr -dc 'A-Za-z0-9@#%+=:,.!'