mirror of
https://github.com/dockur/windows.git
synced 2026-07-28 21:53:34 +07:00
feat: Refactor legacy installation code (#1965)
This commit is contained in:
+167
-113
@@ -969,41 +969,16 @@ validateLegacyUsername() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
legacyInstall() {
|
addLegacyDrivers() {
|
||||||
|
|
||||||
local dir="$2"
|
|
||||||
local desc="$3"
|
|
||||||
local driver="$4"
|
|
||||||
local drivers="/tmp/drivers"
|
|
||||||
local file shortcut="Y"
|
|
||||||
|
|
||||||
if disabled "$SHORTCUT" || disabled "${SAMBA:-Y}"; then
|
|
||||||
shortcut="N"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$DOMAIN" ]; then
|
|
||||||
error "The DOMAIN variable is not supported for $desc!"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
ETFS="[BOOT]/Boot-NoEmul.img"
|
|
||||||
|
|
||||||
if [ ! -f "$dir/$ETFS" ] || [ ! -s "$dir/$ETFS" ]; then
|
|
||||||
error "Failed to locate file \"$ETFS\" in $desc ISO image!" && return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local arch="amd64"
|
|
||||||
[ ! -d "$dir/AMD64" ] && arch="x86"
|
|
||||||
local target="$dir/AMD64"
|
|
||||||
[[ "${arch,,}" == "x86" ]] && target="$dir/I386"
|
|
||||||
|
|
||||||
if [ ! -d "$target" ]; then
|
|
||||||
error "Failed to locate directory \"$target\" in $desc ISO image!" && return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${driver,,}" == "xp" || "${driver,,}" == "2k3" ]]; then
|
|
||||||
|
|
||||||
|
local dir="$1"
|
||||||
|
local target="$2"
|
||||||
|
local driver="$3"
|
||||||
|
local arch="$4"
|
||||||
|
local drivers="$5"
|
||||||
|
local file
|
||||||
local msg="Adding drivers to image..."
|
local msg="Adding drivers to image..."
|
||||||
|
|
||||||
info "$msg" && html "$msg"
|
info "$msg" && html "$msg"
|
||||||
|
|
||||||
rm -rf "$drivers" || return 1
|
rm -rf "$drivers" || return 1
|
||||||
@@ -1067,15 +1042,21 @@ legacyInstall() {
|
|||||||
|
|
||||||
rm -rf "$drivers" || return 1
|
rm -rf "$drivers" || return 1
|
||||||
|
|
||||||
fi
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
setLegacyKey() {
|
||||||
|
|
||||||
|
local target="$1"
|
||||||
|
local driver="$2"
|
||||||
|
local arch="$3"
|
||||||
|
local desc="$4"
|
||||||
|
local setup pid key file
|
||||||
|
|
||||||
local setup
|
|
||||||
setup=$(find "$target" -maxdepth 1 -type f -iname setupp.ini -print -quit) || return 1
|
setup=$(find "$target" -maxdepth 1 -type f -iname setupp.ini -print -quit) || return 1
|
||||||
|
|
||||||
if [ -n "$setup" ] && [ -z "$KEY" ]; then
|
if [ -n "$setup" ] && [ -z "$KEY" ]; then
|
||||||
|
|
||||||
local pid key
|
|
||||||
|
|
||||||
pid=$(<"$setup") || return 1
|
pid=$(<"$setup") || return 1
|
||||||
pid="${pid%$'\r'}"
|
pid="${pid%$'\r'}"
|
||||||
|
|
||||||
@@ -1157,60 +1138,34 @@ legacyInstall() {
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
validateProductKey "$KEY" || return 1
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
local product=""
|
writeCommand() {
|
||||||
[ -n "$KEY" ] && product="ProductID=$KEY"
|
|
||||||
|
|
||||||
mkdir -p "$dir/\$OEM\$" || return 1
|
local install="$1"
|
||||||
|
|
||||||
if ! addFolder "$dir"; then
|
[ ! -f "$install" ] && return 0
|
||||||
error "Failed to add OEM folder to image!" && return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local oem=""
|
|
||||||
local install="$dir/\$OEM\$/\$1/OEM/install.bat"
|
|
||||||
|
|
||||||
if [ -f "$install" ]; then
|
|
||||||
|
|
||||||
if ! enabled "${LOG:-}"; then
|
if ! enabled "${LOG:-}"; then
|
||||||
oem="\"Script\"=\"cmd /C start \\\"Install\\\" \\\"cmd /C C:\\\\OEM\\\\install.bat\\\"\""
|
printf '%s' "\"Script\"=\"cmd /C start \\\"Install\\\" \\\"cmd /C C:\\\\OEM\\\\install.bat\\\"\""
|
||||||
else
|
else
|
||||||
oem="\"Script\"=\"cmd /C start \\\"Install\\\" \\\"cmd /C C:\\\\OEM\\\\install.bat > C:\\\\OEM\\\\install.log 2>&1\\\"\""
|
printf '%s' "\"Script\"=\"cmd /C start \\\"Install\\\" \\\"cmd /C C:\\\\OEM\\\\install.bat > C:\\\\OEM\\\\install.log 2>&1\\\"\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
[ -z "$WIDTH" ] && WIDTH="1280"
|
writeSIF() {
|
||||||
[ -z "$HEIGHT" ] && HEIGHT="720"
|
|
||||||
|
|
||||||
validateResolution "WIDTH" "$WIDTH" 320 || return 1
|
local target="$1"
|
||||||
validateResolution "HEIGHT" "$HEIGHT" 200 || return 1
|
local driver="$2"
|
||||||
validateMembership || return 1
|
local product="$3"
|
||||||
validateComputerName "$HOST" || return 1
|
local sifHost="$4"
|
||||||
validateLegacyText "APP" "$APP" "$desc" || return 1
|
local sifUsername="$5"
|
||||||
validateLegacyText "ENGINE" "$ENGINE" "$desc" || return 1
|
local sifPassword="$6"
|
||||||
|
local sifOrganization="$7"
|
||||||
XHEX=$(printf '%08x\n' "$((10#$WIDTH))") || return 1
|
local sifWorkgroup="$8"
|
||||||
YHEX=$(printf '%08x\n' "$((10#$HEIGHT))") || return 1
|
|
||||||
|
|
||||||
local username="${USERNAME:-Docker}"
|
|
||||||
local password="${PASSWORD:-admin}"
|
|
||||||
local workgroup="${WORKGROUP:-WORKGROUP}"
|
|
||||||
|
|
||||||
local sifHost sifUsername sifPassword sifOrganization sifWorkgroup
|
|
||||||
local regUsername regPassword
|
|
||||||
|
|
||||||
validateLegacyUsername "$username" "$desc" || return 1
|
|
||||||
validatePassword "$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
|
|
||||||
sifWorkgroup=$(escapeSIFValue "$workgroup") || return 1
|
|
||||||
regUsername=$(escapeRegistryValue "$username") || return 1
|
|
||||||
regPassword=$(escapeRegistryValue "$password") || return 1
|
|
||||||
|
|
||||||
find "$target" -maxdepth 1 -type f -iname winnt.sif -delete || return 1
|
find "$target" -maxdepth 1 -type f -iname winnt.sif -delete || return 1
|
||||||
|
|
||||||
@@ -1297,6 +1252,17 @@ legacyInstall() {
|
|||||||
} | unix2dos >> "$target/WINNT.SIF" || return 1
|
} | unix2dos >> "$target/WINNT.SIF" || return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
writeRegistry() {
|
||||||
|
|
||||||
|
local dir="$1"
|
||||||
|
local shortcut="$2"
|
||||||
|
local oem="$3"
|
||||||
|
local regUsername="$4"
|
||||||
|
local regPassword="$5"
|
||||||
|
|
||||||
{
|
{
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
'Windows Registry Editor Version 5.00' \
|
'Windows Registry Editor Version 5.00' \
|
||||||
@@ -1360,6 +1326,14 @@ legacyInstall() {
|
|||||||
printf '%s\n' "$oem" ''
|
printf '%s\n' "$oem" ''
|
||||||
} | unix2dos > "$dir/\$OEM\$/install.reg" || return 1
|
} | unix2dos > "$dir/\$OEM\$/install.reg" || return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
appendRegistry() {
|
||||||
|
|
||||||
|
local dir="$1"
|
||||||
|
local driver="$2"
|
||||||
|
|
||||||
if [[ "$driver" == "2k" ]]; then
|
if [[ "$driver" == "2k" ]]; then
|
||||||
{
|
{
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
@@ -1381,6 +1355,15 @@ legacyInstall() {
|
|||||||
} | unix2dos >> "$dir/\$OEM\$/install.reg" || return 1
|
} | unix2dos >> "$dir/\$OEM\$/install.reg" || return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
writeVBS() {
|
||||||
|
|
||||||
|
local dir="$1"
|
||||||
|
local username="$2"
|
||||||
|
local shortcut="$3"
|
||||||
|
|
||||||
{
|
{
|
||||||
printf '%s\n' \
|
printf '%s\n' \
|
||||||
'Set WshShell = WScript.CreateObject("WScript.Shell")' \
|
'Set WshShell = WScript.CreateObject("WScript.Shell")' \
|
||||||
@@ -1449,48 +1432,119 @@ legacyInstall() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
legacyPrepare() {
|
legacyInstall() {
|
||||||
|
|
||||||
local iso="$1"
|
|
||||||
local dir="$2"
|
local dir="$2"
|
||||||
local desc="$3"
|
local desc="$3"
|
||||||
|
local driver="$4"
|
||||||
|
local shortcut="Y"
|
||||||
|
local drivers="/tmp/drivers"
|
||||||
|
|
||||||
local tmp="$TMP/boot-images"
|
if disabled "$SHORTCUT" || disabled "${SAMBA:-Y}"; then
|
||||||
local image="$tmp/eltorito_img1_bios.img"
|
shortcut="N"
|
||||||
|
fi
|
||||||
|
|
||||||
ETFS="boot.img"
|
if [ -n "$DOMAIN" ]; then
|
||||||
[ -f "$dir/$ETFS" ] && [ -s "$dir/$ETFS" ] && return 0
|
error "The DOMAIN variable is not supported for $desc!"
|
||||||
|
|
||||||
rm -f "$dir/$ETFS" || return 1
|
|
||||||
rm -rf "$tmp" || return 1
|
|
||||||
|
|
||||||
LC_ALL=C xorriso \
|
|
||||||
-no_rc \
|
|
||||||
-osirrox on \
|
|
||||||
-indev "$iso" \
|
|
||||||
-extract_boot_images "$tmp" >/dev/null 2>&1 || {
|
|
||||||
local rc=$?
|
|
||||||
rm -rf "$tmp" || true
|
|
||||||
|
|
||||||
(( rc > 128 )) && exit "$rc"
|
|
||||||
|
|
||||||
error "Failed to extract boot image from $desc ISO!"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ ! -s "$image" ]; then
|
|
||||||
rm -rf "$tmp" || true
|
|
||||||
error "Failed to locate BIOS boot image in $desc ISO!"
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! mv -f "$image" "$dir/$ETFS"; then
|
ETFS="[BOOT]/Boot-NoEmul.img"
|
||||||
rm -rf "$tmp" || true
|
|
||||||
error "Failed to save boot image from $desc ISO!"
|
if [ ! -f "$dir/$ETFS" ] || [ ! -s "$dir/$ETFS" ]; then
|
||||||
return 1
|
error "Failed to locate file \"$ETFS\" in $desc ISO image!" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -rf "$tmp" || return 1
|
local arch="amd64"
|
||||||
|
[ ! -d "$dir/AMD64" ] && arch="x86"
|
||||||
|
|
||||||
|
local target="$dir/AMD64"
|
||||||
|
[[ "${arch,,}" == "x86" ]] && target="$dir/I386"
|
||||||
|
|
||||||
|
if [ ! -d "$target" ]; then
|
||||||
|
error "Failed to locate directory \"$target\" in $desc ISO image!" && return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${driver,,}" == "xp" || "${driver,,}" == "2k3" ]]; then
|
||||||
|
addLegacyDrivers "$dir" "$target" "$driver" "$arch" "$drivers" || return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
setLegacyKey "$target" "$driver" "$arch" "$desc" || return 1
|
||||||
|
validateProductKey "$KEY" || return 1
|
||||||
|
|
||||||
|
local product=""
|
||||||
|
[ -n "$KEY" ] && product="ProductID=$KEY"
|
||||||
|
|
||||||
|
mkdir -p "$dir/\$OEM\$" || return 1
|
||||||
|
|
||||||
|
if ! addFolder "$dir"; then
|
||||||
|
error "Failed to add OEM folder to image!" && return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local oem=""
|
||||||
|
local install
|
||||||
|
|
||||||
|
install=$(find \
|
||||||
|
"$dir/\$OEM\$/\$1/OEM" \
|
||||||
|
-maxdepth 1 \
|
||||||
|
-type f \
|
||||||
|
-iname install.bat \
|
||||||
|
-print -quit
|
||||||
|
) || return 1
|
||||||
|
|
||||||
|
oem=$(writeCommand "$install") || return 1
|
||||||
|
|
||||||
|
[ -z "$WIDTH" ] && WIDTH="1280"
|
||||||
|
[ -z "$HEIGHT" ] && HEIGHT="720"
|
||||||
|
|
||||||
|
validateResolution "WIDTH" "$WIDTH" 320 || return 1
|
||||||
|
validateResolution "HEIGHT" "$HEIGHT" 200 || return 1
|
||||||
|
validateMembership || return 1
|
||||||
|
validateComputerName "$HOST" || return 1
|
||||||
|
validateLegacyText "APP" "$APP" "$desc" || return 1
|
||||||
|
validateLegacyText "ENGINE" "$ENGINE" "$desc" || return 1
|
||||||
|
|
||||||
|
XHEX=$(printf '%08x\n' "$((10#$WIDTH))") || return 1
|
||||||
|
YHEX=$(printf '%08x\n' "$((10#$HEIGHT))") || return 1
|
||||||
|
|
||||||
|
local username="${USERNAME:-Docker}"
|
||||||
|
local password="${PASSWORD:-admin}"
|
||||||
|
local workgroup="${WORKGROUP:-WORKGROUP}"
|
||||||
|
|
||||||
|
local sifHost sifUsername sifPassword sifOrganization sifWorkgroup
|
||||||
|
local regUsername regPassword
|
||||||
|
|
||||||
|
validateLegacyUsername "$username" "$desc" || return 1
|
||||||
|
validatePassword "$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
|
||||||
|
sifWorkgroup=$(escapeSIFValue "$workgroup") || return 1
|
||||||
|
regUsername=$(escapeRegistryValue "$username") || return 1
|
||||||
|
regPassword=$(escapeRegistryValue "$password") || return 1
|
||||||
|
|
||||||
|
writeSIF \
|
||||||
|
"$target" \
|
||||||
|
"$driver" \
|
||||||
|
"$product" \
|
||||||
|
"$sifHost" \
|
||||||
|
"$sifUsername" \
|
||||||
|
"$sifPassword" \
|
||||||
|
"$sifOrganization" \
|
||||||
|
"$sifWorkgroup" || return 1
|
||||||
|
|
||||||
|
writeRegistry \
|
||||||
|
"$dir" \
|
||||||
|
"$shortcut" \
|
||||||
|
"$oem" \
|
||||||
|
"$regUsername" \
|
||||||
|
"$regPassword" || return 1
|
||||||
|
|
||||||
|
appendRegistry "$dir" "$driver" || return 1
|
||||||
|
writeVBS "$dir" "$username" "$shortcut" || return 1
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user