#!/usr/bin/env python3 """Point guest 9202 at the drill catalog (and a 90 s health timeout), or restore the saved config. `09` §6.5: `git.repo_url` alone is INERT (R-615) — the cache dir must go too. The saved copy is `controller.yaml.pre-pg0928` (NOT the older `.pre-28`, which a restore must never pick up). """ import re, sys, io sys.path.insert(0, '.') import walk as w VOL = "/var/lib/docker/volumes/felhom-controller-data/_data" DRILL_REPO = "https://gitea.dooplex.hu/admin/app-catalog-drill.git" def creds(): for l in io.open("/home/kisfenyo/.git-credentials").read().strip().split("\n"): m = re.match(r'https://(admin):([^@]+)@gitea\.dooplex\.hu', l) if m: return m.group(1), m.group(2) raise SystemExit("no admin credential") def to_drill(): u, t = creds() print(w.guest(f""" set -e test -f {VOL}/controller.yaml.pre-pg0928 || cp -p {VOL}/controller.yaml {VOL}/controller.yaml.pre-pg0928 python3 - <<'PY' import re p = "{VOL}/controller.yaml" s = open(p).read() s = re.sub(r'(^\\s+repo_url: ).*$', r'\\g<1>{DRILL_REPO}', s, count=1, flags=re.M) s = re.sub(r'(^git:(?:\\n\\s+.*)*?\\n\\s+token: ).*$', r'\\g<1>"{t}"', s, count=1, flags=re.M) s = re.sub(r'(^git:(?:\\n\\s+.*)*?\\n\\s+username: ).*$', r'\\g<1>"{u}"', s, count=1, flags=re.M) if not re.search(r'^update:', s, re.M): s += "update:\\n health_timeout: 90s\\n" open(p, "w").write(s) PY rm -rf {VOL}/catalog-cache {VOL}/data/catalog-cache docker restart felhom-controller >/dev/null sleep 15 grep -A6 '^git:' {VOL}/controller.yaml | sed 's/token:.*/token: /' grep -A2 '^update:' {VOL}/controller.yaml """)) def restore(): print(w.guest(f""" set -e cp -p {VOL}/controller.yaml.pre-pg0928 {VOL}/controller.yaml rm -rf {VOL}/catalog-cache {VOL}/data/catalog-cache docker restart felhom-controller >/dev/null sleep 15 grep -A6 '^git:' {VOL}/controller.yaml | sed 's/token:.*/token: /' grep -c '^update:' {VOL}/controller.yaml || true """)) if __name__ == "__main__": to_drill() if sys.argv[1] == "drill" else restore()