diff --git a/stages/org.osbuild.yum b/stages/org.osbuild.yum deleted file mode 100755 index 454a7e40..00000000 --- a/stages/org.osbuild.yum +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/python3 - -import json -import subprocess -import sys -import tempfile - -STAGE_DESC = "Install packages using YUM" -STAGE_INFO = """ -Depsolves, downloads, and installs packages (and dependencies) using YUM. - -Writes the `repos` into `/tmp/yum.conf`, does some tree setup, and then runs -the buildhost's `yum` command with `--installroot`, plus the following -arguments generated from the stage options: - -* `--releasever={releasever}` -* `--rpmverbosity={verbosity}` -* `--config=/tmp/yum.conf` - -To prepare the tree, this stage mounts `devtmpfs`, `sysfs`, and `proc` at -`/dev`, `/sys`, and `/proc` (respectively). - -Each repo listed in `repos` needs at least one of `mirrorlist`, `metalink`, or -`baseurl`. If a `gpgkey` is provided, `gpgcheck` will be turned on for that -repo, and YUM will exit with an error unless every package downloaded from that -repo is signed by one of the trusted `gpgkey`s. - -Buildhost commands used: `/bin/sh`, `yum`, `mkdir`, `mount`. -""" -STAGE_OPTS = """ -"required": ["repos", "packages", "releasever"], -"properties": { - "repos": { - "description": "Array of repo objects to set up", - "type": "array", - "minItems": 1, - "items": { - "type": "object", - "properties": { - "metalink": { - "description": "metalink URL for this repo", - "type": "string" - }, - "mirrorlist": { - "description": "mirrorlist URL for this repo", - "type": "string" - }, - "baseurl": { - "description": "baseurl for this repo", - "type": "string" - }, - "gpgkey": { - "description": "GPG public key contents (to check signatures)", - "type": "string" - } - }, - "anyOf": [ - {"required": ["metalink"]}, - {"required": ["mirrorlist"]}, - {"required": ["baseurl"]} - ] - } - }, - "packages": { - "description": "List of package-specs to pass to yum", - "type": "array", - "minItems": 1, - "items": { "type": "string" } - }, - "releasever": { - "description": "yum $releasever value", - "type": "string" - }, - "operation": { - "description": "yum command to use", - "type": "string", - "default": "install" - }, - "verbosity": { - "description": "Set yum's --rpmverbosity", - "type": "string", - "default": "info" - } -} -""" - -def write_repofile(f, repoid, repo, keydir): - f.write(f"[{repoid}]\n") - - def write_option(key, value): - f.write(f"{key}={value}\n") - - # silence dnf warning about missing name - write_option("name", repoid) - - for key in ("metalink", "mirrorlist", "baseurl"): - value = repo.get(key) - if value: - write_option(key, value) - - if "gpgkey" in repo: - keyfile = f"{keydir}/{repoid}.asc" - with open(keyfile, "w") as key: - key.write(repo["gpgkey"]) - write_option("gpgcheck", 1) - write_option("gpgkey", f"file://{keyfile}") - - -def main(tree, options): - repos = options["repos"] - packages = options["packages"] - releasever = options["releasever"] - operation = options.get("operation", "install") - verbosity = options.get("verbosity", "info") - - script = f""" - set -e - mkdir -p {tree}/dev {tree}/sys {tree}/proc - mount -t devtmpfs none {tree}/dev - mount -t sysfs none {tree}/sys - mount -t proc none {tree}/proc - """ - try: - subprocess.run(["/bin/sh", "-c", script], check=True) - except subprocess.CalledProcessError as err: - print(f"setting up API VFS in target tree failed: {err.returncode}") - return err.returncode - - with tempfile.TemporaryDirectory(prefix="org.osbuild.yum.") as confdir: - yumconf = f"{confdir}/yum.conf" - with open(yumconf, "w") as conf: - for num, repo in enumerate(repos): - write_repofile(conf, f"repo{num}", repo, confdir) - - cmd = [ - "yum", "--assumeyes", - f"--installroot={tree}", - "--setopt=\"reposdir=\"", - f"--releasever={releasever}", - f"--rpmverbosity={verbosity}", - f"--config={yumconf}", - operation - ] + packages - - print(" ".join(cmd), flush=True) - return subprocess.run(cmd, check=False).returncode - - -if __name__ == '__main__': - args = json.load(sys.stdin) - r = main(args["tree"], args["options"]) - sys.exit(r)