From 02c95fb960ea372d57627bb5eb8b0761b48c24a6 Mon Sep 17 00:00:00 2001 From: hellodword <46193371+hellodword@users.noreply.github.com> Date: Sun, 28 Apr 2024 11:03:37 +0000 Subject: [PATCH] feat: Automatically execute script after installation (#423) --- assets/win10x64-enterprise-eval.xml | 5 +++++ assets/win10x64-iot.xml | 5 +++++ assets/win10x64-ltsc.xml | 5 +++++ assets/win10x64.xml | 5 +++++ assets/win11x64-enterprise-eval.xml | 5 +++++ assets/win11x64.xml | 5 +++++ assets/win2008r2.xml | 5 +++++ assets/win2012r2-eval.xml | 5 +++++ assets/win2016-eval.xml | 5 +++++ assets/win2019-eval.xml | 5 +++++ assets/win2022-eval.xml | 5 +++++ assets/win7x64.xml | 5 +++++ assets/win81x64-enterprise-eval.xml | 5 +++++ assets/win81x64.xml | 5 +++++ assets/winvistax64.xml | 5 +++++ readme.md | 15 ++++++++++--- src/install.sh | 33 +++++++++++++++++++++++++++++ 17 files changed, 120 insertions(+), 3 deletions(-) diff --git a/assets/win10x64-enterprise-eval.xml b/assets/win10x64-enterprise-eval.xml index 19224d9..80183d9 100644 --- a/assets/win10x64-enterprise-eval.xml +++ b/assets/win10x64-enterprise-eval.xml @@ -462,6 +462,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 23 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win10x64-iot.xml b/assets/win10x64-iot.xml index 66d69a9..27b5ca1 100644 --- a/assets/win10x64-iot.xml +++ b/assets/win10x64-iot.xml @@ -470,6 +470,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 23 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win10x64-ltsc.xml b/assets/win10x64-ltsc.xml index 6c8836d..74417a4 100644 --- a/assets/win10x64-ltsc.xml +++ b/assets/win10x64-ltsc.xml @@ -468,6 +468,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 23 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win10x64.xml b/assets/win10x64.xml index 7af05c5..4dacfab 100644 --- a/assets/win10x64.xml +++ b/assets/win10x64.xml @@ -464,6 +464,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 23 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win11x64-enterprise-eval.xml b/assets/win11x64-enterprise-eval.xml index 0df076d..987e2d4 100644 --- a/assets/win11x64-enterprise-eval.xml +++ b/assets/win11x64-enterprise-eval.xml @@ -485,6 +485,11 @@ reg.exe add "HKCU\Control Panel\UnsupportedHardwareNotificationCache" /v SV2 /d 0 /t REG_DWORD /f Disable unsupported hardware notifications + + 24 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win11x64.xml b/assets/win11x64.xml index 05d8118..e773e54 100644 --- a/assets/win11x64.xml +++ b/assets/win11x64.xml @@ -487,6 +487,11 @@ reg.exe add "HKCU\Control Panel\UnsupportedHardwareNotificationCache" /v SV2 /d 0 /t REG_DWORD /f Disable unsupported hardware notifications + + 24 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win2008r2.xml b/assets/win2008r2.xml index 0a4f267..4903645 100644 --- a/assets/win2008r2.xml +++ b/assets/win2008r2.xml @@ -302,6 +302,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 17 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win2012r2-eval.xml b/assets/win2012r2-eval.xml index 5d5df8d..00a5e3c 100644 --- a/assets/win2012r2-eval.xml +++ b/assets/win2012r2-eval.xml @@ -341,6 +341,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 17 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win2016-eval.xml b/assets/win2016-eval.xml index 6be15ac..981b766 100644 --- a/assets/win2016-eval.xml +++ b/assets/win2016-eval.xml @@ -371,6 +371,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 23 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win2019-eval.xml b/assets/win2019-eval.xml index 831d1d1..2f9b304 100644 --- a/assets/win2019-eval.xml +++ b/assets/win2019-eval.xml @@ -375,6 +375,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 23 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win2022-eval.xml b/assets/win2022-eval.xml index afeda33..badd14c 100644 --- a/assets/win2022-eval.xml +++ b/assets/win2022-eval.xml @@ -375,6 +375,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 23 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win7x64.xml b/assets/win7x64.xml index 944c520..e0ae7e0 100644 --- a/assets/win7x64.xml +++ b/assets/win7x64.xml @@ -305,6 +305,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 17 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win81x64-enterprise-eval.xml b/assets/win81x64-enterprise-eval.xml index 76ba9bb..b6c9e95 100644 --- a/assets/win81x64-enterprise-eval.xml +++ b/assets/win81x64-enterprise-eval.xml @@ -326,6 +326,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 17 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/win81x64.xml b/assets/win81x64.xml index 3ac7963..19ea568 100644 --- a/assets/win81x64.xml +++ b/assets/win81x64.xml @@ -335,6 +335,11 @@ netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes Enable File Sharing + + 17 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/assets/winvistax64.xml b/assets/winvistax64.xml index 22739a1..b613f6f 100644 --- a/assets/winvistax64.xml +++ b/assets/winvistax64.xml @@ -259,6 +259,11 @@ reg.exe add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\Terminal Services" /v "fAllowUnlistedRemotePrograms" /t REG_DWORD /d 1 /f Enable RemoteAPP to launch unlisted programs + + 20 + cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat" + Execute custom script from the OEM folder if exists + diff --git a/readme.md b/readme.md index 1e4c45d..b12e1de 100644 --- a/readme.md +++ b/readme.md @@ -168,9 +168,7 @@ docker run -it --rm --name windows -p 8006:8006 --device=/dev/kvm --cap-add NET_ * ### How do I customize the installation? - You can customize any part of the automatic installation, and even execute certain commands at boot if needed. - - Download the XML file corresponding to your Windows version, for example [win11x64.xml](https://raw.githubusercontent.com/dockur/windows/master/assets/win11x64.xml). Then apply your modifications to it, and add this line to your compose file: + You can customize every setting used by the automatic installation. Download the XML file corresponding to your Windows version, for example [win11x64.xml](https://raw.githubusercontent.com/dockur/windows/master/assets/win11x64.xml). Then apply your modifications to it, and add this line to your compose file: ```yaml volumes: @@ -179,6 +177,17 @@ docker run -it --rm --name windows -p 8006:8006 --device=/dev/kvm --cap-add NET_ Replace the example path `/home/user/custom.xml` with the filename of the modified XML file. +* ### How do I run a script after installation? + + To run your own script after installation, you can create a file called `install.bat` and place it in a folder together with other files it needs (programs to install for example). Then bind it in your compose file like this: + + ```yaml + volumes: + - /home/user/example:/storage/oem + ``` + + The example path `/home/user/example` will be copied to `C:\OEM` during installation and the containing `install.bat` will be executed. + * ### How do I perform a manual installation? It's best to use the automatic installation, as it optimizes various settings for use with this container. These tweaks will give you maximum performance and prevent common issues. diff --git a/src/install.sh b/src/install.sh index 417e4ef..dcf0a82 100644 --- a/src/install.sh +++ b/src/install.sh @@ -1082,6 +1082,35 @@ updateImage() { return 0 } +copyOEM() { + local dir="$1" + local folder="$STORAGE/oem" + local src + + [ ! -d "$folder" ] && folder="$STORAGE/OEM" + [ ! -d "$folder" ] && folder="$STORAGE/shared/oem" + [ ! -d "$folder" ] && folder="$STORAGE/shared/OEM" + [ ! -d "$folder" ] && return 0 + + local msg="Copying OEM folder to image..." + info "$msg" && html "$msg" + + src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1) + + if [ ! -d "$src" ]; then + error "failed to locate 'sources' folder in ISO image!" && return 1 + fi + + local dest="$src/\$OEM\$/\$1/" + mkdir -p "$dest" + + if ! cp -r "$folder" "$dest"; then + error "Failed to copy OEM folder!" && return 1 + fi + + return 0 +} + buildImage() { local dir="$1" @@ -1242,6 +1271,10 @@ if ! rm -f "$ISO" 2> /dev/null; then rm -f "$ISO" fi +if ! copyOEM "$DIR"; then + exit 63 +fi + if ! buildImage "$DIR"; then exit 65 fi