#!/usr/bin/env python3 """Dokonczenie: nginx (oba userdel) + pulseaudio + telepathy-idle.""" import re, sys, yaml R = "/var/lib/pagan-sync/recipes" def edit_block(path, old_lines, new_lines, label, expect=1): text = open(path, encoding="utf-8").read() for sep in ("\n[ \t]*", r"\\n[ \t]*"): pat = r"^([ \t]*)" + sep.join(re.escape(l) for l in old_lines) hits = list(re.finditer(pat, text, re.M)) if len(hits) == expect: ind = hits[0].group(1) joiner = ("\n" if sep == "\n[ \t]*" else r"\n") + ind repl = ind + joiner.join(new_lines) text = re.sub(pat, repl.replace("\\", "\\\\"), text, flags=re.M) open(path, "w", encoding="utf-8").write(text) print(f"OK {label} ({len(hits)}x)") return cnt = [len(re.findall(r"^([ \t]*)" + sep.join(re.escape(l) for l in old_lines), text, re.M)) for sep in ("\n[ \t]*", r"\\n[ \t]*")] sys.exit(f"[{label}] dopasowan {cnt} (oczekiwano {expect})") def bump(path, label): text = open(path, encoding="utf-8").read() m = re.search(r"(?m)^pkgrel:\s*'?(\d+)'?\s*$", text) n = int(m.group(1)) + 1 open(path, "w", encoding="utf-8").write(text[:m.start()] + f"pkgrel: '{n}'" + text[m.end():]) print(f"OK {label}: pkgrel -> {n}") NG = f"{R}/utils/nginx/PAGBUILD.yaml" edit_block(NG, ["(getent passwd $UN > /dev/null) && userdel $UN", "(getent group $UN > /dev/null) && groupdel $UN"], ["# Usuniete kasowanie kont www/apache: userdel zostawial pliki z", "# osieroconym uid. Wlasciwe konto http jest tworzone ponizej."], "nginx: bez userdel", expect=2) bump(NG, "nginx") PA = f"{R}/gui/pulseaudio/PAGBUILD.yaml" edit_block(PA, ["grep -qe 'autospawn = no' etc/pulse/client.conf||sudo sed '/autospawn/iautospawn = no' -i etc/pulse/client.conf"], ["grep -qe 'autospawn = no' etc/pulse/client.conf || sed -i '/autospawn/iautospawn = no' etc/pulse/client.conf"], "pulseaudio: bez sudo") bump(PA, "pulseaudio") TI = f"{R}/gui/telepathy-idle/PAGBUILD.yaml" edit_block(TI, ["killall -HUP dbus-daemon 2>&1"], ["systemctl reload dbus 2>/dev/null || true"], "telepathy-idle: reload dbus") bump(TI, "telepathy-idle") print("=== walidacja ===") for f in ["core/shadow", "core/sudo", "core/bash", "core/glibc", "gui/pulseaudio", "gui/telepathy-idle", "utils/nginx"]: p = f + "/PAGBUILD.yaml" d = yaml.safe_load(open(p, encoding="utf-8")) or {} print("OK ", p, "pkgrel=", d.get("pkgrel"))