vinix-ports / tools / desktop-root.py
56 lines · 50 sloc · 2.79 KB · ae5d59975b62c2b37c7f4f2f490e34de16681bff
Raw
1"""Install the default Vinix desktop package set from an independently pinned feed."""
2import argparse
3import hashlib
4import subprocess
5import sys
6from pathlib import Path
7
8
9def build(args):
10 work = args.work
11 work.mkdir()
12 trust = work / "trust"
13 client = work / "client"
14
15 def run(label, argv):
16 with (work / (label + ".log")).open("x") as log:
17 subprocess.run(argv, check=True, stdout=log, stderr=subprocess.STDOUT)
18
19 run("trust", ["feed", "trust", trust, args.repo / "test-signer.asc", args.fingerprint])
20 run("install", ["feed", "install", trust, args.repo, args.arch, client, "--fakeroot", "vinix-release-desktop"])
21 run("audit", [args.auditor, args.arch, client])
22 records = {}
23 for record in (client / "db/local").glob("*/desc"):
24 desc = record.read_text().split("\n\n")
25 name, = [field.splitlines()[1] for field in desc if field.startswith("%NAME%\n")]
26 records[name] = record.with_name("files")
27 owners = {"busybox": "bin/sh", "vinix-desktop-init": "sbin/init", "vpac": "usr/bin/vpac",
28 "vinix-pkg": "usr/bin/pkg",
29 "vinix-keyring": "usr/share/vpac/keyrings/vinix.gpg", "gcc": "usr/bin/gcc",
30 "binutils": "usr/bin/ld", "make": "usr/bin/make", "zsh": "bin/zsh", "btop": "usr/bin/btop"}
31 for name, path in owners.items():
32 if name not in records or path not in records[name].read_text().splitlines():
33 raise ValueError(f"expected {name} to own /{path}")
34 root = client / "root"
35 if args.arch == "aarch64":
36 watchdog = "usr/libexec/vinix-desktop-watchdog"
37 if watchdog not in records["vinix-desktop-init"].read_text().splitlines():
38 raise ValueError(f"expected vinix-desktop-init to own /{watchdog}")
39 for path in ("etc/alpine-release", "etc/apk", "lib/apk/db", "sbin/apk", "usr/sbin/apk", "usr/bin/apk"):
40 if (root / path).exists() or (root / path).is_symlink():
41 raise ValueError(f"unexpected Alpine package-management path /{path}")
42 run("stage", [sys.executable, Path(__file__).with_name("stage-image.py"), args.arch, client,
43 args.repo, work / "image", args.auditor, args.fingerprint])
44 with (work / "receipts.sha256").open("x") as receipts:
45 for path in sorted(work.glob("*.log")):
46 with path.open("rb") as stream:
47 receipts.write(f"{hashlib.file_digest(stream, 'sha256').hexdigest()} {path.name}\n")
48
49
50if __name__ == "__main__":
51 parser = argparse.ArgumentParser(description=__doc__)
52 parser.add_argument("arch", choices=("aarch64", "x86_64"))
53 for name in ("repo", "auditor", "work"):
54 parser.add_argument(name, type=lambda p: Path(p).resolve())
55 parser.add_argument("fingerprint", help="the distributor's fingerprint supplied independently of the feed")
56 build(parser.parse_args())
57