feat: Allow product key configuration (#1110)

This commit is contained in:
Kroese 2025-03-13 12:55:36 +01:00 committed by GitHub
parent b465f78646
commit 5ab42e9409
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 59 deletions

View File

@ -178,7 +178,7 @@ kubectl apply -f https://raw.githubusercontent.com/dockur/windows/refs/heads/mas
By default, a user called `Docker` (with an empty password) is created during installation. By default, a user called `Docker` (with an empty password) is created during installation.
If you want to use different credentials, you can configure them (only BEFORE installation) in your compose file: If you want to use different credentials, you can configure them in your compose file (only before installation):
```yaml ```yaml
environment: environment:
@ -201,13 +201,23 @@ kubectl apply -f https://raw.githubusercontent.com/dockur/windows/refs/heads/mas
### How do I select the keyboard layout? ### How do I select the keyboard layout?
If you want to use a keyboard layout or locale that is not the default for your selected language, before installation you can add `KEYBOARD` and `REGION` variables like this: If you want to use a keyboard layout or locale that is not the default for your selected language, you can add `KEYBOARD` and `REGION` variables like this (before installation):
```yaml ```yaml
environment: environment:
REGION: "en-US" REGION: "en-US"
KEYBOARD: "en-US" KEYBOARD: "en-US"
``` ```
### How do I set the product key?
By default, an evaluation version of Windows will be installed, but if you have product key you can add a `KEY` variable like this (before installation):
```yaml
environment:
KEY: "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"
```
### How do I install a custom image? ### How do I install a custom image?
In order to download an unsupported ISO image, specify its URL in the `VERSION` environment variable: In order to download an unsupported ISO image, specify its URL in the `VERSION` environment variable:

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -Eeuo pipefail set -Eeuo pipefail
: "${KEY:=""}"
: "${WIDTH:=""}" : "${WIDTH:=""}"
: "${HEIGHT:=""}" : "${HEIGHT:=""}"
: "${VERIFY:=""}" : "${VERIFY:=""}"
@ -1175,9 +1176,7 @@ prepareInstall() {
local dir="$2" local dir="$2"
local desc="$3" local desc="$3"
local arch="$4" local driver="$4"
local key="$5"
local driver="$6"
local drivers="/tmp/drivers" local drivers="/tmp/drivers"
rm -rf "$drivers" rm -rf "$drivers"
@ -1196,7 +1195,8 @@ prepareInstall() {
error "Failed to extract drivers!" && return 1 error "Failed to extract drivers!" && return 1
fi fi
local target local arch target
[ -d "$dir/AMD64" ] && arch="amd64" || arch="x86"
[[ "${arch,,}" == "x86" ]] && target="$dir/I386" || target="$dir/AMD64" [[ "${arch,,}" == "x86" ]] && target="$dir/I386" || target="$dir/AMD64"
if [ ! -f "$drivers/viostor/$driver/$arch/viostor.sys" ]; then if [ ! -f "$drivers/viostor/$driver/$arch/viostor.sys" ]; then
@ -1282,6 +1282,24 @@ prepareInstall() {
[ -n "$PASSWORD" ] && password="$PASSWORD" [ -n "$PASSWORD" ] && password="$PASSWORD"
[ -n "$USERNAME" ] && username=$(echo "$USERNAME" | sed 's/[^[:alnum:]@!._-]//g') [ -n "$USERNAME" ] && username=$(echo "$USERNAME" | sed 's/[^[:alnum:]@!._-]//g')
if [[ "${driver,,}" == "xp" ]]; then
if [[ "${arch,,}" == "x86" ]]; then
# Windows XP Professional x86 generic key (no activation, trial-only)
[ -z "$KEY" ] && KEY="DR8GV-C8V6J-BYXHG-7PYJR-DB66Y"
else
# Windows XP Professional x64 generic key (no activation, trial-only)
[ -z "$KEY" ] && KEY="B2RBK-7KPT9-4JP6X-QQFWM-PJD6G"
fi
else
if [[ "${arch,,}" == "x86" ]]; then
# Windows Server 2003 Standard x86 generic key (no activation, trial-only)
[ -z "$KEY" ] && KEY="QKDCQ-TP2JM-G4MDG-VR6F2-P9C48"
else
# Windows Server 2003 Standard x64 generic key (no activation, trial-only)
[ -z "$KEY" ] && KEY="P4WJG-WK3W7-3HM8W-RWHCK-8JTRY"
fi
fi
find "$target" -maxdepth 1 -type f -iname winnt.sif -exec rm {} \; find "$target" -maxdepth 1 -type f -iname winnt.sif -exec rm {} \;
{ echo "[Data]" { echo "[Data]"
@ -1319,7 +1337,7 @@ prepareInstall() {
echo " FullName=\"$username\"" echo " FullName=\"$username\""
echo " ComputerName=\"*\"" echo " ComputerName=\"*\""
echo " OrgName=\"Windows for Docker\"" echo " OrgName=\"Windows for Docker\""
echo " ProductKey=$key" echo " ProductKey=$KEY"
echo "" echo ""
echo "[Identification]" echo "[Identification]"
echo " JoinWorkgroup = WORKGROUP" echo " JoinWorkgroup = WORKGROUP"
@ -1465,56 +1483,6 @@ prepareInstall() {
return 0 return 0
} }
prepare2k3() {
local iso="$1"
local dir="$2"
local desc="$3"
local driver="2k3"
local arch key
[ -d "$dir/AMD64" ] && arch="amd64" || arch="x86"
if [[ "${arch,,}" == "x86" ]]; then
# Windows Server 2003 Standard x86 generic key (no activation, trial-only)
# This is not a pirated key, it comes from the official MS documentation.
key="QKDCQ-TP2JM-G4MDG-VR6F2-P9C48"
else
# Windows Server 2003 Standard x64 generic key (no activation, trial-only)
# This is not a pirated key, it comes from the official MS documentation.
key="P4WJG-WK3W7-3HM8W-RWHCK-8JTRY"
fi
prepareInstall "$iso" "$dir" "$desc" "$arch" "$key" "$driver" || return 1
return 0
}
prepareXP() {
local iso="$1"
local dir="$2"
local desc="$3"
local driver="xp"
local arch key
[ -d "$dir/AMD64" ] && arch="amd64" || arch="x86"
if [[ "${arch,,}" == "x86" ]]; then
# Windows XP Professional x86 generic key (no activation, trial-only)
# This is not a pirated key, it comes from the official MS documentation.
key="DR8GV-C8V6J-BYXHG-7PYJR-DB66Y"
else
# Windows XP Professional x64 generic key (no activation, trial-only)
# This is not a pirated key, it comes from the official MS documentation.
key="B2RBK-7KPT9-4JP6X-QQFWM-PJD6G"
fi
prepareInstall "$iso" "$dir" "$desc" "$arch" "$key" "$driver" || return 1
return 0
}
prepareLegacy() { prepareLegacy() {
local iso="$1" local iso="$1"
@ -1601,11 +1569,11 @@ setMachine() {
"win2k"* ) "win2k"* )
ETFS="[BOOT]/Boot-NoEmul.img" ;; ETFS="[BOOT]/Boot-NoEmul.img" ;;
"winxp"* ) "winxp"* )
if ! prepareXP "$iso" "$dir" "$desc"; then if ! prepareInstall "$iso" "$dir" "$desc" "xp"; then
error "Failed to prepare $desc ISO!" && return 1 error "Failed to prepare $desc ISO!" && return 1
fi ;; fi ;;
"win2003"* ) "win2003"* )
if ! prepare2k3 "$iso" "$dir" "$desc"; then if ! prepareInstall "$iso" "$dir" "$desc" "2k3"; then
error "Failed to prepare $desc ISO!" && return 1 error "Failed to prepare $desc ISO!" && return 1
fi ;; fi ;;
esac esac

View File

@ -681,6 +681,11 @@ updateXML() {
sed -i "s/SERVERSTANDARD<\/Value>/SERVER${EDITION^^}<\/Value>/g" "$asset" sed -i "s/SERVERSTANDARD<\/Value>/SERVER${EDITION^^}<\/Value>/g" "$asset"
fi fi
if [ -n "$KEY" ]; then
sed -i '/<ProductKey>/,/<\/ProductKey>/d' "$asset"
sed -i "s/<\/UserData>/ <ProductKey>\n <Key>${KEY}<\/Key>\n <WillShowUI>OnError<\/WillShowUI>\n <\/ProductKey>\n <\/UserData>/g" "$asset"
fi
return 0 return 0
} }