vinix-ports / tools / release-inputs.py
72 lines · 66 sloc · 3.47 KB · 0632491f44d35d2a0fd7b9931c47480461568ba2
Raw
1"""Prepare the audited initramfs and X11 sidecar consumed by deploy-iso.sh."""
2
3import argparse
4import hashlib
5import os
6from pathlib import Path
7import re
8import subprocess
9import sys
10import tempfile
11
12
13def assemble(args):
14 output = args.output
15 if output.exists() or output.is_symlink():
16 raise FileExistsError(output)
17 arch = "amd64" if args.arch == "x86_64" else "arm64"
18 if not re.fullmatch(r"[0-9a-f]{40}", args.commit):
19 raise ValueError("expected the full Vinix source commit")
20 if args.release and not re.fullmatch(r"[A-Za-z0-9][A-Za-z0-9._-]*", args.release):
21 raise ValueError("invalid Vinix release tag")
22 programs = ["usr/bin/vinix-desktop", "usr/sbin/vinix-account", "usr/sbin/vinix-authd",
23 "usr/sbin/vinix-session", "usr/sbin/vinix-system"]
24 machine = 62 if args.arch == "x86_64" else 183
25 for program in programs:
26 path = args.native / program
27 if path.is_symlink() or not path.is_file() or not os.access(path, os.X_OK):
28 raise ValueError(f"native layer is missing executable /{program}")
29 with path.open("rb") as stream:
30 header = stream.read(20)
31 if header[:6] != b"\x7fELF\x02\x01" or int.from_bytes(header[18:20], "little") != machine:
32 raise ValueError(f"native layer executable has the wrong ELF architecture: /{program}")
33
34 tools = Path(__file__).resolve().parent
35 with tempfile.TemporaryDirectory(prefix=".ports-inputs-", dir=output.parent) as temporary:
36 work = Path(temporary)
37 bundle = work / "bundle"
38 stage = work / "image"
39 bundle_command = [sys.executable, tools / "bundle-x11.py", args.arch, args.desktop,
40 args.graphics, args.auditor, bundle]
41 if args.prepared_x11:
42 bundle_command.extend(["--prepared", args.prepared_x11])
43 subprocess.run(bundle_command, check=True)
44 command = [sys.executable, tools / "stage-image.py", args.arch, args.desktop,
45 args.repo, stage, args.auditor, args.fingerprint, "--native-layer",
46 args.native, "--initramfs", f"--release={args.release}",
47 "--seed-client", args.graphics]
48 if args.archive_coverage:
49 command.extend(["--archive-coverage", args.archive_coverage])
50 subprocess.run(command, check=True)
51 (stage / "initramfs.tar").rename(bundle / "initramfs.tar")
52 info = bundle / "build-info"
53 info.write_text(f"commit={args.commit}\nrelease={args.release}\narch={arch}\n")
54 assets = sorted(bundle.iterdir())
55 with (bundle / "SHA256SUMS").open("x") as manifest:
56 for path in assets:
57 with path.open("rb") as stream:
58 digest = hashlib.file_digest(stream, "sha256").hexdigest()
59 manifest.write(f"{digest} {path.name}\n")
60 bundle.rename(output)
61
62
63if __name__ == "__main__":
64 parser = argparse.ArgumentParser(description=__doc__)
65 parser.add_argument("arch", choices=("x86_64", "aarch64"))
66 for name in ("repo", "desktop", "graphics", "native", "auditor", "output"):
67 parser.add_argument(name, type=lambda path: Path(path).absolute())
68 for name in ("fingerprint", "commit", "release"):
69 parser.add_argument(name)
70 parser.add_argument("--archive-coverage", type=Path, help="verified archive inventory for the signed seed")
71 parser.add_argument("--prepared-x11", type=Path, help="directory of the previously assembled X11 sidecar")
72 assemble(parser.parse_args())
73