Add pre-boot hook support

This commit is contained in:
randogoth 2025-10-19 12:47:08 +03:00
parent 8cc9294dd4
commit a29f17dabb
2 changed files with 35 additions and 0 deletions

View file

@ -74,6 +74,7 @@ All persistent user data inside the guest lives under `/home/dosuser/.dosemu`, w
- **`allowed_repo/` volume** drop files here on the host; they are copied into C:\ during login. - **`allowed_repo/` volume** drop files here on the host; they are copied into C:\ during login.
- **`config/dos_allowed`** list relative paths (from `allowed_repo/`) to permit when `DOS_ALLOW_MODE=list`. With `DOS_ALLOW_MODE=all` every file in the repo is staged. - **`config/dos_allowed`** list relative paths (from `allowed_repo/`) to permit when `DOS_ALLOW_MODE=list`. With `DOS_ALLOW_MODE=all` every file in the repo is staged.
- **`dos_env/` templates** place `AUTOEXEC.BAT` and/or `CONFIG.SYS` to control boot scripts. - **`dos_env/` templates** place `AUTOEXEC.BAT` and/or `CONFIG.SYS` to control boot scripts.
- **Pre-boot hook** create an executable `dos_env/pre-boot.sh` (or point `DOS_PRE_BOOT_HOOK` at another path). It runs as `dosuser` immediately before dosemu starts, with helper environment variables (`C_DRIVE`, `DOSEMU_DIR`, `ALLOWED_REPO`, `SVARDOS_ROOT`, `SVARDOS_BASE`) so you can copy, delete, or patch files on the DOS drive.
- **Forcing a reinstall** set `DOS_FORCE_INSTALL=1` in the environment before logging in; the script re-seeds the drive from `/opt/svardos/base`. - **Forcing a reinstall** set `DOS_FORCE_INSTALL=1` in the environment before logging in; the script re-seeds the drive from `/opt/svardos/base`.
Typical layout when using `docker compose`: Typical layout when using `docker compose`:
@ -101,6 +102,7 @@ You can influence runtime behaviour with environment variables. Set them either
| `DOS_FORCE_INSTALL` | `0` (default) or `1` | Rebuilds the C: drive from the SvarDOS base on the next login. | | `DOS_FORCE_INSTALL` | `0` (default) or `1` | Rebuilds the C: drive from the SvarDOS base on the next login. |
| `DOS_TERMINAL_MODE` | `auto` | Determines whether `dosemu` launches with X11 (`-X`), terminal (`-td`) or `-dumb`. | | `DOS_TERMINAL_MODE` | `auto` | Determines whether `dosemu` launches with X11 (`-X`), terminal (`-td`) or `-dumb`. |
| `DOS_ENV_DIR` | defaults to `/etc/dos_env` | Override if you mount templates somewhere else. | | `DOS_ENV_DIR` | defaults to `/etc/dos_env` | Override if you mount templates somewhere else. |
| `DOS_PRE_BOOT_HOOK` | `${DOS_ENV_DIR}/pre-boot.sh` | Custom shell script to run (as `dosuser`) before launching dosemu. Must be executable. |
| `SVARDOS_ROOT`/`SVARDOS_BASE` | default `/opt/svardos` | Changes where the base image lives (mostly useful during debugging). | | `SVARDOS_ROOT`/`SVARDOS_BASE` | default `/opt/svardos` | Changes where the base image lives (mostly useful during debugging). |
| `AO_DRIVER` | auto-set to `null` when sound is muted | You can override to force libao to a specific backend. | | `AO_DRIVER` | auto-set to `null` when sound is muted | You can override to force libao to a specific backend. |

View file

@ -14,6 +14,7 @@ SVARDOS_BASE="${SVARDOS_BASE:-${SVARDOS_ROOT}/base}"
ALLOW_MODE="${DOS_ALLOW_MODE:-all}" 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}"
if [ "$(id -u)" -eq 0 ]; then if [ "$(id -u)" -eq 0 ]; then
DOS_USER="${DEFAULT_DOS_USER}" DOS_USER="${DEFAULT_DOS_USER}"
@ -137,6 +138,37 @@ apply_templates() {
detect_dosemu_args detect_dosemu_args
run_pre_boot_hook() {
if [ ! -e "${PRE_BOOT_HOOK}" ]; then
return
fi
if [ ! -x "${PRE_BOOT_HOOK}" ]; then
echo "dos-shell: pre-boot hook found but not executable: ${PRE_BOOT_HOOK}" >&2
return
fi
echo "dos-shell: running pre-boot hook: ${PRE_BOOT_HOOK}" >&2
if [ "$(id -u)" -eq 0 ]; then
runuser -u "${DOS_USER}" -- env \
C_DRIVE="${C_DRIVE}" \
DOSEMU_DIR="${DOSEMU_DIR}" \
DOS_HOME="${DOS_HOME}" \
ALLOWED_REPO="${ALLOWED_REPO}" \
SVARDOS_ROOT="${SVARDOS_ROOT}" \
SVARDOS_BASE="${SVARDOS_BASE}" \
"${PRE_BOOT_HOOK}"
else
C_DRIVE="${C_DRIVE}" \
DOSEMU_DIR="${DOSEMU_DIR}" \
DOS_HOME="${DOS_HOME}" \
ALLOWED_REPO="${ALLOWED_REPO}" \
SVARDOS_ROOT="${SVARDOS_ROOT}" \
SVARDOS_BASE="${SVARDOS_BASE}" \
"${PRE_BOOT_HOOK}"
fi
}
FORCE_CPU_EMULATION=0 FORCE_CPU_EMULATION=0
detect_kvm_support() { detect_kvm_support() {
if [ ! -c /dev/kvm ]; then if [ ! -c /dev/kvm ]; then
@ -281,6 +313,7 @@ fi
sync_allowed_content sync_allowed_content
apply_templates apply_templates
run_pre_boot_hook
write_autoconfig write_autoconfig
if [ "$(id -u)" -eq 0 ]; then if [ "$(id -u)" -eq 0 ]; then