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)} "$@"
"""
)
)
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
"--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