8db4425d98
gates / gates (push) Successful in 2m38s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
38 lines
1.6 KiB
Python
38 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Point 9202 at the drill catalog, or put the saved controller.yaml back. `09` §6.5."""
|
|
import io, os, re, sys
|
|
sys.path.insert(0, "/mnt/5_hdd/felhom.eu/git/app-catalog-felhom.eu/scripts")
|
|
import box_walk as w
|
|
VOL = "/var/lib/docker/volumes/felhom-controller-data/_data"
|
|
SAVE = f"{VOL}/controller.yaml.pre-designbuild"
|
|
DRILL = "https://gitea.dooplex.hu/admin/app-catalog-drill.git"
|
|
def creds():
|
|
for l in io.open(os.path.expanduser("~/.git-credentials")).read().split("\n"):
|
|
m = re.match(r"https://(admin):([^@]+)@gitea\.dooplex\.hu", l)
|
|
if m: return m.group(1), m.group(2)
|
|
sys.exit("no admin credential")
|
|
if sys.argv[1] == "drill":
|
|
u, t = creds()
|
|
out = w.guest(f"""set -e
|
|
test -f {SAVE} || cp -p {VOL}/controller.yaml {SAVE}
|
|
python3 - <<'PY'
|
|
import re
|
|
p = "{VOL}/controller.yaml"; s = open(p).read()
|
|
s = re.sub(r'(^\\s+repo_url: ).*$', r'\\g<1>{DRILL}', 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)
|
|
open(p, "w").write(s)
|
|
PY
|
|
rm -rf {VOL}/catalog-cache {VOL}/data/catalog-cache
|
|
docker restart felhom-controller >/dev/null
|
|
grep -n 'repo_url' {VOL}/controller.yaml
|
|
""")
|
|
print(out.replace(t, "<token>"))
|
|
elif sys.argv[1] == "restore":
|
|
print(w.guest(f"""set -e
|
|
cp -p {SAVE} {VOL}/controller.yaml
|
|
rm -rf {VOL}/catalog-cache {VOL}/data/catalog-cache
|
|
docker restart felhom-controller >/dev/null
|
|
grep -n 'repo_url' {VOL}/controller.yaml; grep -c 'token: ""' {VOL}/controller.yaml || true
|
|
cmp {SAVE} {VOL}/controller.yaml && echo RESTORED-IDENTICAL"""))
|