#!/usr/bin/env python3 """Point guest 9202 at the drill catalog, or back at the live one (09 ยง6.5, R-615). `git.repo_url` alone is INERT: `Syncer.gitCloneOrPull` clones only when the cache has no `.git`, otherwise it fetches from the remote the existing clone stores. The cache directory must be removed too, or the box goes on following the live catalog AND REPORTS SUCCESS. That is R-615, and it is why step 3 exists. """ import re, sys, io sys.path.insert(0, '.') import walk as w VOL = "/var/lib/docker/volumes/felhom-controller-data/_data" LIVE = "https://gitea.dooplex.hu/admin/app-catalog-felhom.eu.git" 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 for gitea.dooplex.hu") def repoint(to_drill): u, t = creds() if to_drill else ("", "") url = DRILL_REPO if to_drill else LIVE script = f""" set -e test -f {VOL}/controller.yaml.pre-28 || cp {VOL}/controller.yaml {VOL}/controller.yaml.pre-28 python3 - <<'EOF' import re p = "{VOL}/controller.yaml" s = open(p).read() s = re.sub(r'(^\\s+repo_url: ).*$', r'\\g<1>{url}', s, count=1, flags=re.M) s = re.sub(r'(^\\s+token: ).*$', r'\\g<1>"{t}"', s, count=1, flags=re.M) s = re.sub(r'(^\\s+username: ).*$', r'\\g<1>"{u}"', s, count=1, flags=re.M) open(p, "w").write(s) EOF # R-615: the cache is the thing that actually decides which remote is fetched. rm -rf {VOL}/catalog-cache {VOL}/data/catalog-cache docker restart felhom-controller >/dev/null sleep 12 grep -A6 '^git:' {VOL}/controller.yaml | sed 's/token:.*/token: /' """ print(w.guest(script)) if __name__ == "__main__": repoint(sys.argv[1] == "drill")