]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
mkosi-chroot: just run shell if no arguments are specified
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 29 Oct 2023 13:26:45 +0000 (14:26 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 29 Oct 2023 17:33:40 +0000 (18:33 +0100)
chroot(1) is documented to run "$SHELL -i" as the default command. Let's do
something similar and call "sh -i". When a user is using '--debug-shell' and one
of the scripts fails, the mkosi-chroot can be used to chroot into the image.
I think this is what users expect, based on the 'chroot' in the name.

(I don't think using $SHELL makes sense. It could either be set to 'sh', or to
something from the outside, which might not even be installed in the chroot. We
call 'sh' ourselves, so we know it must be there, so let's just call that
uncoditionally.)

mkosi/__init__.py

index 7071a8a3d309466dee1c8f247c3e77b300374933..f081d84c4e49aed88feda602dcd560255b290825 100644 (file)
@@ -342,7 +342,11 @@ 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
-                    exec {shlex.join(str(s) for s in script)} "$@"
+                    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
                     """
                 )
             )