osbuild
This commit is contained in:
commit
ae1afef209
3 changed files with 156 additions and 0 deletions
39
stages/io.weldr.anaconda
Executable file
39
stages/io.weldr.anaconda
Executable file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
def main(tree, kickstart, skip_package_install=False):
|
||||
with open("/tmp/kickstart.ks", "w") as f:
|
||||
if skip_package_install:
|
||||
subprocess.run(["tar", "cvf", "/tmp/empty.tar", "--files-from", "/dev/null"])
|
||||
f.write(f"liveimg --url=file:///tmp/empty.tar\n")
|
||||
f.write(kickstart)
|
||||
|
||||
cmd = [
|
||||
"anaconda",
|
||||
"--cmdline",
|
||||
"--loglevel", "debug",
|
||||
"--kickstart", "/tmp/kickstart.ks",
|
||||
"--dirinstall", tree
|
||||
]
|
||||
print(" ".join(cmd), flush=True)
|
||||
returncode = subprocess.run(cmd).returncode
|
||||
|
||||
if returncode != 0:
|
||||
print("\n=== anaconda.log" + "=" * 50)
|
||||
with open("/tmp/anaconda.log") as f:
|
||||
print(f.read())
|
||||
|
||||
if skip_package_install:
|
||||
os.unlink("/tmp/empty.tar")
|
||||
os.unlink("/tmp/kickstart.ks")
|
||||
|
||||
return returncode
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
47
stages/io.weldr.dnf
Executable file
47
stages/io.weldr.dnf
Executable file
|
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import atexit
|
||||
import configparser
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
def bindmount(source, dest):
|
||||
os.makedirs(source, 0o755, True)
|
||||
os.makedirs(dest, 0o755, True)
|
||||
subprocess.run(["mount", "--bind", source, dest], check=True)
|
||||
atexit.register(lambda: subprocess.run(["umount", dest]))
|
||||
|
||||
def main(tree, repos, packages, releasever, cache=None):
|
||||
with tempfile.NamedTemporaryFile(mode="w", prefix="dnf-", suffix=".conf", delete=False) as dnfconfig:
|
||||
p = configparser.ConfigParser()
|
||||
p.read_dict(repos)
|
||||
p.write(dnfconfig)
|
||||
atexit.register(lambda: os.unlink(dnfconfig.name))
|
||||
|
||||
bindmount("/proc", f"{tree}/proc")
|
||||
bindmount("/sys", f"{tree}/sys")
|
||||
bindmount("/dev", f"{tree}/dev")
|
||||
|
||||
if cache:
|
||||
bindmount(cache, f"{tree}/var/cache/dnf")
|
||||
|
||||
cmd = [
|
||||
"dnf", "-yv",
|
||||
"--installroot", tree,
|
||||
"--setopt", "reposdir=",
|
||||
"--setopt", "keepcache=True",
|
||||
"--setopt", "install_weak_deps=False",
|
||||
"--releasever", releasever,
|
||||
"--config", dnfconfig.name,
|
||||
"install"
|
||||
] + packages
|
||||
|
||||
print(" ".join(cmd), flush=True)
|
||||
return subprocess.run(cmd).returncode
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = json.load(sys.stdin)
|
||||
sys.exit(main(**options))
|
||||
Loading…
Add table
Add a link
Reference in a new issue