Work around a bug on aarch64[1] where `qemu-img` would hang about a third of the time when converting images. To be able to activate the work-around based on the environment, i.e. only on certain distributions, introduce an environment variable, `OSBUILD_QEMU_IMG_COROUTINES`, that is set in the runner and then picked up in the assembler. [1] https://bugs.launchpad.net/qemu/+bug/1805256
83 lines
2.2 KiB
Text
Executable file
83 lines
2.2 KiB
Text
Executable file
#!/usr/libexec/platform-python
|
|
|
|
import os
|
|
import platform
|
|
import subprocess
|
|
import sys
|
|
|
|
import osbuild.api
|
|
|
|
|
|
def quirks():
|
|
# Platform specific quirks
|
|
env = os.environ.copy()
|
|
|
|
if platform.machine() == "aarch64":
|
|
# Work around a bug in qemu-img on aarch64 that can lead to qemu-img
|
|
# hangs when more then one coroutine is use (which is the default)
|
|
# See https://bugs.launchpad.net/qemu/+bug/1805256
|
|
env["OSBUILD_QEMU_IMG_COROUTINES"] = "1"
|
|
|
|
return env
|
|
|
|
|
|
def ldconfig():
|
|
# ld.so.conf must exist, or `ldconfig` throws a warning
|
|
subprocess.run(["touch", "/etc/ld.so.conf"], check=True)
|
|
subprocess.run(["ldconfig"], check=True)
|
|
|
|
|
|
def sysusers():
|
|
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)
|
|
|
|
|
|
def tmpfiles():
|
|
# 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"], check=False)
|
|
|
|
|
|
def nsswitch():
|
|
# the default behavior is fine, but using nss-resolve does not
|
|
# necessarily work in a non-booted container, so make sure that
|
|
# is not configured.
|
|
try:
|
|
os.remove("/etc/nsswitch.conf")
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
|
|
def python_alternatives():
|
|
"""/usr/bin/python3 is a symlink to /etc/alternatives/python3, which points
|
|
to /usr/bin/python3.6 by default. Recreate the link in /etc, so that
|
|
shebang lines in stages and assemblers work.
|
|
"""
|
|
os.makedirs("/etc/alternatives", exist_ok=True)
|
|
try:
|
|
os.symlink("/usr/bin/python3.6", "/etc/alternatives/python3")
|
|
except FileExistsError:
|
|
pass
|
|
|
|
|
|
def main():
|
|
with osbuild.api.exception_handler():
|
|
ldconfig()
|
|
sysusers()
|
|
tmpfiles()
|
|
nsswitch()
|
|
python_alternatives()
|
|
|
|
env = quirks()
|
|
|
|
r = subprocess.run(sys.argv[1:],
|
|
env=env,
|
|
check=False)
|
|
sys.exit(r.returncode)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|