From 9409c06e326ad00dd99fca77d4caf0abeeabde93 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 19 Jul 2026 00:33:00 +0200 Subject: [PATCH] feat: Add post-install command support (#1887) --- docs/environment.md | 5 +++-- readme.md | 17 ++++++++++++----- src/define.sh | 28 ++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/docs/environment.md b/docs/environment.md index d2a669f4..0778dd6d 100644 --- a/docs/environment.md +++ b/docs/environment.md @@ -17,7 +17,6 @@ An empty default means the variable is unset and its value is determined automat | `PASSWORD` | `admin` | Password for the Windows account. | | `DOMAIN` | | Active Directory domain to join during installation. | | `KEY` | | Windows product key used to install and activate Windows. | -| `MANUAL` | `N` | Enables manual installation instead of unattended installation. | ## 🧠 CPU and Memory @@ -146,7 +145,7 @@ Also see [Dynamic memory allocation](https://github.com/qemus/qemu/blob/master/d | `BALLOONING_INTERVAL` | `5` | Polling interval in seconds. | | `BALLOONING_DEBUG` | `N` | Enables debug output for the ballooning monitor. | -## 💿 Installation Media +## 💿 Installation | Variable | Default | Description | |---|---|---| @@ -154,6 +153,8 @@ Also see [Dynamic memory allocation](https://github.com/qemus/qemu/blob/master/d | `ESD` | `Y` | Enables downloading Windows through the ESD-based installation method. | | `VERIFY` | `N` | Verifies downloaded installation media against predefined checksums. | | `REMOVE` | `Y` | Deletes the downloaded Windows ISO after installation to save space. | +| `MANUAL` | `N` | Enables manual installation instead of unattended installation. | +| `COMMAND` | | Command to be executed during the final step of automatic installation. | ## 🔌 Shutdown diff --git a/readme.md b/readme.md index 33bdf02d..ba421fff 100644 --- a/readme.md +++ b/readme.md @@ -272,18 +272,25 @@ kubectl apply -f https://raw.githubusercontent.com/dockur/windows/refs/heads/mas Replace the example path `./example.iso` with the filename of your desired ISO file. The value of `VERSION` will be ignored in this case. -### How do I run a script after installation? +### How do I run a command after installation? + + To execute a single command during the final step of the automatic installation, add the `COMMAND` environment variable: + + ```yaml + environment: + COMMAND: 'reg add "HKLM\Software\Example" /v Enabled /t REG_DWORD /d 1 /f' + ``` + + To run a script or include additional files, create a file called `install.bat` and place it in a folder together with any files it needs, such as software to be installed. - To run your own script after installation, you can create a file called `install.bat` and place it in a folder together with any additional files it needs (software to be installed for example). - Then bind that folder in your compose file like this: ```yaml volumes: - - ./example:/oem + - ./example:/oem ``` - The example folder `./example` will be copied to `C:\OEM` and the `install.bat` file inside that folder will be executed during the last step of the automatic installation. + The example folder `./example` will be copied to `C:\OEM` and the `install.bat` file inside it will be executed during the final step of the automatic installation. ### How do I perform a manual installation? diff --git a/src/define.sh b/src/define.sh index f60a4b11..4b369a04 100644 --- a/src/define.sh +++ b/src/define.sh @@ -1347,23 +1347,39 @@ validVersion() { addFolder() { local src="$1" - local folder="/oem" + local folder="/oem" file="" + local dest="$src/\$OEM\$/\$1/OEM" [ ! -d "$folder" ] && folder="/OEM" [ ! -d "$folder" ] && folder="$STORAGE/oem" [ ! -d "$folder" ] && folder="$STORAGE/OEM" - [ ! -d "$folder" ] && return 0 + [ ! -d "$folder" ] && folder="" - local msg="Adding OEM folder to image..." + [ -z "$folder" ] && [ -z "$COMMAND" ] && return 0 + + local msg="Adding OEM files to image..." info "$msg" && html "$msg" - local dest="$src/\$OEM\$/\$1/OEM" mkdir -p "$dest" || return 1 - cp -Lr "$folder/." "$dest" || return 1 - local file + if [ -n "$folder" ]; then + cp -Lr "$folder/." "$dest" || return 1 + fi + file=$(find "$dest" -maxdepth 1 -type f -iname install.bat -print -quit) || return 1 + if [ -n "$COMMAND" ]; then + + [ -z "$file" ] && file="$dest/install.bat" + + if [ -s "$file" ]; then + printf '\n' >> "$file" || return 1 + fi + + printf '%s\n' "$COMMAND" >> "$file" || return 1 + + fi + if [ -f "$file" ]; then if ! unix2dos -q "$file"; then error "Failed to convert $file to DOS format!"