From e6dd428107030243ac72246e2fc209aced9ef241 Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Fri, 14 Jun 2019 18:45:19 +0200 Subject: [PATCH] osbuild.py: rename run-stage to osbuild-run Run all programs in the build root through osbuild-run. The things it sets up are probbaly needed by everything. --- osbuild-run | 22 ++++++++++++++++++++++ osbuild.py | 10 +++++----- run-stage | 36 ------------------------------------ 3 files changed, 27 insertions(+), 41 deletions(-) create mode 100755 osbuild-run delete mode 100755 run-stage diff --git a/osbuild-run b/osbuild-run new file mode 100755 index 00000000..c05a67f7 --- /dev/null +++ b/osbuild-run @@ -0,0 +1,22 @@ +#!/usr/bin/python3 + +import subprocess +import sys + + +# ld.so.conf must exist, or `ldconfig` throws a warning +subprocess.run(["touch", "/etc/ld.so.conf"], check=True) +subprocess.run(["ldconfig"], check=True) + +try: + subprocess.run(["systemd-sysusers"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True) +except subprocess.CalledProcessError as error: + sys.stderr.write(error.stdout) + sys.exit(1) + +# Allow systemd-tmpfiles to return non-0. Some packages want to create +# directories owned by users that are not set up with systemd-sysusers. +subprocess.run(["systemd-tmpfiles", "--create"]) + +r = subprocess.run(sys.argv[1:]) +sys.exit(r.returncode) diff --git a/osbuild.py b/osbuild.py index f109187c..aaf85849 100644 --- a/osbuild.py +++ b/osbuild.py @@ -66,9 +66,11 @@ class BuildRoot: "--volatile=yes", f"--machine={self.machine_name}", f"--directory={self.buildroot}", + f"--bind={libdir}/osbuild-run:/run/osbuild-run", f"--bind={self.tree}:/tmp/tree", *[f"--bind={src}:{dest}" for src, dest in binds], - *[f"--bind-ro={src}:{dest}" for src, dest in readonly_binds] + *[f"--bind-ro={src}:{dest}" for src, dest in readonly_binds], + "/run/osbuild-run", ] + argv, *args, **kwargs) def run_stage(self, stage, options={}, input_dir=None): @@ -79,7 +81,6 @@ class BuildRoot: } robinds = [ - (f"{libdir}/run-stage", "/tmp/run-stage"), (f"{libdir}/stages/{stage}", "/tmp/stage"), ("/etc/pki", "/etc/pki") ] @@ -87,7 +88,7 @@ class BuildRoot: options["input_dir"] = "/tmp/input" robinds.append((input_dir, "/tmp/input")) try: - self.run(["/tmp/run-stage", "/tmp/stage"], readonly_binds=robinds, + self.run(["/tmp/stage"], readonly_binds=robinds, input=json.dumps(options), encoding="utf-8", check=True) except subprocess.CalledProcessError as error: raise StageFailed(stage, error.returncode) @@ -103,7 +104,6 @@ class BuildRoot: } robinds = [ - (f"{libdir}/run-stage", "/tmp/run-stage"), (f"{libdir}/stages/{name}", "/tmp/stage"), ("/etc/pki", "/etc/pki") ] @@ -114,7 +114,7 @@ class BuildRoot: binds.append((output_dir, "/tmp/output")) try: - self.run(["/tmp/run-stage", "/tmp/stage"], binds=binds, readonly_binds=robinds, input=json.dumps(options), encoding="utf-8", check=True) + self.run(["/tmp/stage"], binds=binds, readonly_binds=robinds, input=json.dumps(options), encoding="utf-8", check=True) except subprocess.CalledProcessError as error: raise StageFailed(stage, error.returncode) diff --git a/run-stage b/run-stage deleted file mode 100755 index 343f6d11..00000000 --- a/run-stage +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/python3 - -import argparse -import subprocess -import sys - - -RESET = "\033[0m" -BOLD = "\033[1m" -RED = "\033[31m" - - -def main(stage): - # ld.so.conf must exist, or `ldconfig` throws a warning - subprocess.run(["touch", "/etc/ld.so.conf"], check=True) - subprocess.run(["ldconfig"], check=True) - - try: - subprocess.run(["systemd-sysusers"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True) - except subprocess.CalledProcessError as error: - sys.stderr.write(error.stdout) - return 1 - - # Allow systemd-tmpfiles to return non-0. Some packages want to create - # directories owned by users that are not set up with systemd-sysusers. - subprocess.run(["systemd-tmpfiles", "--create"]) - - r = subprocess.run([stage]) - return r.returncode - - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument("stage") - args = parser.parse_args() - sys.exit(main(**vars(args)))