From 200c6c373c11f6837ac2564f7e1f7329c0232db4 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 16 Feb 2021 18:26:48 +0100 Subject: [PATCH] stages: add org.osbuild.lorax-script Add a new stage that uses the recently added lorax template helpers to execute such a template. The template itself will be search in the build root, but the command of the script will operate on the tree. --- stages/org.osbuild.lorax-script | 97 +++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100755 stages/org.osbuild.lorax-script diff --git a/stages/org.osbuild.lorax-script b/stages/org.osbuild.lorax-script new file mode 100755 index 00000000..476c4c9b --- /dev/null +++ b/stages/org.osbuild.lorax-script @@ -0,0 +1,97 @@ +#!/usr/bin/python3 +""" +Run a lorax template script on the tree + +This stage can be use to run a lorax template script on the tree. +The location that is specified in `path` will be interpreted to be +relative to `/usr/share/lorax/templates.d` on the build root. + +The use case for this stage is primarily to run the post install +scripts to create bootable isos, provided by Lorax. Depending on +the script, `basearch`, `product` or both have to be specified. + +The stage uses the `osbuild.utils.lorax` helpers internally, so all +operations supported by the helpers are supported by this stage. +NB: This is only a subset of the Lorax ones, i.e. it is missing the +commands to create disks and images. +""" + +import collections +import os +import sys + +from osbuild.util.lorax import render_template, Script + +import osbuild.api + + +SCHEMA = """ +"additionalProperties": false, +"required": ["path"], +"properties": { + "path": { + + }, + "basearch": { + "type": "string", + "description": "The basic architecture param to supply to the template" + }, + "product": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + } + }, + "libdir": { + "type": "string", + "default": "lib64" + } + } +} +""" + + +LORAX_TEMPLATES = "/usr/share/lorax/templates.d" + + +Product = collections.namedtuple("Product", ["name", "version"]) + + +def main(tree, options): + filename = options["path"] + basearch = options.get("basearch", "x86_64") + product = options.get("product", {}) + libdir = options.get("libdir", "lib64") + + fullpath = os.path.join(LORAX_TEMPLATES, filename) + basepath = os.path.dirname(fullpath) + configdir = os.path.join(basepath, "config_files") + + name = product.get("name", "") + version = product.get("version", "") + product = Product(name, version) + + args = { + "root": tree, + "basearch": basearch, + "configdir": configdir, + "libdir": libdir, + "product": product + } + + tpl = render_template(fullpath, args) + script = Script(tpl, "/", tree) + print(f"running script: {os.path.dirname(filename)}") + script() + + +if __name__ == '__main__': + stage_args = osbuild.api.arguments() + r = main(stage_args["tree"], + stage_args["options"]) + sys.exit(r)