From ee124df3364055cd35a6006536965b942b283db0 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Sun, 6 Jun 2021 14:43:10 +0000 Subject: [PATCH] stages: add org.osbuild.ostree.init-os Initializes a new stateroot (see [1]) for the OS with the name `osname`. --- stages/org.osbuild.ostree.os-init | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 stages/org.osbuild.ostree.os-init diff --git a/stages/org.osbuild.ostree.os-init b/stages/org.osbuild.ostree.os-init new file mode 100755 index 00000000..ffb34f3a --- /dev/null +++ b/stages/org.osbuild.ostree.os-init @@ -0,0 +1,49 @@ +#!/usr/bin/python3 +""" +Initialize a new stateroot for a new OS + +Initializes a new stateroot (see [1]) for the OS with the +name `osname`. + +[1] https://ostree.readthedocs.io/en/latest/manual/deployment/ +""" + +import sys +import subprocess + +import osbuild.api + +SCHEMA = """ +"required": ["osname"], +"properties": { + "osname": { + "description": "Name of the stateroot to be used in the deployment", + "type": "string" + } +} +""" + + +def ostree(*args, _input=None, **kwargs): + args = list(args) + [f'--{k}={v}' for k, v in kwargs.items()] + print("ostree " + " ".join(args), file=sys.stderr) + subprocess.run(["ostree"] + args, + encoding="utf-8", + stdout=sys.stderr, + input=_input, + check=True) + + +def main(tree, options): + osname = options["osname"] + + ostree("admin", "os-init", osname, sysroot=tree) + + return 0 + + +if __name__ == '__main__': + stage_args = osbuild.api.arguments() + r = main(stage_args["tree"], + stage_args["options"]) + sys.exit(r)