From 3eb87a14e133b266ab8d8c634dda3af312474f1f Mon Sep 17 00:00:00 2001 From: Nippy Date: Sat, 19 Sep 2026 18:04:27 +0200 Subject: new user settings --- raveos-updater/check.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 raveos-updater/check.py (limited to 'raveos-updater/check.py') diff --git a/raveos-updater/check.py b/raveos-updater/check.py new file mode 100644 index 0000000..79a0ba3 --- /dev/null +++ b/raveos-updater/check.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +"""RaveOS frissítés-ellenőrző. + +A raveos-core-repo szinkron adatbázisából kiolvassa a RaveOS saját +csomagjainak legfrissebb verzióját, összeveti a telepített verziókkal, +és a /var/lib/raveos-updater/status.json fájlba írja az eredményt. + +Használat: + check.py # pacman -Sy után ellenőriz (root; a systemd timer hívja) + check.py --no-sync # nem szinkronizál, a meglévő DB-t használja (pacman hook) +""" + +import json +import os +import subprocess +import sys +from datetime import datetime + +REPO = "raveos-core-repo" +STATUS_DIR = "/var/lib/raveos-updater" +STATUS_FILE = os.path.join(STATUS_DIR, "status.json") + + +def run(args): + return subprocess.run(args, capture_output=True, text=True) + + +def main(): + sync = "--no-sync" not in sys.argv[1:] + error = None + + if sync: + r = run(["pacman", "-Sy", "--noconfirm"]) + if r.returncode != 0: + error = "sync failed" + + installed = {} + repo = {} + + try: + for line in run(["pacman", "-Q"]).stdout.splitlines(): + name, _, version = line.partition(" ") + if version: + installed[name] = version + + for line in run(["pacman", "-Sl", REPO]).stdout.splitlines(): + parts = line.split() + if len(parts) >= 3: + repo[parts[1]] = parts[2] + except FileNotFoundError: + error = "pacman not found" + + updates = [] + for name, newver in sorted(repo.items()): + oldver = installed.get(name) + if oldver is None: + continue + r = run(["vercmp", newver, oldver]) + try: + newer = int(r.stdout.strip()) > 0 + except (ValueError, AttributeError): + continue + if newer: + updates.append({"name": name, "old": oldver, "new": newver}) + + status = { + "count": len(updates), + "checked": datetime.now().astimezone().isoformat(timespec="seconds"), + "updates": updates, + } + if error: + status["error"] = error + + os.makedirs(STATUS_DIR, exist_ok=True) + tmp = STATUS_FILE + ".tmp" + with open(tmp, "w", encoding="utf-8") as f: + json.dump(status, f, ensure_ascii=False, indent=2) + os.replace(tmp, STATUS_FILE) + os.chmod(STATUS_FILE, 0o644) + + +if __name__ == "__main__": + main() -- cgit v1.3