From: Daan De Meyer Date: Mon, 19 Feb 2024 09:22:29 +0000 (+0100) Subject: Move interactive shell logic for mkosi-chroot into chroot_cmd() X-Git-Tag: v21~44^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=538ebd602a6c9ce88b891bb7904c7a1334b1bf90;p=thirdparty%2Fmkosi.git Move interactive shell logic for mkosi-chroot into chroot_cmd() Currently the logic applies to all scripts which does the wrong thing except for mkosi-chroot. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index cd0d93379..7a227a1eb 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -363,11 +363,7 @@ def finalize_scripts(scripts: Mapping[str, Sequence[PathString]] = {}) -> Iterat DIR="$(cd "$(dirname "$0")" && pwd)" PATH="$(echo "$PATH" | tr ':' '\\n' | grep -v "$DIR" | tr '\\n' ':')" export PATH - if [ $# -gt 0 ]; then - exec {shlex.join(str(s) for s in script)} "$@" - else - exec {shlex.join(str(s) for s in script)} sh -i - fi + exec {shlex.join(str(s) for s in script)} "$@" """ ) ) diff --git a/mkosi/sandbox.py b/mkosi/sandbox.py index d95807dd8..b94a4f8f2 100644 --- a/mkosi/sandbox.py +++ b/mkosi/sandbox.py @@ -211,7 +211,7 @@ def apivfs_cmd(root: Path) -> list[PathString]: def chroot_cmd(root: Path, *, resolve: bool = False, options: Sequence[PathString] = ()) -> list[PathString]: - cmdline: list[PathString] = [ + return apivfs_cmd(root) + [ "sh", "-c", f"trap 'rm -rf {root / 'work'}' EXIT && " # /etc/resolv.conf can be a dangling symlink to /run/systemd/resolve/stub-resolv.conf. Bubblewrap tries to call @@ -226,11 +226,9 @@ def chroot_cmd(root: Path, *, resolve: bool = False, options: Sequence[PathStrin "--setenv", "container", "mkosi", "--setenv", "HOME", "/", "--setenv", "PATH", "/work/scripts:/usr/bin:/usr/sbin", + *(["--ro-bind-try", "/etc/resolv.conf", "/etc/resolv.conf"] if resolve else []), + *options, + # Start an interactive bash shell if we're not given any arguments. + "sh", "-c", '[ "$0" = "sh" ] && [ $# -eq 0 ] && exec bash -i || exec $0 "$@"', ] - if resolve: - cmdline += ["--ro-bind-try", "/etc/resolv.conf", "/etc/resolv.conf"] - - cmdline += options - - return apivfs_cmd(root) + cmdline