]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Move interactive shell logic for mkosi-chroot into chroot_cmd()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 19 Feb 2024 09:22:29 +0000 (10:22 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 19 Feb 2024 14:39:50 +0000 (15:39 +0100)
Currently the logic applies to all scripts which does the wrong thing
except for mkosi-chroot.

mkosi/__init__.py
mkosi/sandbox.py

index cd0d9337924ac4e799c18f09e6c538e75a77cdb2..7a227a1eb7e4b4922b88a8cf05335058fa94345e 100644 (file)
@@ -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)} "$@"
                     """
                 )
             )
index d95807dd897c005350c06f47b47cc8f6e3468ea5..b94a4f8f239957e7b323367df059e024f1fed693 100644 (file)
@@ -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