"""Upgrade a signed Vinix account seed over locally edited, locked test accounts.""" import argparse from pathlib import Path import shutil import stat import subprocess def command(*args): subprocess.run(args, check=True) def test(args): args.work.mkdir() src = args.work / "vinix-accounts" src.mkdir() recipe = src / "PKGBUILD.vile" shutil.copyfile(args.recipe, recipe) manifest = args.work / "manifest" command("vpac", "--native-build", recipe, manifest) old, = manifest.read_text().splitlines() old_feed = args.work / "old-feed" new_feed = args.work / "new-feed" command("feed", "publish", args.keys, old_feed, args.arch, old) client = args.work / "client" command("feed", "install", args.keys, old_feed, args.arch, client, "--fakeroot", "vinix-accounts") etc = client / "root/etc" edited = {} for name, entry in [("passwd", "fixture:x:45000:45000:Test:/nonexistent:/bin/false"), ("group", "fixture:x:45000:"), ("shadow", "fixture:!:0:0:99999:7:::")]: path = etc / name with path.open("a") as output: output.write(entry + "\n") edited[name] = path.read_bytes() # Only the private test snapshot changes the packaged default group. text = recipe.read_text() start = " #:package, fn() {" if text.count(start) != 1 or text.count("#:pkgrel, 1,") != 1: raise ValueError("update fixture must match the original recipe") text = text.replace("#:pkgrel, 1,", "#:pkgrel, 2,") recipe.write_text(text.replace(start, start + '\n run("sed", "-i", "$a vendor:x:45001:", "group")')) command("vpac", "--native-build", recipe, manifest) new, = manifest.read_text().splitlines() command("feed", "publish", args.keys, new_feed, args.arch, new) config = (client / "config.vile").read_text() if config.count("/old-feed/") != 1: raise ValueError("expected exactly one initial feed in client configuration") upgrade_config = client / "upgrade.vile" upgrade_config.write_text(config.replace("/old-feed/", "/new-feed/")) command("fakeroot", "--", "vpac", "--config", upgrade_config, "u", "--sync", "--noconfirm") for name, value in edited.items(): if (etc / name).read_bytes() != value: raise RuntimeError(f"local {name} entries changed on upgrade") if stat.S_IMODE((etc / "shadow").stat().st_mode) != 0o600: raise RuntimeError("installed shadow permissions changed") if "vendor:x:45001:" not in (etc / "group.pacnew").read_text().splitlines(): raise RuntimeError("new packaged group defaults were not preserved for review") db = client / "db/local" if not (db / "vinix-accounts-0.1.0-2").is_dir() or (db / "vinix-accounts-0.1.0-1").exists(): raise RuntimeError("account seed version did not upgrade") print("Account seed upgrade preserved local passwd, group, private shadow and the new group defaults.") if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) for name in ["recipe", "keys", "work"]: parser.add_argument(name, type=lambda path: Path(path).resolve()) parser.add_argument("arch", choices=["x86_64", "aarch64"]) test(parser.parse_args())