| author | Urja (ARMLFS builder)
            <urja+armlfs@urja.dev> 2025-10-11 11:10:27 UTC | 
| committer | Urja (ARMLFS builder)
            <urja+armlfs@urja.dev> 2025-10-11 11:10:27 UTC | 
| parent | 6b1e5ff79fe557c8c2c905184e4e590354f4e12e | 
| autoupdater_helpers/__init__.py | +68 | -8 | 
| crontab.txt | +1 | -0 | 
| nss.py | +23 | -0 | 
diff --git a/autoupdater_helpers/__init__.py b/autoupdater_helpers/__init__.py index 38637a3..0e1682e 100644 --- a/autoupdater_helpers/__init__.py +++ b/autoupdater_helpers/__init__.py @@ -5,20 +5,42 @@ def pkgbuild_ver(): if line.startswith("pkgver="): return line[7:].strip() -def pkgbuild_new_ver(ver, sha256sum=None, rel="1"): +def pkgbuild_new_ver(ver, sha256sum=None, rel="1", sumtype="sha256", sum=None): import os + sumpfx = sumtype + "sums=(" + if sha256sum: + sum = sha256sum + # Skip one line with a checksum + skipsumln = False + # Skip the whole rest of the checksum section + skipsumlines = False with open("PKGBUILD.new", "w") as outf: for line in open("PKGBUILD"): + if skipsumln: + if ')' in line: + skipsumln = False + elif "'" not in line: + continue + else: + skipsumln = False + continue + if skipsumlines: + if ')' in line: + skipsumlines = False + continue if line.startswith("pkgver="): outf.write("pkgver=" + ver + "\n") elif line.startswith("pkgrel="): outf.write(f"pkgrel={rel}\n") - elif line.startswith("sha256sums=("): - if sha256sum: - outf.write("sha256sums=('" + sha256sum + "'\n") + elif line.startswith(sumpfx): + if sum: + outf.write(sumpfx + "'" + sum + "'\n") + if "'" not in line: + skipsumln = True else: - break + if ")" not in line: + skipsumlines = True else: outf.write(line) @@ -38,12 +60,12 @@ def _log(desc): f.write(desc + "\n") -def mpkg(pkg, ver=None): +def mpkg(pkg, ver=None, carch=None): statepath = "/tmp/armlfs-evt" activepath = statepath + "/active" donepath = statepath + "/done" failpath = statepath + "/failed" - from os import makedirs, chdir, getcwd, rename + from os import makedirs, chdir, getcwd, rename, environ from os.path import join from subprocess import run, CalledProcessError desc = f"{pkg} {ver}" if ver else pkg @@ -54,8 +76,11 @@ def mpkg(pkg, ver=None): f.write(desc + "\n") prev_path = getcwd() chdir("/sources/base-pkgbuilds") + myenv = None + if carch: + myenv = dict(environ, CARCH=carch) try: - run(["./mpkg.sh", pkg], check=True) + run(["./mpkg.sh", pkg], env=myenv, check=True) chdir(prev_path) makedirs(donepath, exist_ok=True) rename(fpath, join(donepath,fn)) @@ -66,3 +91,38 @@ def mpkg(pkg, ver=None): rename(fpath, join(failpath,fn)) _log(desc + " FAIL") raise + +def parse_pkgbuild_ver_sum(fn): + meta = {} + sumnextln = False + for line in open(fn): + if sumnextln: + if "'" in line: + _,meta['sum'],_ = line.strip().split("'") + sumnextln = False + if ")" in line: + sumnextln = False + continue + if line.startswith("pkgver="): + meta['ver'] = line[7:].strip() + if "sums=(" in line: + type, sum = line.strip().split("sums=(",maxsplit=1) + if type not in ("b2", "sha512", "sha384", "sha256", "sha224", "sha1", "md5", "ck"): + continue + if "'" not in sum: + sumnextln = True + else: + _,meta['sum'],_ = sum.strip().split("'") + meta['sumtype'] = type + if 'ver' in meta and 'sum' in meta: + break + return meta + +def get_arch_pkgbuild_ver_sum(pkg): + from tempfile import TemporaryDirectory + from subprocess import run + url = f"https://gitlab.archlinux.org/archlinux/packaging/packages/{pkg}.git" + with TemporaryDirectory(prefix=f"tmp-{pkg}-") as dir: + cmd = ["git", "clone", "--depth=1", url, dir ] + run(cmd, check=True) + return parse_pkgbuild_ver_sum(dir + '/PKGBUILD') diff --git a/crontab.txt b/crontab.txt index efa15bc..78620dd 100644 --- a/crontab.txt +++ b/crontab.txt @@ -1,4 +1,5 @@ 40 3 * * * cd /sources/autoupdaters/linux-kbb && ./kbbcron.sh 28 0 21 1,4-12 * cd /sources/autoupdaters && ./updater-cron.sh kicad +12 3 12 * * cd /sources/autoupdaters && ./updater-cron.sh nss 44 5 12 * * cd /sources/autoupdaters && ./updater-cron.sh firefox 7 0 * * 5 cd /sources/autoupdaters && ./updater-cron.sh yt-dlp diff --git a/nss.py b/nss.py new file mode 100755 index 0000000..403cf7f --- /dev/null +++ b/nss.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +import os +import sys +from autoupdater_helpers import * + +os.chdir("/sources/base-pkgbuilds/nss") +prev_ver = pkgbuild_ver() +meta = get_arch_pkgbuild_ver_sum("nss") +ver = meta['ver'] + +if ver == prev_ver: + print("Update not necessary") + sys.exit(0) + +pkgbuild_new_ver(**meta) + +os.chdir("..") + +print(f"Updating {prev_ver} to {ver}") +mpkg("nss", ver) +mpkg("nss", ver, carch="aarch64") +