stages: add org.osbuild.untar

Add a new stage that can be used to extract a tarball.
This commit is contained in:
Christian Kellner 2021-08-06 23:53:18 +02:00 committed by Achilleas Koutsou
parent ff63bb6b51
commit 569697e9a9
6 changed files with 1507 additions and 0 deletions

73
stages/org.osbuild.untar Executable file
View file

@ -0,0 +1,73 @@
#!/usr/bin/python3
"""
Extract a tarball
Buildhost commands used: `tar`.
"""
import os
import subprocess
import sys
import osbuild.api
SCHEMA_2 = r"""
"inputs": {
"type": "object",
"additionalProperties": false,
"required": ["file"],
"properties": {
"file": {
"type": "object",
"additionalProperties": true
}
}
},
"options": {
"additionalProperties": false,
"properties": {
"prefix": {
"description": "Unpack here.",
"type": "string",
"default": "/"
}
}
}
"""
def parse_input(inputs):
image = inputs["file"]
files = image["data"]["files"]
assert len(files) == 1
filename, _ = files.popitem()
filepath = os.path.join(image["path"], filename)
return filepath
def main(inputs, output, options):
prefix = options.get("prefix", "/")
source = parse_input(inputs)
target = os.path.join(output, prefix.lstrip("/"))
cmd = [
"tar",
"--auto-compress",
"-x",
"-f", source,
"-C", target
]
subprocess.run(
cmd, check=True
)
return 0
if __name__ == '__main__':
args = osbuild.api.arguments()
r = main(args["inputs"], args["tree"], args["options"])
sys.exit(r)