DOS/Linux shell

This commit is contained in:
randogoth 2025-10-19 16:55:18 +03:00
parent a29f17dabb
commit 442ea5008b
3 changed files with 64 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
tmp/

View file

@ -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. `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) ## Environment Variables (Container / Compose)
`compose.yml` exposes a few knobs. You can drop a `.env` file next to it to override the defaults. `compose.yml` exposes a few knobs. You can drop a `.env` file next to it to override the defaults.

View file

@ -15,6 +15,7 @@ ALLOW_MODE="${DOS_ALLOW_MODE:-all}"
DEFAULT_DOS_USER="dosuser" DEFAULT_DOS_USER="dosuser"
INSTALL_SENTINEL_NAME=".svardos_installed" INSTALL_SENTINEL_NAME=".svardos_installed"
PRE_BOOT_HOOK="${DOS_PRE_BOOT_HOOK:-${ENV_DIR}/pre-boot.sh}" 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 if [ "$(id -u)" -eq 0 ]; then
DOS_USER="${DEFAULT_DOS_USER}" DOS_USER="${DEFAULT_DOS_USER}"
@ -29,6 +30,57 @@ if [ -z "${DOS_HOME}" ]; then
exit 1 exit 1
fi 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" DOSEMU_DIR="${DOS_HOME}/.dosemu"
C_DRIVE="${DOSEMU_DIR}/drive_c" C_DRIVE="${DOSEMU_DIR}/drive_c"
INSTALL_SENTINEL_PATH="${DOSEMU_DIR}/${INSTALL_SENTINEL_NAME}" INSTALL_SENTINEL_PATH="${DOSEMU_DIR}/${INSTALL_SENTINEL_NAME}"