From a67a6a26e86894f0196aa42e40b692dd666ac468 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 19 Jul 2026 09:48:04 +0200 Subject: [PATCH] feat: Assign HOST as the Windows computer name (#1897) --- docs/environment.md | 2 +- src/define.sh | 35 +++++++++++++++++++++++++++++++++-- src/install.sh | 5 ++++- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/docs/environment.md b/docs/environment.md index ac1b583f..500b109d 100644 --- a/docs/environment.md +++ b/docs/environment.md @@ -53,7 +53,7 @@ An empty default means the variable is unset and its value is determined automat |---|---|---| | `NETWORK` | | Network mode, such as `nat`, `user`, or `N` to disable networking. | | `DHCP` | `N` | Enables macvtap networking so Windows receives an address from the external LAN through DHCP. | -| `HOST` | `Windows` | Hostname assigned to Windows. | +| `HOST` | `Windows` | Computer name assigned to Windows and advertised on the network. | | `IP` | | Overrides the automatically selected guest IPv4 address. | | `MAC` | | Guest network adapter MAC address. | | `ADAPTER` | `virtio-net-pci` | QEMU network adapter model. | diff --git a/src/define.sh b/src/define.sh index a4da136c..ab9ea52a 100644 --- a/src/define.sh +++ b/src/define.sh @@ -2,6 +2,7 @@ set -Eeuo pipefail : "${KEY:=""}" +: "${HOST:=""}" : "${WIDTH:=""}" : "${HEIGHT:=""}" : "${VERIFY:=""}" @@ -20,6 +21,7 @@ set -Eeuo pipefail # Sanitize variables KEY=$(strip "$KEY") +HOST=$(strip "$HOST") WIDTH=$(strip "$WIDTH") HEIGHT=$(strip "$HEIGHT") DOMAIN=$(strip "$DOMAIN") @@ -1380,6 +1382,33 @@ validateProductKey() { return 0 } +validateComputerName() { + + local value="$1" + + if [ -z "$value" ]; then + value="$APP" + HOST="$value" + fi + + if [ "${#value}" -gt 15 ]; then + error "The HOST variable cannot contain more than 15 characters!" + return 1 + fi + + if [[ ! "$value" =~ ^[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?$ ]]; then + error "The HOST variable may only contain letters, digits, and hyphens, and cannot start or end with a hyphen!" + return 1 + fi + + if [[ "$value" =~ ^[0-9]+$ ]]; then + error "The HOST variable cannot contain only digits!" + return 1 + fi + + return 0 +} + validateLegacyText() { local name="$1" @@ -1719,6 +1748,7 @@ prepareInstall() { validateResolution "WIDTH" "$WIDTH" 320 || return 1 validateResolution "HEIGHT" "$HEIGHT" 200 || return 1 + validateComputerName "$HOST" || return 1 validateLegacyText "APP" "$APP" "$desc" || return 1 validateLegacyText "ENGINE" "$ENGINE" "$desc" || return 1 @@ -1727,12 +1757,13 @@ prepareInstall() { local username="${USERNAME:-Docker}" local password="${PASSWORD:-admin}" - local sifUsername sifPassword sifOrganization + local sifHost sifUsername sifPassword sifOrganization local regUsername regPassword validateLegacyUsername "$username" "$desc" || return 1 validateLegacyPassword "$password" "$desc" || return 1 + sifHost=$(escapeSIFValue "$HOST") || return 1 sifUsername=$(escapeSIFValue "$username") || return 1 sifPassword=$(escapeSIFValue "$password") || return 1 sifOrganization=$(escapeSIFValue "$APP for $ENGINE") || return 1 @@ -1774,7 +1805,7 @@ prepareInstall() { echo "" echo "[UserData]" echo " FullName=\"$sifUsername\"" - echo " ComputerName=\"*\"" + echo " ComputerName=\"$sifHost\"" echo " OrgName=\"$sifOrganization\"" echo " $product" echo "" diff --git a/src/install.sh b/src/install.sh index 1459f9db..98512223 100644 --- a/src/install.sh +++ b/src/install.sh @@ -1027,19 +1027,22 @@ updateXML() { local language="$2" local app value culture region keyboard edition key local user raw_user user_xml auth_user safe_user - local admin pass pw domain qualifier + local admin pass pw domain qualifier host [ -z "$WIDTH" ] && WIDTH="1280" [ -z "$HEIGHT" ] && HEIGHT="720" validateResolution "WIDTH" "$WIDTH" 320 || return 1 validateResolution "HEIGHT" "$HEIGHT" 200 || return 1 + validateComputerName "$HOST" || return 1 validateProductKey "$KEY" || return 1 validatePassword "$PASSWORD" || return 1 app=$(escapeXMLSed "$APP for $ENGINE") || return 1 + host=$(escapeXMLSed "$HOST") || return 1 sed -i "s|>Windows for Docker<|>$app<|g" "$asset" || return 1 + sed -i -E "s|[^<]*|$host|g" "$asset" || return 1 sed -i "s|1080|$HEIGHT|g" "$asset" || return 1 sed -i "s|1920|$WIDTH|g" "$asset" || return 1