Skip to content

Commit 5768ae5

Browse files
authored
feat: Automatically execute script after installation (#94)
1 parent 210efeb commit 5768ae5

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

assets/win10arm64.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@
464464
<CommandLine>netsh advfirewall firewall set rule group="File and Printer Sharing" new enable=Yes</CommandLine>
465465
<Description>Enable File Sharing</Description>
466466
</SynchronousCommand>
467+
<SynchronousCommand wcm:action="add">
468+
<Order>23</Order>
469+
<CommandLine>cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat"</CommandLine>
470+
<Description>Execute custom script from the OEM folder if exists</Description>
471+
</SynchronousCommand>
467472
</FirstLogonCommands>
468473
</component>
469474
</settings>

assets/win11arm64.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,11 @@
488488
<CommandLine>reg.exe add "HKCU\Control Panel\UnsupportedHardwareNotificationCache" /v SV2 /d 0 /t REG_DWORD /f</CommandLine>
489489
<Description>Disable unsupported hardware notifications</Description>
490490
</SynchronousCommand>
491+
<SynchronousCommand wcm:action="add">
492+
<Order>24</Order>
493+
<CommandLine>cmd /C if exist "C:\OEM\install.bat" start "Install" "cmd /C C:\OEM\install.bat"</CommandLine>
494+
<Description>Execute custom script from the OEM folder if exists</Description>
495+
</SynchronousCommand>
491496
</FirstLogonCommands>
492497
</component>
493498
</settings>

readme.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ docker run -it --rm --name windows -p 8006:8006 --device=/dev/kvm --cap-add NET_
155155

156156
* ### How do I customize the installation?
157157

158-
You can customize any part of the automatic installation, and even execute certain commands at boot if needed.
159-
160-
Download the XML file corresponding to your Windows version, for example [win11arm64.xml](https://raw.githubusercontent.com/dockur/windows-arm/master/assets/win11arm64.xml). Then apply your modifications to it, and add this line to your compose file:
158+
You can customize every setting used by the automatic installation. Download the XML file corresponding to your Windows version, for example [win11arm64.xml](https://raw.githubusercontent.com/dockur/windows/master/assets/win11arm64.xml). Then apply your modifications to it, and add this line to your compose file:
161159

162160
```yaml
163161
volumes:
@@ -166,6 +164,17 @@ docker run -it --rm --name windows -p 8006:8006 --device=/dev/kvm --cap-add NET_
166164

167165
Replace the example path `/home/user/custom.xml` with the filename of the modified XML file.
168166

167+
* ### How do I run a script after installation?
168+
169+
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:
170+
171+
```yaml
172+
volumes:
173+
- /home/user/example:/storage/oem
174+
```
175+
176+
The example path `/home/user/example` will be copied to `C:\OEM` during installation and the containing `install.bat` will be executed.
177+
169178
* ### How do I assign an individual IP address to the container?
170179

171180
By default, the container uses bridge networking, which shares the IP address with the host.

src/install.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,35 @@ updateImage() {
638638
return 0
639639
}
640640

641+
copyOEM() {
642+
local dir="$1"
643+
local folder="$STORAGE/oem"
644+
local src
645+
646+
[ ! -d "$folder" ] && folder="$STORAGE/OEM"
647+
[ ! -d "$folder" ] && folder="$STORAGE/shared/oem"
648+
[ ! -d "$folder" ] && folder="$STORAGE/shared/OEM"
649+
[ ! -d "$folder" ] && return 0
650+
651+
local msg="Copying OEM folder to image..."
652+
info "$msg" && html "$msg"
653+
654+
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
655+
656+
if [ ! -d "$src" ]; then
657+
error "failed to locate 'sources' folder in ISO image!" && return 1
658+
fi
659+
660+
local dest="$src/\$OEM\$/\$1/"
661+
mkdir -p "$dest"
662+
663+
if ! cp -r "$folder" "$dest"; then
664+
error "Failed to copy OEM folder!" && return 1
665+
fi
666+
667+
return 0
668+
}
669+
641670
buildImage() {
642671

643672
local dir="$1"
@@ -736,6 +765,10 @@ if ! rm -f "$ISO" 2> /dev/null; then
736765
rm -f "$ISO"
737766
fi
738767

768+
if ! copyOEM "$DIR"; then
769+
exit 63
770+
fi
771+
739772
if ! buildImage "$DIR"; then
740773
exit 65
741774
fi

0 commit comments

Comments
 (0)