Build /usr/share/truenas/sysext-extensions/functioning-dpkg.raw (#756)

This commit is contained in:
themylogin
2024-11-15 15:39:20 +01:00
committed by GitHub
parent e393bb01e4
commit a7fe3aa528

View File

@@ -5,6 +5,7 @@ import os
import textwrap
import shutil
import stat
import tempfile
from scale_build.config import SIGNING_KEY, SIGNING_PASSWORD
from scale_build.utils.manifest import get_apt_base_url, get_manifest
@@ -176,13 +177,33 @@ def custom_rootfs_setup():
shutil.rmtree(tmp_systemd)
run_in_chroot(['depmod'], check=False)
# /usr will be readonly and so we want the ca-certificates directory to
# /usr will be readonly, and so we want the ca-certificates directory to
# symlink to writeable location in /var/local
local_cacerts = os.path.join(CHROOT_BASEDIR, "usr/local/share/ca-certificates")
os.makedirs(os.path.join(CHROOT_BASEDIR, "usr/local/share"), exist_ok=True)
shutil.rmtree(local_cacerts, ignore_errors=True)
os.symlink("/var/local/ca-certificates", local_cacerts)
# Build a systemd-sysext extension that, upon loading, will make `/usr/bin/dpkg` working.
# It is necessary for `update-initramfs` to function properly.
sysext_extensions_dir = os.path.join(CHROOT_BASEDIR, "usr/share/truenas/sysext-extensions")
os.makedirs(sysext_extensions_dir, exist_ok=True)
with tempfile.TemporaryDirectory() as td:
os.makedirs(f"{td}/usr/bin")
shutil.copy2(f"{CHROOT_BASEDIR}/usr/bin/dpkg", f"{td}/usr/bin/dpkg")
os.makedirs(f"{td}/usr/local/bin")
with open(f"{td}/usr/local/bin/dpkg", "w") as f:
f.write("#!/bin/bash\n")
f.write("exec /usr/bin/dpkg \"$@\"")
os.chmod(f"{td}/usr/local/bin/dpkg", 0o755)
os.makedirs(f"{td}/usr/lib/extension-release.d")
with open(f"{td}/usr/lib/extension-release.d/extension-release.functioning-dpkg", "w") as f:
f.write("ID=_any\n")
run(["mksquashfs", td, f"{sysext_extensions_dir}/functioning-dpkg.raw"])
def clean_rootfs():
to_remove = get_manifest()['base-prune']