diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c036379 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tmp/ \ No newline at end of file diff --git a/README.md b/README.md index 033fd60..c50fcef 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,17 @@ You can influence runtime behaviour with environment variables. Set them either `dos-shell` also writes a managed `~/.dosemu/dosemurc` (marked with `# Managed by dos-shell…`) when it needs to enforce CPU or audio fallbacks. Delete the file to restore defaults; it is regenerated on demand. +### Podman / Docker exec entrypoints + +`dos-shell` remains the default login shell for `dosuser`, so a plain `podman exec -it dos-env dos-shell` (or `docker exec`) drops you straight into the DOS session. When you need a regular Linux shell in the same running container, reuse the wrapper but append `--linux-shell`: + +```sh +podman exec -it dos-env dos-shell --linux-shell # interactive bash as dosuser +podman exec -it dos-env dos-shell --linux-shell "ls" # run a single command as dosuser +``` + +You can override which binary is used for the Linux side by setting `DOS_LINUX_SHELL` (defaults to `/bin/bash`). + ## Environment Variables (Container / Compose) `compose.yml` exposes a few knobs. You can drop a `.env` file next to it to override the defaults. diff --git a/scripts/dos-shell b/scripts/dos-shell index f6d1865..6e41201 100755 --- a/scripts/dos-shell +++ b/scripts/dos-shell @@ -15,6 +15,7 @@ ALLOW_MODE="${DOS_ALLOW_MODE:-all}" DEFAULT_DOS_USER="dosuser" INSTALL_SENTINEL_NAME=".svardos_installed" PRE_BOOT_HOOK="${DOS_PRE_BOOT_HOOK:-${ENV_DIR}/pre-boot.sh}" +LINUX_SHELL="${DOS_LINUX_SHELL:-/bin/bash}" if [ "$(id -u)" -eq 0 ]; then DOS_USER="${DEFAULT_DOS_USER}" @@ -29,6 +30,57 @@ if [ -z "${DOS_HOME}" ]; then exit 1 fi +shell_passthrough=0 +shell_payload="" + +if [ "${1:-}" = "--help" ]; then + cat <<'EOF' +Usage: dos-shell [--linux-shell [command]] + +Default invocation boots the DOS environment via dosemu. +Use --linux-shell to open the underlying Linux shell instead. +EOF + exit 0 +fi + +if [ "${1:-}" = "--linux-shell" ]; then + shift + shell_passthrough=1 + if [ $# -gt 0 ]; then + shell_payload="$*" + fi +fi + +if [ "${shell_passthrough}" -eq 0 ] && [ -n "${SSH_ORIGINAL_COMMAND:-}" ]; then + case "${SSH_ORIGINAL_COMMAND}" in + linux-shell) + shell_passthrough=1 + shell_payload="" + ;; + linux-shell[[:space:]]*) + shell_passthrough=1 + shell_payload="${SSH_ORIGINAL_COMMAND#linux-shell}" + shell_payload="${shell_payload#"${shell_payload%%[![:space:]]*}"}" + ;; + esac +fi + +if [ "${shell_passthrough}" -eq 1 ]; then + if [ "$(id -u)" -eq 0 ]; then + if [ -n "${shell_payload}" ]; then + exec runuser -u "${DOS_USER}" -- "${LINUX_SHELL}" -lc "${shell_payload}" + else + exec runuser -u "${DOS_USER}" -- "${LINUX_SHELL}" -l + fi + else + if [ -n "${shell_payload}" ]; then + exec "${LINUX_SHELL}" -lc "${shell_payload}" + else + exec "${LINUX_SHELL}" -l + fi + fi +fi + DOSEMU_DIR="${DOS_HOME}/.dosemu" C_DRIVE="${DOSEMU_DIR}/drive_c" INSTALL_SENTINEL_PATH="${DOSEMU_DIR}/${INSTALL_SENTINEL_NAME}"