"""Install the default Vinix desktop package set from an independently pinned feed.""" import argparse import hashlib import subprocess import sys from pathlib import Path def build(args): work = args.work work.mkdir() trust = work / "trust" client = work / "client" def run(label, argv): with (work / (label + ".log")).open("x") as log: subprocess.run(argv, check=True, stdout=log, stderr=subprocess.STDOUT) run("trust", ["feed", "trust", trust, args.repo / "test-signer.asc", args.fingerprint]) run("install", ["feed", "install", trust, args.repo, args.arch, client, "--fakeroot", "vinix-release-desktop"]) run("audit", [args.auditor, args.arch, client]) records = {} for record in (client / "db/local").glob("*/desc"): desc = record.read_text().split("\n\n") name, = [field.splitlines()[1] for field in desc if field.startswith("%NAME%\n")] records[name] = record.with_name("files") owners = {"busybox": "bin/sh", "vinix-desktop-init": "sbin/init", "vpac": "usr/bin/vpac", "vinix-pkg": "usr/bin/pkg", "vinix-keyring": "usr/share/vpac/keyrings/vinix.gpg", "gcc": "usr/bin/gcc", "binutils": "usr/bin/ld", "make": "usr/bin/make", "zsh": "bin/zsh", "btop": "usr/bin/btop"} for name, path in owners.items(): if name not in records or path not in records[name].read_text().splitlines(): raise ValueError(f"expected {name} to own /{path}") root = client / "root" if args.arch == "aarch64": watchdog = "usr/libexec/vinix-desktop-watchdog" if watchdog not in records["vinix-desktop-init"].read_text().splitlines(): raise ValueError(f"expected vinix-desktop-init to own /{watchdog}") for path in ("etc/alpine-release", "etc/apk", "lib/apk/db", "sbin/apk", "usr/sbin/apk", "usr/bin/apk"): if (root / path).exists() or (root / path).is_symlink(): raise ValueError(f"unexpected Alpine package-management path /{path}") if not args.install_only: run("stage", [sys.executable, Path(__file__).with_name("stage-image.py"), args.arch, client, args.repo, work / "image", args.auditor, args.fingerprint]) with (work / "receipts.sha256").open("x") as receipts: for path in sorted(work.glob("*.log")): with path.open("rb") as stream: receipts.write(f"{hashlib.file_digest(stream, 'sha256').hexdigest()} {path.name}\n") if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("arch", choices=("aarch64", "x86_64")) for name in ("repo", "auditor", "work"): parser.add_argument(name, type=lambda p: Path(p).resolve()) parser.add_argument("fingerprint", help="the distributor's fingerprint supplied independently of the feed") parser.add_argument("--install-only", action="store_true", help="prepare the audited client for a separate image assembly") build(parser.parse_args())