From d793ffd80557bfc3891881956ffefc5fb0359b5a Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 8 Jul 2021 23:30:15 +0200 Subject: [PATCH] stages: add org.osbuild.ostree.config Change OSTree configuration for a repository via `ostree config`. --- stages/org.osbuild.ostree.config | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 stages/org.osbuild.ostree.config diff --git a/stages/org.osbuild.ostree.config b/stages/org.osbuild.ostree.config new file mode 100755 index 00000000..5dc378ca --- /dev/null +++ b/stages/org.osbuild.ostree.config @@ -0,0 +1,72 @@ +#!/usr/bin/python3 +""" +Change OSTree configuration + +Change the configuration for an OSTree repository. +Currently only the following values are supported: + - `sysroot.readonly` +""" + +import os +import sys +import subprocess + +import osbuild.api + + +SCHEMA = """ +"additionalProperties": false, +"required": ["repo"], +"properties": { + "repo": { + "description": "Location of the OSTree repo.", + "type": "string" + }, + "config": { + "type": "object", + "additionalProperties": false, + "description": "OSTree configuration groups", + "properties": { + "sysroot": { + "type": "object", + "additionalProperties": false, + "description": "Options concerning the sysroot", + "properties": { + "readonly": { + "description": "Read only sysroot and boot", + "type": "boolean" + } + } + } + } + } +} +""" + + +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): + repo = os.path.join(tree, options["repo"].lstrip("/")) + config = options["config"] + + for group, items in config.items(): + for key, value in items.items(): + name = f"{group}.{key}" + ostree("config", "set", name, str(value), + repo=repo) + + +if __name__ == '__main__': + stage_args = osbuild.api.arguments() + r = main(stage_args["tree"], + stage_args["options"]) + sys.exit(r)