vinix-ports / tools / desktop-root.py
67 lines · 61 sloc · 3.39 KB · 0f5d6ec05df94bda5d2d6ccc22182f1e876ae9c7
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 if not args.install_only:
43 command = [sys.executable, Path(__file__).with_name("stage-image.py"), args.arch, client,
44 args.repo, work / "image", args.auditor, args.fingerprint]
45 if args.native_layer:
46 command += ["--native-layer", args.native_layer]
47 run("stage", command)
48 with (work / "receipts.sha256").open("x") as receipts:
49 for path in sorted(work.glob("*.log")):
50 with path.open("rb") as stream:
51 receipts.write(f"{hashlib.file_digest(stream, 'sha256').hexdigest()} {path.name}\n")
52
53
54if __name__ == "__main__":
55 parser = argparse.ArgumentParser(description=__doc__)
56 parser.add_argument("arch", choices=("aarch64", "x86_64"))
57 for name in ("repo", "auditor", "work"):
58 parser.add_argument(name, type=lambda p: Path(p).resolve())
59 parser.add_argument("fingerprint", help="the distributor's fingerprint supplied independently of the feed")
60 parser.add_argument("--install-only", action="store_true",
61 help="prepare the audited client for a separate image assembly")
62 parser.add_argument("--native-layer", type=lambda p: Path(p).resolve(),
63 help="install the source-built native desktop layer into the staged image")
64 args = parser.parse_args()
65 if args.install_only and args.native_layer:
66 parser.error("--native-layer requires image staging")
67 build(args)
68