|
| 1 | +From e5db53cf8924d705a95702b404929d5d88c91256 Mon Sep 17 00:00:00 2001 |
| 2 | +From: jbtrystram < [email protected]> |
| 3 | +Date: Tue, 21 Oct 2025 13:13:57 +0200 |
| 4 | +Subject: [PATCH] stages: add new symlink stage |
| 5 | + |
| 6 | +This introduces a new stage, `org.osbuild.symlink`, for creating |
| 7 | +symbolic links within the filesystem tree. |
| 8 | + |
| 9 | +This takes a list of paths, each with a `source` and a `link` |
| 10 | +parameters, inspired by the copy stage. |
| 11 | + |
| 12 | +The source is a simple string because we want the link to be either |
| 13 | +absolute or relative. |
| 14 | +--- |
| 15 | + stages/org.osbuild.symlink | 25 +++++++++++++ |
| 16 | + stages/org.osbuild.symlink.meta.json | 56 ++++++++++++++++++++++++++++ |
| 17 | + 2 files changed, 81 insertions(+) |
| 18 | + create mode 100755 stages/org.osbuild.symlink |
| 19 | + create mode 100644 stages/org.osbuild.symlink.meta.json |
| 20 | + |
| 21 | +diff --git a/stages/org.osbuild.symlink b/stages/org.osbuild.symlink |
| 22 | +new file mode 100755 |
| 23 | +index 000000000..cd7ccc2f6 |
| 24 | +--- /dev/null |
| 25 | ++++ b/stages/org.osbuild.symlink |
| 26 | +@@ -0,0 +1,25 @@ |
| 27 | ++#!/usr/bin/python3 |
| 28 | ++import os |
| 29 | ++import sys |
| 30 | ++ |
| 31 | ++import osbuild.api |
| 32 | ++from osbuild.util import parsing |
| 33 | ++ |
| 34 | ++ |
| 35 | ++def main(args, options): |
| 36 | ++ items = options["paths"] |
| 37 | ++ |
| 38 | ++ for path in items: |
| 39 | ++ src = path["source"] |
| 40 | ++ link = parsing.parse_location(path["link"], args) |
| 41 | ++ |
| 42 | ++ print(f"linking'{link}' -> '{src}'") |
| 43 | ++ os.symlink(src, link) |
| 44 | ++ |
| 45 | ++ return 0 |
| 46 | ++ |
| 47 | ++ |
| 48 | ++if __name__ == '__main__': |
| 49 | ++ _args = osbuild.api.arguments() |
| 50 | ++ r = main(_args, _args["options"]) |
| 51 | ++ sys.exit(r) |
| 52 | +diff --git a/stages/org.osbuild.symlink.meta.json b/stages/org.osbuild.symlink.meta.json |
| 53 | +new file mode 100644 |
| 54 | +index 000000000..2b7b990a9 |
| 55 | +--- /dev/null |
| 56 | ++++ b/stages/org.osbuild.symlink.meta.json |
| 57 | +@@ -0,0 +1,56 @@ |
| 58 | ++{ |
| 59 | ++ "summary": "Create symlinks", |
| 60 | ++ "description": [ |
| 61 | ++ "Creates symbolic links within the tree or mounts. The source and destination are specified as URLs.", |
| 62 | ++ "Only allows tree or mounts URLs." |
| 63 | ++ ], |
| 64 | ++ "schema_2": { |
| 65 | ++ "options": { |
| 66 | ++ "additionalProperties": false, |
| 67 | ++ "required": ["paths"], |
| 68 | ++ "properties": { |
| 69 | ++ "paths": { |
| 70 | ++ "description": "Array of symlinks to create.", |
| 71 | ++ "type": "array", |
| 72 | ++ "minItems": 1, |
| 73 | ++ "items": { |
| 74 | ++ "type": "object", |
| 75 | ++ "additionalProperties": false, |
| 76 | ++ "required": ["source", "link"], |
| 77 | ++ "properties": { |
| 78 | ++ "source": { |
| 79 | ++ "type": "string", |
| 80 | ++ "description": "The source of the link, relative or absolute" |
| 81 | ++ }, |
| 82 | ++ "link": { |
| 83 | ++ "oneOf": [ |
| 84 | ++ { |
| 85 | ++ "type": "string", |
| 86 | ++ "description": "The link path, if in a mount", |
| 87 | ++ "pattern": "^mount://[^/]+/" |
| 88 | ++ }, |
| 89 | ++ { |
| 90 | ++ "type": "string", |
| 91 | ++ "description": "The link path, if in a tree", |
| 92 | ++ "pattern": "^tree:///" |
| 93 | ++ } |
| 94 | ++ ] |
| 95 | ++ } |
| 96 | ++ } |
| 97 | ++ } |
| 98 | ++ } |
| 99 | ++ } |
| 100 | ++ }, |
| 101 | ++ "devices": { |
| 102 | ++ "type": "object", |
| 103 | ++ "additionalProperties": true |
| 104 | ++ }, |
| 105 | ++ "mounts": { |
| 106 | ++ "type": "array" |
| 107 | ++ }, |
| 108 | ++ "inputs": { |
| 109 | ++ "type": "object", |
| 110 | ++ "additionalProperties": true |
| 111 | ++ } |
| 112 | ++ } |
| 113 | ++} |
0 commit comments