Skip to content

Commit

Permalink
Build /usr/share/truenas/sysext-extensions/functioning-dpkg.raw (#768)
Browse files Browse the repository at this point in the history
(cherry picked from commit b5fa484)
(cherry picked from commit 37cb425)

Co-authored-by: themylogin <[email protected]>
  • Loading branch information
bugclerk and themylogin authored Nov 21, 2024
1 parent bfb38f1 commit 7d1fc7d
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion scale_build/image/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import textwrap
import shutil
import stat
import tempfile

from scale_build.config import SIGNING_KEY, SIGNING_PASSWORD
from scale_build.utils.manifest import get_manifest
Expand Down Expand Up @@ -174,13 +175,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']
Expand Down

0 comments on commit 7d1fc7d

Please sign in to comment.