From a29f17dabb13279dad9f50c1f876858840bcb0f8 Mon Sep 17 00:00:00 2001 From: randogoth Date: Sun, 19 Oct 2025 12:47:08 +0300 Subject: [PATCH] Add pre-boot hook support --- README.md | 2 ++ scripts/dos-shell | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/README.md b/README.md index a32c9e6..033fd60 100644 --- a/README.md +++ b/README.md @@ -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. - **`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. +- **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`. 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_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_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). | | `AO_DRIVER` | auto-set to `null` when sound is muted | You can override to force libao to a specific backend. | diff --git a/scripts/dos-shell b/scripts/dos-shell index 6da79c5..f6d1865 100755 --- a/scripts/dos-shell +++ b/scripts/dos-shell @@ -14,6 +14,7 @@ SVARDOS_BASE="${SVARDOS_BASE:-${SVARDOS_ROOT}/base}" 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}" if [ "$(id -u)" -eq 0 ]; then DOS_USER="${DEFAULT_DOS_USER}" @@ -137,6 +138,37 @@ apply_templates() { 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 detect_kvm_support() { if [ ! -c /dev/kvm ]; then @@ -281,6 +313,7 @@ fi sync_allowed_content apply_templates +run_pre_boot_hook write_autoconfig if [ "$(id -u)" -eq 0 ]; then