2024-01-14 15:39:24 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-01-14 14:19:58 +00:00
|
|
|
set -Eeuo pipefail
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
TMP="$STORAGE/tmp"
|
|
|
|
DIR="$TMP/unpack"
|
|
|
|
FB="falling back to manual installation!"
|
|
|
|
ETFS="boot/etfsboot.com"
|
|
|
|
EFISYS="efi/microsoft/boot/efisys_noprompt.bin"
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
skipInstall() {
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-05-12 11:49:56 +00:00
|
|
|
local iso="$1"
|
|
|
|
local magic byte
|
|
|
|
local boot="$STORAGE/windows.boot"
|
|
|
|
local previous="$STORAGE/windows.base"
|
|
|
|
|
|
|
|
if [ -f "$previous" ]; then
|
|
|
|
previous=$(<"$previous")
|
|
|
|
if [ -n "$previous" ]; then
|
|
|
|
previous="$STORAGE/$previous"
|
|
|
|
if [[ "${previous,,}" != "${iso,,}" ]]; then
|
|
|
|
if [ -f "$boot" ] && hasDisk; then
|
|
|
|
info "Detected that the version was changed, but ignoring this because Windows is already installed."
|
|
|
|
info "Please start with an empty /storage folder, if you want to install a different version of Windows."
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
[ -f "$previous" ] && rm -f "$previous"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
2024-01-24 04:38:16 +00:00
|
|
|
fi
|
2024-01-19 03:28:03 +00:00
|
|
|
|
2024-05-12 11:49:56 +00:00
|
|
|
[ -f "$boot" ] && hasDisk && return 0
|
|
|
|
|
|
|
|
[ ! -f "$iso" ] && return 1
|
|
|
|
[ ! -s "$iso" ] && return 1
|
|
|
|
|
|
|
|
# Check if the ISO was already processed by our script
|
|
|
|
magic=$(dd if="$iso" seek=0 bs=1 count=1 status=none | tr -d '\000')
|
|
|
|
magic="$(printf '%s' "$magic" | od -A n -t x1 -v | tr -d ' \n')"
|
|
|
|
byte="16" && [[ "$MANUAL" == [Yy1]* ]] && byte="17"
|
|
|
|
|
|
|
|
if [[ "$magic" != "$byte" ]]; then
|
|
|
|
info "The ISO will be processed again because the configuration was changed..."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
2024-01-24 04:38:16 +00:00
|
|
|
}
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
startInstall() {
|
2024-01-16 18:58:55 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
html "Starting $APP..."
|
2024-01-22 22:31:35 +00:00
|
|
|
|
2024-05-12 11:49:56 +00:00
|
|
|
if [ -z "$CUSTOM" ]; then
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-05-21 22:53:19 +00:00
|
|
|
local file="${VERSION//\//}.iso"
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
if [[ "${VERSION,,}" == "http"* ]]; then
|
2024-01-24 04:38:16 +00:00
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
file=$(basename "${VERSION%%\?*}")
|
|
|
|
: "${file//+/ }"; printf -v file '%b' "${_//%/\\x}"
|
|
|
|
file=$(echo "$file" | sed -e 's/[^A-Za-z0-9._-]/_/g')
|
2024-01-24 04:38:16 +00:00
|
|
|
|
2024-05-18 14:33:12 +00:00
|
|
|
else
|
|
|
|
|
|
|
|
local language
|
|
|
|
language=$(getLanguage "$LANGUAGE" "culture")
|
|
|
|
language="${language%%-*}"
|
|
|
|
|
|
|
|
if [ -n "$language" ] && [[ "${language,,}" != "en" ]]; then
|
2024-05-21 22:53:19 +00:00
|
|
|
file="${VERSION//\//}_${language,,}.iso"
|
2024-05-18 14:33:12 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
fi
|
2024-01-24 04:38:16 +00:00
|
|
|
|
2024-05-12 11:49:56 +00:00
|
|
|
BOOT="$STORAGE/$file"
|
2024-01-24 04:38:16 +00:00
|
|
|
|
2024-05-12 11:49:56 +00:00
|
|
|
! migrateFiles "$BOOT" "$VERSION" && error "Migration failed!" && exit 57
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-12 11:49:56 +00:00
|
|
|
skipInstall "$BOOT" && return 1
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
rm -rf "$TMP"
|
|
|
|
mkdir -p "$TMP"
|
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
if [ -z "$CUSTOM" ]; then
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-05-12 11:49:56 +00:00
|
|
|
ISO=$(basename "$BOOT")
|
2024-05-05 19:24:47 +00:00
|
|
|
ISO="$TMP/$ISO"
|
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
if [ -f "$BOOT" ] && [ -s "$BOOT" ]; then
|
|
|
|
mv -f "$BOOT" "$ISO"
|
|
|
|
fi
|
|
|
|
|
2024-04-22 13:50:01 +00:00
|
|
|
fi
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
rm -f "$BOOT"
|
2024-01-24 04:38:16 +00:00
|
|
|
return 0
|
|
|
|
}
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
finishInstall() {
|
|
|
|
|
|
|
|
local iso="$1"
|
|
|
|
local aborted="$2"
|
2024-05-12 11:49:56 +00:00
|
|
|
local base byte
|
2024-05-04 11:28:12 +00:00
|
|
|
|
|
|
|
if [ ! -s "$iso" ] || [ ! -f "$iso" ]; then
|
|
|
|
error "Failed to find ISO file: $iso" && return 1
|
|
|
|
fi
|
|
|
|
|
2024-05-12 11:49:56 +00:00
|
|
|
if [[ "$aborted" != [Yy1]* ]]; then
|
2024-05-04 11:28:12 +00:00
|
|
|
# Mark ISO as prepared via magic byte
|
2024-05-12 11:49:56 +00:00
|
|
|
byte="16" && [[ "$MANUAL" == [Yy1]* ]] && byte="17"
|
2024-05-09 13:59:06 +00:00
|
|
|
if ! printf '%b' "\x$byte" | dd of="$iso" bs=1 seek=0 count=1 conv=notrunc status=none; then
|
2024-05-12 11:49:56 +00:00
|
|
|
warn "failed to set magic byte in ISO file: $iso"
|
2024-05-04 11:28:12 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f "$STORAGE/windows.old"
|
2024-05-27 10:40:19 +00:00
|
|
|
rm -f "$STORAGE/windows.type"
|
2024-05-12 11:49:56 +00:00
|
|
|
rm -f "$STORAGE/windows.base"
|
2024-05-04 11:28:12 +00:00
|
|
|
rm -f "$STORAGE/windows.boot"
|
|
|
|
rm -f "$STORAGE/windows.mode"
|
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
cp -f /run/version "$STORAGE/windows.ver"
|
2024-05-04 11:28:12 +00:00
|
|
|
|
2024-05-12 11:49:56 +00:00
|
|
|
if [[ "$iso" == "$STORAGE/"* ]]; then
|
|
|
|
if [[ "$aborted" != [Yy1]* ]] || [ -z "$CUSTOM" ]; then
|
|
|
|
base=$(basename "$iso")
|
|
|
|
echo "$base" > "$STORAGE/windows.base"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
|
|
|
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
|
|
|
|
echo "$BOOT_MODE" > "$STORAGE/windows.mode"
|
|
|
|
if [[ "${MACHINE,,}" != "q35" ]]; then
|
|
|
|
echo "$MACHINE" > "$STORAGE/windows.old"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Enable secure boot + TPM on manual installs as Win11 requires
|
|
|
|
if [[ "$MANUAL" == [Yy1]* ]] || [[ "$aborted" == [Yy1]* ]]; then
|
|
|
|
if [[ "${DETECTED,,}" == "win11"* ]]; then
|
|
|
|
BOOT_MODE="windows_secure"
|
|
|
|
echo "$BOOT_MODE" > "$STORAGE/windows.mode"
|
|
|
|
fi
|
|
|
|
fi
|
2024-05-23 00:38:21 +00:00
|
|
|
# Enable secure boot on multi-socket systems to workaround freeze
|
|
|
|
if [ -n "$SOCKETS" ] && [[ "$SOCKETS" != "1" ]]; then
|
|
|
|
BOOT_MODE="windows_secure"
|
2024-05-27 10:40:19 +00:00
|
|
|
echo "$BOOT_MODE" > "$STORAGE/windows.mode"
|
2024-05-23 00:38:21 +00:00
|
|
|
fi
|
2024-05-04 11:28:12 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
if [ -n "${DISK_TYPE:-}" ] && [[ "${DISK_TYPE:-}" != "scsi" ]]; then
|
|
|
|
echo "$DISK_TYPE" > "$STORAGE/windows.type"
|
|
|
|
fi
|
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
rm -rf "$TMP"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
abortInstall() {
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
local dir="$1"
|
|
|
|
local iso="$2"
|
2024-05-04 11:28:12 +00:00
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
[[ "${iso,,}" == *".esd" ]] && exit 60
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
if [ ! -d "$dir/EFI" ]; then
|
|
|
|
[[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
|
|
|
|
fi
|
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
if [ -n "$CUSTOM" ]; then
|
|
|
|
BOOT="$iso"
|
|
|
|
REMOVE="N"
|
|
|
|
else
|
|
|
|
if [[ "$iso" != "$BOOT" ]]; then
|
|
|
|
if ! mv -f "$iso" "$BOOT"; then
|
|
|
|
error "Failed to move ISO file: $iso" && return 1
|
|
|
|
fi
|
2024-05-04 11:28:12 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
finishInstall "$BOOT" "Y" && return 0
|
2024-05-04 11:28:12 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
detectCustom() {
|
|
|
|
|
2024-05-22 22:16:02 +00:00
|
|
|
local file base
|
2024-05-04 11:28:12 +00:00
|
|
|
CUSTOM=""
|
|
|
|
|
2024-05-22 22:16:02 +00:00
|
|
|
file=$(find / -maxdepth 1 -type f -iname custom.iso | head -n 1)
|
|
|
|
[ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname custom.iso | head -n 1)
|
2024-04-30 20:57:44 +00:00
|
|
|
|
2024-05-22 22:16:02 +00:00
|
|
|
if [ ! -s "$file" ] && [[ "${VERSION,,}" != "http"* ]]; then
|
|
|
|
base=$(basename "$VERSION")
|
|
|
|
file="$STORAGE/$base"
|
|
|
|
fi
|
2024-05-04 11:28:12 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
if [ ! -f "$file" ] || [ ! -s "$file" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
2024-05-05 19:24:47 +00:00
|
|
|
|
2024-05-22 22:16:02 +00:00
|
|
|
local size
|
2024-05-05 19:24:47 +00:00
|
|
|
size="$(stat -c%s "$file")"
|
|
|
|
[ -z "$size" ] || [[ "$size" == "0" ]] && return 0
|
2024-04-30 20:57:44 +00:00
|
|
|
|
2024-05-12 11:49:56 +00:00
|
|
|
ISO="$file"
|
|
|
|
CUSTOM="$ISO"
|
|
|
|
BOOT="$STORAGE/windows.$size.iso"
|
2024-05-04 11:28:12 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-02-04 18:45:32 +00:00
|
|
|
extractESD() {
|
|
|
|
|
|
|
|
local iso="$1"
|
|
|
|
local dir="$2"
|
2024-04-30 20:57:44 +00:00
|
|
|
local version="$3"
|
|
|
|
local desc="$4"
|
2024-02-04 18:45:32 +00:00
|
|
|
local size size_gb space space_gb desc
|
|
|
|
|
|
|
|
local msg="Extracting $desc bootdisk..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
if [ "$(stat -c%s "$iso")" -lt 100000000 ]; then
|
|
|
|
error "Invalid ESD file: Size is smaller than 100 MB" && return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf "$dir"
|
|
|
|
mkdir -p "$dir"
|
|
|
|
|
2024-02-04 18:45:32 +00:00
|
|
|
size=16106127360
|
|
|
|
size_gb=$(( (size + 1073741823)/1073741824 ))
|
2024-04-24 18:16:43 +00:00
|
|
|
space=$(df --output=avail -B 1 "$dir" | tail -n 1)
|
2024-02-04 18:45:32 +00:00
|
|
|
space_gb=$(( (space + 1073741823)/1073741824 ))
|
|
|
|
|
|
|
|
if (( size > space )); then
|
2024-04-24 18:16:43 +00:00
|
|
|
error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1
|
2024-02-04 18:45:32 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
local esdImageCount
|
2024-05-10 16:21:41 +00:00
|
|
|
esdImageCount=$(wimlib-imagex info "$iso" | awk '/Image Count:/ {print $3}')
|
2024-02-04 18:45:32 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
wimlib-imagex apply "$iso" 1 "$dir" --quiet 2>/dev/null || {
|
2024-02-04 18:45:32 +00:00
|
|
|
retVal=$?
|
2024-04-30 20:57:44 +00:00
|
|
|
error "Extracting $desc bootdisk failed" && return $retVal
|
2024-02-04 18:45:32 +00:00
|
|
|
}
|
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
local bootWimFile="$dir/sources/boot.wim"
|
|
|
|
local installWimFile="$dir/sources/install.wim"
|
2024-02-04 18:45:32 +00:00
|
|
|
|
|
|
|
local msg="Extracting $desc environment..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
2024-05-10 19:26:10 +00:00
|
|
|
wimlib-imagex export "$iso" 2 "$bootWimFile" --compress=none --quiet || {
|
2024-02-04 18:45:32 +00:00
|
|
|
retVal=$?
|
|
|
|
error "Adding WinPE failed" && return ${retVal}
|
|
|
|
}
|
|
|
|
|
|
|
|
local msg="Extracting $desc setup..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
2024-05-10 19:26:10 +00:00
|
|
|
wimlib-imagex export "$iso" 3 "$bootWimFile" --compress=none --boot --quiet || {
|
2024-02-04 18:45:32 +00:00
|
|
|
retVal=$?
|
|
|
|
error "Adding Windows Setup failed" && return ${retVal}
|
|
|
|
}
|
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
|
|
|
LABEL="CCCOMA_X64FRE_EN-US_DV9"
|
|
|
|
else
|
|
|
|
LABEL="CPBA_A64FRE_EN-US_DV9"
|
|
|
|
fi
|
|
|
|
|
2024-02-04 18:45:32 +00:00
|
|
|
local msg="Extracting $desc image..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
|
|
|
local edition imageIndex imageEdition
|
2024-05-05 19:24:47 +00:00
|
|
|
edition=$(getCatalog "$version" "name")
|
2024-02-04 18:45:32 +00:00
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
if [ -z "$edition" ]; then
|
|
|
|
error "Invalid VERSION specified, value \"$version\" is not recognized!" && return 1
|
|
|
|
fi
|
2024-02-04 18:45:32 +00:00
|
|
|
|
|
|
|
for (( imageIndex=4; imageIndex<=esdImageCount; imageIndex++ )); do
|
2024-05-10 16:21:41 +00:00
|
|
|
imageEdition=$(wimlib-imagex info "$iso" ${imageIndex} | grep '^Description:' | sed 's/Description:[ \t]*//')
|
2024-05-05 19:24:47 +00:00
|
|
|
[[ "${imageEdition,,}" != "${edition,,}" ]] && continue
|
2024-05-10 16:21:41 +00:00
|
|
|
wimlib-imagex export "$iso" ${imageIndex} "$installWimFile" --compress=LZMS --chunk-size 128K --quiet || {
|
2024-02-04 18:45:32 +00:00
|
|
|
retVal=$?
|
2024-05-10 16:21:41 +00:00
|
|
|
error "Addition of $imageIndex to the $desc image failed" && return $retVal
|
2024-02-04 18:45:32 +00:00
|
|
|
}
|
|
|
|
return 0
|
|
|
|
done
|
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
error "Failed to find product '$edition' in install.wim!" && return 1
|
2024-02-04 18:45:32 +00:00
|
|
|
}
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
extractImage() {
|
|
|
|
|
|
|
|
local iso="$1"
|
|
|
|
local dir="$2"
|
2024-04-30 20:57:44 +00:00
|
|
|
local version="$3"
|
2024-05-04 11:28:12 +00:00
|
|
|
local desc="local ISO"
|
2024-01-24 04:54:26 +00:00
|
|
|
local size size_gb space space_gb
|
2024-01-24 23:18:59 +00:00
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
if [ -z "$CUSTOM" ]; then
|
|
|
|
desc="downloaded ISO"
|
|
|
|
if [[ "$version" != "http"* ]]; then
|
|
|
|
desc=$(printVersion "$version" "$desc")
|
|
|
|
fi
|
2024-02-04 18:45:32 +00:00
|
|
|
fi
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if [[ "${iso,,}" == *".esd" ]]; then
|
|
|
|
extractESD "$iso" "$dir" "$version" "$desc" && return 0
|
|
|
|
return 1
|
2024-01-27 13:52:58 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
local msg="Extracting $desc image..."
|
2024-01-24 04:38:16 +00:00
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
rm -rf "$dir"
|
|
|
|
mkdir -p "$dir"
|
|
|
|
|
2024-01-24 04:54:26 +00:00
|
|
|
size=$(stat -c%s "$iso")
|
|
|
|
size_gb=$(( (size + 1073741823)/1073741824 ))
|
2024-04-24 18:16:43 +00:00
|
|
|
space=$(df --output=avail -B 1 "$dir" | tail -n 1)
|
2024-01-24 04:54:26 +00:00
|
|
|
space_gb=$(( (space + 1073741823)/1073741824 ))
|
2024-01-24 04:38:16 +00:00
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
if ((size<100000000)); then
|
|
|
|
error "Invalid ISO file: Size is smaller than 100 MB" && return 1
|
2024-01-19 14:18:56 +00:00
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
if (( size > space )); then
|
2024-04-24 18:16:43 +00:00
|
|
|
error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1
|
2024-01-24 04:38:16 +00:00
|
|
|
fi
|
2024-01-22 01:56:28 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
rm -rf "$dir"
|
2024-01-25 15:15:18 +00:00
|
|
|
|
|
|
|
if ! 7z x "$iso" -o"$dir" > /dev/null; then
|
2024-04-24 18:16:43 +00:00
|
|
|
error "Failed to extract ISO file: $iso" && return 1
|
2024-01-25 15:15:18 +00:00
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
LABEL=$(isoinfo -d -i "$iso" | sed -n 's/Volume id: //p')
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
getPlatform() {
|
2024-05-04 11:28:12 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
local xml="$1"
|
|
|
|
local tag="ARCH"
|
|
|
|
local platform="x64"
|
|
|
|
local arch
|
2024-05-04 11:28:12 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
arch=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$xml")
|
2024-05-04 11:28:12 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
case "${arch,,}" in
|
|
|
|
"0" ) platform="x86" ;;
|
|
|
|
"9" ) platform="x64" ;;
|
|
|
|
"12" )platform="arm64" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
echo "$platform"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-05-18 14:33:12 +00:00
|
|
|
checkPlatform() {
|
|
|
|
|
|
|
|
local xml="$1"
|
|
|
|
local platform compat
|
|
|
|
|
|
|
|
platform=$(getPlatform "$xml")
|
|
|
|
|
|
|
|
case "${platform,,}" in
|
|
|
|
"x86" ) compat="x64" ;;
|
|
|
|
"x64" ) compat="$platform" ;;
|
|
|
|
"arm64" ) compat="$platform" ;;
|
|
|
|
* ) compat="${PLATFORM,,}" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
[[ "${compat,,}" == "${PLATFORM,,}" ]] && return 0
|
|
|
|
|
|
|
|
error "You cannot boot ${platform^^} images on a $PLATFORM CPU!"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
hasVersion() {
|
|
|
|
|
|
|
|
local id="$1"
|
|
|
|
local tag="$2"
|
|
|
|
local xml="$3"
|
|
|
|
local edition
|
|
|
|
|
|
|
|
[ ! -f "/run/assets/$id.xml" ] && return 1
|
|
|
|
|
|
|
|
edition=$(printEdition "$id" "")
|
|
|
|
[ -z "$edition" ] && return 1
|
|
|
|
[[ "${xml,,}" != *"<${tag,,}>${edition,,}</${tag,,}>"* ]] && return 1
|
|
|
|
|
|
|
|
return 0
|
2024-05-04 11:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
selectVersion() {
|
|
|
|
|
|
|
|
local tag="$1"
|
|
|
|
local xml="$2"
|
2024-05-07 00:11:59 +00:00
|
|
|
local platform="$3"
|
2024-05-10 16:21:41 +00:00
|
|
|
local id name prefer
|
2024-05-04 11:28:12 +00:00
|
|
|
|
|
|
|
name=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$xml")
|
|
|
|
[[ "$name" == *"Operating System"* ]] && name=""
|
|
|
|
[ -z "$name" ] && return 0
|
|
|
|
|
2024-05-07 00:11:59 +00:00
|
|
|
id=$(fromName "$name" "$platform")
|
2024-05-04 11:28:12 +00:00
|
|
|
[ -z "$id" ] && warn "Unknown ${tag,,}: '$name'" && return 0
|
|
|
|
|
|
|
|
prefer="$id-enterprise"
|
2024-05-10 16:21:41 +00:00
|
|
|
hasVersion "$prefer" "$tag" "$xml" && echo "$prefer" && return 0
|
2024-05-04 11:28:12 +00:00
|
|
|
|
|
|
|
prefer="$id-ultimate"
|
2024-05-10 16:21:41 +00:00
|
|
|
hasVersion "$prefer" "$tag" "$xml" && echo "$prefer" && return 0
|
2024-05-04 11:28:12 +00:00
|
|
|
|
|
|
|
prefer="$id"
|
2024-05-10 16:21:41 +00:00
|
|
|
hasVersion "$prefer" "$tag" "$xml" && echo "$prefer" && return 0
|
2024-05-04 11:28:12 +00:00
|
|
|
|
2024-05-07 00:11:59 +00:00
|
|
|
prefer=$(getVersion "$name" "$platform")
|
2024-05-04 11:28:12 +00:00
|
|
|
|
|
|
|
echo "$prefer"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
detectVersion() {
|
|
|
|
|
|
|
|
local xml="$1"
|
|
|
|
local id platform
|
|
|
|
|
|
|
|
platform=$(getPlatform "$xml")
|
2024-05-09 09:19:34 +00:00
|
|
|
id=$(selectVersion "DISPLAYNAME" "$xml" "$platform")
|
|
|
|
[ -z "$id" ] && id=$(selectVersion "PRODUCTNAME" "$xml" "$platform")
|
|
|
|
[ -z "$id" ] && id=$(selectVersion "NAME" "$xml" "$platform")
|
2024-05-04 11:28:12 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
echo "$id"
|
2024-01-22 19:44:38 +00:00
|
|
|
return 0
|
2024-01-24 04:38:16 +00:00
|
|
|
}
|
2024-01-15 22:45:35 +00:00
|
|
|
|
2024-05-18 14:33:12 +00:00
|
|
|
detectLanguage() {
|
|
|
|
|
|
|
|
local xml="$1"
|
|
|
|
local lang=""
|
|
|
|
|
|
|
|
if [[ "$xml" == *"LANGUAGE><DEFAULT>"* ]]; then
|
|
|
|
lang="${xml#*LANGUAGE><DEFAULT>}"
|
|
|
|
lang="${lang%%<*}"
|
|
|
|
else
|
|
|
|
if [[ "$xml" == *"FALLBACK><DEFAULT>"* ]]; then
|
|
|
|
lang="${xml#*FALLBACK><DEFAULT>}"
|
|
|
|
lang="${lang%%<*}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$lang" ]; then
|
|
|
|
warn "Language could not be detected from ISO!" && return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
local culture
|
|
|
|
culture=$(getLanguage "$lang" "culture")
|
|
|
|
[ -n "$culture" ] && LANGUAGE="$lang" && return 0
|
|
|
|
|
|
|
|
warn "Invalid language detected: \"$lang\""
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
setXML() {
|
|
|
|
|
|
|
|
local file="/custom.xml"
|
2024-05-27 10:40:19 +00:00
|
|
|
|
2024-05-18 14:33:12 +00:00
|
|
|
[ ! -f "$file" ] || [ ! -s "$file" ] && file="$STORAGE/custom.xml"
|
|
|
|
[ ! -f "$file" ] || [ ! -s "$file" ] && file="/run/assets/custom.xml"
|
|
|
|
[ ! -f "$file" ] || [ ! -s "$file" ] && file="$1"
|
|
|
|
[ ! -f "$file" ] || [ ! -s "$file" ] && file="/run/assets/$DETECTED.xml"
|
|
|
|
[ ! -f "$file" ] || [ ! -s "$file" ] && return 1
|
|
|
|
|
|
|
|
XML="$file"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-01-25 15:15:18 +00:00
|
|
|
detectImage() {
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-02-01 13:16:54 +00:00
|
|
|
local dir="$1"
|
2024-05-04 11:28:12 +00:00
|
|
|
local version="$2"
|
2024-05-27 10:40:19 +00:00
|
|
|
local desc msg find language
|
2024-05-04 11:28:12 +00:00
|
|
|
|
|
|
|
XML=""
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-05-09 09:19:34 +00:00
|
|
|
if [ -z "$DETECTED" ] && [ -z "$CUSTOM" ]; then
|
|
|
|
[[ "${version,,}" != "http"* ]] && DETECTED="$version"
|
2024-01-26 21:11:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$DETECTED" ]; then
|
2024-01-27 13:52:58 +00:00
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
skipVersion "${DETECTED,,}" && return 0
|
2024-02-01 13:16:54 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
if ! setXML "" && [[ "$MANUAL" != [Yy1]* ]]; then
|
|
|
|
MANUAL="Y"
|
|
|
|
desc=$(printEdition "$DETECTED" "this version")
|
|
|
|
warn "the answer file for $desc was not found ($DETECTED.xml), $FB."
|
|
|
|
fi
|
2024-01-27 13:52:58 +00:00
|
|
|
|
2024-01-25 15:15:18 +00:00
|
|
|
return 0
|
2024-01-24 04:38:16 +00:00
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
info "Detecting version from ISO image..."
|
2024-05-28 14:39:57 +00:00
|
|
|
|
|
|
|
if detectLegacy "$dir"; then
|
|
|
|
desc=$(printEdition "$DETECTED" "$DETECTED")
|
|
|
|
info "Detected: $desc"
|
|
|
|
return 0
|
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
local src wim info
|
2024-02-16 13:43:03 +00:00
|
|
|
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
|
2024-02-16 13:38:00 +00:00
|
|
|
|
|
|
|
if [ ! -d "$src" ]; then
|
2024-04-24 18:16:43 +00:00
|
|
|
warn "failed to locate 'sources' folder in ISO image, $FB" && return 1
|
2024-02-16 13:38:00 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
wim=$(find "$src" -maxdepth 1 -type f -iname install.wim | head -n 1)
|
|
|
|
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1)
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
if [ ! -f "$wim" ]; then
|
2024-04-24 18:16:43 +00:00
|
|
|
warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1
|
2024-01-24 04:38:16 +00:00
|
|
|
fi
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
info=$(wimlib-imagex info -xml "$wim" | tr -d '\000')
|
2024-05-10 16:21:41 +00:00
|
|
|
! checkPlatform "$info" && exit 67
|
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
DETECTED=$(detectVersion "$info")
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-01-25 15:15:18 +00:00
|
|
|
if [ -z "$DETECTED" ]; then
|
2024-05-04 11:28:12 +00:00
|
|
|
msg="Failed to determine Windows version from image"
|
2024-05-10 16:21:41 +00:00
|
|
|
if setXML "" || [[ "$MANUAL" == [Yy1]* ]]; then
|
|
|
|
info "${msg}!"
|
|
|
|
else
|
|
|
|
MANUAL="Y"
|
|
|
|
warn "${msg}, $FB."
|
|
|
|
fi
|
|
|
|
return 0
|
2024-01-24 04:38:16 +00:00
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
desc=$(printEdition "$DETECTED" "$DETECTED")
|
2024-05-18 14:33:12 +00:00
|
|
|
detectLanguage "$info"
|
|
|
|
|
|
|
|
if [[ "${LANGUAGE,,}" != "en" ]] && [[ "${LANGUAGE,,}" != "en-"* ]]; then
|
|
|
|
language=$(getLanguage "$LANGUAGE" "desc")
|
|
|
|
desc="$desc ($language)"
|
|
|
|
fi
|
2024-01-22 01:56:28 +00:00
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
info "Detected: $desc"
|
|
|
|
setXML "" && return 0
|
2024-01-24 04:38:16 +00:00
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
msg="the answer file for $desc was not found ($DETECTED.xml)"
|
|
|
|
local fallback="/run/assets/${DETECTED%%-*}.xml"
|
2024-01-15 22:45:35 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
if setXML "$fallback" || [[ "$MANUAL" == [Yy1]* ]]; then
|
|
|
|
[[ "$MANUAL" != [Yy1]* ]] && warn "${msg}."
|
|
|
|
else
|
|
|
|
MANUAL="Y"
|
|
|
|
warn "${msg}, $FB."
|
|
|
|
fi
|
2024-05-05 19:24:47 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
return 0
|
|
|
|
}
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-02-01 13:16:54 +00:00
|
|
|
prepareImage() {
|
|
|
|
|
|
|
|
local iso="$1"
|
|
|
|
local dir="$2"
|
2024-05-27 23:00:16 +00:00
|
|
|
local desc missing
|
|
|
|
|
|
|
|
desc=$(printVersion "$DETECTED" "$DETECTED")
|
2024-05-04 11:28:12 +00:00
|
|
|
|
2024-05-28 14:39:57 +00:00
|
|
|
! setMachine "$DETECTED" "$iso" "$dir" "$desc" && return 1
|
|
|
|
skipVersion "$DETECTED" && return 0
|
2024-05-27 10:40:19 +00:00
|
|
|
|
2024-03-13 09:20:18 +00:00
|
|
|
if [[ "${BOOT_MODE,,}" != "windows_legacy" ]]; then
|
2024-02-01 13:16:54 +00:00
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
[ -f "$dir/$ETFS" ] && [ -f "$dir/$EFISYS" ] && return 0
|
2024-02-01 13:16:54 +00:00
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
missing=$(basename "$dir/$EFISYS")
|
|
|
|
[ ! -f "$dir/$ETFS" ] && missing=$(basename "$dir/$ETFS")
|
2024-02-01 13:16:54 +00:00
|
|
|
|
2024-05-28 14:39:57 +00:00
|
|
|
error "Failed to locate file \"${missing,,}\" in ISO image!"
|
2024-05-27 10:40:19 +00:00
|
|
|
return 1
|
2024-02-01 13:16:54 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-27 23:00:16 +00:00
|
|
|
prepareLegacy "$iso" "$dir" "$desc" && return 0
|
2024-04-30 20:57:44 +00:00
|
|
|
|
2024-05-28 14:39:57 +00:00
|
|
|
error "Failed to extract boot image from ISO image!"
|
2024-05-04 11:28:12 +00:00
|
|
|
return 1
|
2024-02-01 13:16:54 +00:00
|
|
|
}
|
|
|
|
|
2024-05-18 14:33:12 +00:00
|
|
|
updateXML() {
|
|
|
|
|
|
|
|
local asset="$1"
|
|
|
|
local language="$2"
|
2024-05-22 22:16:02 +00:00
|
|
|
local culture region user admin pass keyboard
|
2024-05-18 14:33:12 +00:00
|
|
|
|
|
|
|
culture=$(getLanguage "$language" "culture")
|
|
|
|
|
|
|
|
if [ -n "$culture" ] && [[ "${culture,,}" != "en-us" ]]; then
|
|
|
|
sed -i "s/<UILanguage>en-US<\/UILanguage>/<UILanguage>$culture<\/UILanguage>/g" "$asset"
|
|
|
|
fi
|
|
|
|
|
|
|
|
region="$REGION"
|
|
|
|
[ -z "$region" ] && region="$culture"
|
|
|
|
|
|
|
|
if [ -n "$region" ] && [[ "${region,,}" != "en-us" ]]; then
|
|
|
|
sed -i "s/<UserLocale>en-US<\/UserLocale>/<UserLocale>$region<\/UserLocale>/g" "$asset"
|
|
|
|
sed -i "s/<SystemLocale>en-US<\/SystemLocale>/<SystemLocale>$region<\/SystemLocale>/g" "$asset"
|
|
|
|
fi
|
|
|
|
|
|
|
|
keyboard="$KEYBOARD"
|
|
|
|
[ -z "$keyboard" ] && keyboard="$culture"
|
|
|
|
|
|
|
|
if [ -n "$keyboard" ] && [[ "${keyboard,,}" != "en-us" ]]; then
|
|
|
|
sed -i "s/<InputLocale>en-US<\/InputLocale>/<InputLocale>$keyboard<\/InputLocale>/g" "$asset"
|
|
|
|
sed -i "s/<InputLocale>0409:00000409<\/InputLocale>/<InputLocale>$keyboard<\/InputLocale>/g" "$asset"
|
|
|
|
fi
|
|
|
|
|
2024-05-22 22:16:02 +00:00
|
|
|
user=$(echo "$USERNAME" | sed 's/[^[:alnum:]@!._-]//g')
|
|
|
|
|
|
|
|
if [ -n "$user" ]; then
|
|
|
|
sed -i "s/<Name>Docker<\/Name>/<Name>$user<\/Name>/g" "$asset"
|
|
|
|
sed -i "s/where name=\"Docker\"/where name=\"$user\"/g" "$asset"
|
|
|
|
sed -i "s/<FullName>Docker<\/FullName>/<FullName>$user<\/FullName>/g" "$asset"
|
|
|
|
sed -i "s/<Username>Docker<\/Username>/<Username>$user<\/Username>/g" "$asset"
|
2024-05-18 14:33:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$PASSWORD" ]; then
|
2024-05-22 22:16:02 +00:00
|
|
|
pass=$(printf '%s' "${PASSWORD}Password" | iconv -f utf-8 -t utf-16le | base64 -w 0)
|
|
|
|
admin=$(printf '%s' "${PASSWORD}AdministratorPassword" | iconv -f utf-8 -t utf-16le | base64 -w 0)
|
2024-05-19 18:12:59 +00:00
|
|
|
sed -i "s/<Value>password<\/Value>/<Value>$admin<\/Value>/g" "$asset"
|
|
|
|
sed -i "s/<PlainText>true<\/PlainText>/<PlainText>false<\/PlainText>/g" "$asset"
|
|
|
|
sed -z "s/<Password>...........<Value \/>/<Password>\n <Value>$pass<\/Value>/g" -i "$asset"
|
|
|
|
sed -z "s/<Password>...............<Value \/>/<Password>\n <Value>$pass<\/Value>/g" -i "$asset"
|
|
|
|
sed -z "s/<AdministratorPassword>...........<Value \/>/<AdministratorPassword>\n <Value>$admin<\/Value>/g" -i "$asset"
|
|
|
|
sed -z "s/<AdministratorPassword>...............<Value \/>/<AdministratorPassword>\n <Value>$admin<\/Value>/g" -i "$asset"
|
2024-05-18 14:33:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
addDriver() {
|
|
|
|
|
|
|
|
local id="$1"
|
|
|
|
local path="$2"
|
|
|
|
local target="$3"
|
|
|
|
local driver="$4"
|
|
|
|
local folder=""
|
|
|
|
|
|
|
|
case "${id,,}" in
|
|
|
|
"win7x86"* ) folder="w7/x86" ;;
|
|
|
|
"win7x64"* ) folder="w7/amd64" ;;
|
2024-05-29 19:54:08 +00:00
|
|
|
"win81x64"* ) folder="w8.1/amd64" ;;
|
2024-05-27 10:40:19 +00:00
|
|
|
"win10x64"* ) folder="w10/amd64" ;;
|
|
|
|
"win11x64"* ) folder="w11/amd64" ;;
|
2024-05-27 23:00:16 +00:00
|
|
|
"win2025"* ) folder="2k22/amd64" ;;
|
2024-05-27 10:40:19 +00:00
|
|
|
"win2022"* ) folder="2k22/amd64" ;;
|
|
|
|
"win2019"* ) folder="2k19/amd64" ;;
|
|
|
|
"win2016"* ) folder="2k16/amd64" ;;
|
2024-05-29 19:54:08 +00:00
|
|
|
"win2012"* ) folder="2k12R2/amd64" ;;
|
2024-05-27 10:40:19 +00:00
|
|
|
"win2008"* ) folder="2k8R2/amd64" ;;
|
|
|
|
"win10arm64"* ) folder="w10/ARM64" ;;
|
|
|
|
"win11arm64"* ) folder="w11/ARM64" ;;
|
|
|
|
"winvistax86"* ) folder="2k8/x86" ;;
|
|
|
|
"winvistax64"* ) folder="2k8/amd64" ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ -z "$folder" ]; then
|
|
|
|
warn "no \"$driver\" driver found for \"$DETECTED\" !" && return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ ! -d "$path/$driver/$folder" ] && return 0
|
|
|
|
|
|
|
|
if [[ "${id,,}" == "winvista"* ]]; then
|
|
|
|
[[ "${driver,,}" == "viorng" ]] && return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
local dest="$path/$target/$driver"
|
|
|
|
mv "$path/$driver/$folder" "$dest"
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
addDrivers() {
|
|
|
|
|
|
|
|
local file="$1"
|
|
|
|
local index="$2"
|
|
|
|
local version="$3"
|
|
|
|
|
|
|
|
local msg="Adding drivers to image..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
|
|
|
local drivers="$TMP/drivers"
|
|
|
|
mkdir -p "$drivers"
|
|
|
|
|
|
|
|
if ! tar -xf /drivers.txz -C "$drivers" --warning=no-timestamp; then
|
|
|
|
error "Failed to extract driver!" && return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local target="\$WinPEDriver\$"
|
|
|
|
local dest="$drivers/$target"
|
|
|
|
mkdir -p "$dest"
|
|
|
|
|
|
|
|
wimlib-imagex update "$file" "$index" --command "delete --force --recursive /$target" >/dev/null || true
|
|
|
|
|
|
|
|
addDriver "$version" "$drivers" "$target" "qxl"
|
|
|
|
addDriver "$version" "$drivers" "$target" "viofs"
|
|
|
|
addDriver "$version" "$drivers" "$target" "sriov"
|
|
|
|
addDriver "$version" "$drivers" "$target" "smbus"
|
|
|
|
addDriver "$version" "$drivers" "$target" "qxldod"
|
|
|
|
addDriver "$version" "$drivers" "$target" "viorng"
|
|
|
|
addDriver "$version" "$drivers" "$target" "viostor"
|
|
|
|
addDriver "$version" "$drivers" "$target" "NetKVM"
|
|
|
|
addDriver "$version" "$drivers" "$target" "Balloon"
|
|
|
|
addDriver "$version" "$drivers" "$target" "vioscsi"
|
|
|
|
addDriver "$version" "$drivers" "$target" "pvpanic"
|
|
|
|
addDriver "$version" "$drivers" "$target" "vioinput"
|
|
|
|
addDriver "$version" "$drivers" "$target" "viogpudo"
|
|
|
|
addDriver "$version" "$drivers" "$target" "vioserial"
|
|
|
|
addDriver "$version" "$drivers" "$target" "qemupciserial"
|
|
|
|
|
|
|
|
if ! wimlib-imagex update "$file" "$index" --command "add $dest /$target" >/dev/null; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf "$drivers"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
addFolder() {
|
|
|
|
|
|
|
|
local src="$1"
|
|
|
|
local folder="/oem"
|
|
|
|
|
|
|
|
[ ! -d "$folder" ] && folder="/OEM"
|
|
|
|
[ ! -d "$folder" ] && folder="$STORAGE/oem"
|
|
|
|
[ ! -d "$folder" ] && folder="$STORAGE/OEM"
|
|
|
|
[ ! -d "$folder" ] && return 0
|
|
|
|
|
|
|
|
local msg="Adding OEM folder to image..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
|
|
|
local dest="$src/\$OEM\$/\$1/"
|
|
|
|
mkdir -p "$dest"
|
|
|
|
|
|
|
|
! cp -r "$folder" "$dest" && return 1
|
|
|
|
|
|
|
|
local file
|
|
|
|
file=$(find "$dest" -maxdepth 1 -type f -iname install.bat | head -n 1)
|
|
|
|
[ -f "$file" ] && unix2dos -q "$file"
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
updateImage() {
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
local dir="$1"
|
|
|
|
local asset="$2"
|
2024-05-18 14:33:12 +00:00
|
|
|
local language="$3"
|
2024-05-10 16:21:41 +00:00
|
|
|
local file="autounattend.xml"
|
2024-05-21 22:53:19 +00:00
|
|
|
local org="${file//.xml/.org}"
|
|
|
|
local dat="${file//.xml/.dat}"
|
2024-05-27 10:40:19 +00:00
|
|
|
local desc path src wim xml index result
|
2024-05-10 16:21:41 +00:00
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
skipVersion "${DETECTED,,}" && return 0
|
2024-05-16 05:23:29 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
if [ ! -s "$asset" ] || [ ! -f "$asset" ]; then
|
|
|
|
asset=""
|
|
|
|
if [[ "$MANUAL" != [Yy1]* ]]; then
|
|
|
|
MANUAL="Y"
|
|
|
|
warn "no answer file provided, $FB."
|
|
|
|
fi
|
|
|
|
fi
|
2024-02-16 13:38:00 +00:00
|
|
|
|
2024-02-16 13:43:03 +00:00
|
|
|
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
|
2024-02-16 13:38:00 +00:00
|
|
|
|
|
|
|
if [ ! -d "$src" ]; then
|
2024-05-27 10:40:19 +00:00
|
|
|
error "failed to locate 'sources' folder in ISO image, $FB" && return 1
|
2024-02-16 13:38:00 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
wim=$(find "$src" -maxdepth 1 -type f -iname boot.wim | head -n 1)
|
|
|
|
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1)
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
if [ ! -f "$wim" ]; then
|
|
|
|
error "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1
|
2024-01-24 04:38:16 +00:00
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-01-24 04:54:26 +00:00
|
|
|
index="1"
|
2024-05-27 10:40:19 +00:00
|
|
|
result=$(wimlib-imagex info -xml "$wim" | tr -d '\000')
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
if [[ "${result^^}" == *"<IMAGE INDEX=\"2\">"* ]]; then
|
|
|
|
index="2"
|
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
if ! addDrivers "$wim" "$index" "$DETECTED"; then
|
|
|
|
error "Failed to add drivers to image!" && return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! addFolder "$src"; then
|
|
|
|
error "Failed to add OEM folder to image!" && return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if wimlib-imagex extract "$wim" "$index" "/$file" "--dest-dir=$TMP" >/dev/null 2>&1; then
|
|
|
|
if ! wimlib-imagex extract "$wim" "$index" "/$dat" "--dest-dir=$TMP" >/dev/null 2>&1; then
|
|
|
|
if ! wimlib-imagex extract "$wim" "$index" "/$org" "--dest-dir=$TMP" >/dev/null 2>&1; then
|
|
|
|
if ! wimlib-imagex update "$wim" "$index" --command "rename /$file /$org" > /dev/null; then
|
2024-05-10 16:21:41 +00:00
|
|
|
warn "failed to backup original answer file ($file)."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
rm -f "$TMP/$dat"
|
|
|
|
rm -f "$TMP/$org"
|
|
|
|
rm -f "$TMP/$file"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$MANUAL" != [Yy1]* ]]; then
|
|
|
|
|
|
|
|
xml=$(basename "$asset")
|
|
|
|
info "Adding $xml for automatic installation..."
|
|
|
|
|
2024-05-18 14:33:12 +00:00
|
|
|
local answer="$TMP/$xml"
|
|
|
|
cp "$asset" "$answer"
|
|
|
|
updateXML "$answer" "$language"
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
if ! wimlib-imagex update "$wim" "$index" --command "add $answer /$file" > /dev/null; then
|
2024-05-10 16:21:41 +00:00
|
|
|
MANUAL="Y"
|
|
|
|
warn "failed to add answer file ($xml) to ISO image, $FB"
|
|
|
|
else
|
2024-05-27 10:40:19 +00:00
|
|
|
wimlib-imagex update "$wim" "$index" --command "add $answer /$dat" > /dev/null || true
|
2024-05-10 16:21:41 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-18 14:33:12 +00:00
|
|
|
rm -f "$answer"
|
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$MANUAL" == [Yy1]* ]]; then
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
wimlib-imagex update "$wim" "$index" --command "delete --force /$file" > /dev/null || true
|
2024-05-10 16:21:41 +00:00
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
if wimlib-imagex extract "$wim" "$index" "/$org" "--dest-dir=$TMP" >/dev/null 2>&1; then
|
|
|
|
if ! wimlib-imagex update "$wim" "$index" --command "add $TMP/$org /$file" > /dev/null; then
|
2024-05-10 16:21:41 +00:00
|
|
|
warn "failed to restore original answer file ($org)."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-05-18 14:33:12 +00:00
|
|
|
rm -f "$TMP/$org"
|
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
local find="$file"
|
|
|
|
[[ "$MANUAL" == [Yy1]* ]] && find="$org"
|
|
|
|
path=$(find "$dir" -maxdepth 1 -type f -iname "$find" | head -n 1)
|
|
|
|
|
|
|
|
if [ -f "$path" ]; then
|
|
|
|
if [[ "$MANUAL" != [Yy1]* ]]; then
|
|
|
|
mv -f "$path" "${path%.*}.org"
|
|
|
|
else
|
|
|
|
mv -f "$path" "${path%.*}.xml"
|
|
|
|
fi
|
2024-01-25 15:15:18 +00:00
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
removeImage() {
|
2024-05-18 14:33:12 +00:00
|
|
|
|
|
|
|
local iso="$1"
|
|
|
|
|
|
|
|
[ ! -f "$iso" ] && return 0
|
|
|
|
[ -n "$CUSTOM" ] && return 0
|
|
|
|
! rm -f "$iso" 2> /dev/null && warn "failed to remove $iso !"
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
buildImage() {
|
|
|
|
|
|
|
|
local dir="$1"
|
2024-05-27 10:40:19 +00:00
|
|
|
local failed=""
|
2024-01-24 04:38:16 +00:00
|
|
|
local cat="BOOT.CAT"
|
2024-01-25 15:15:18 +00:00
|
|
|
local log="/run/shm/iso.log"
|
2024-05-05 19:24:47 +00:00
|
|
|
local base size size_gb space space_gb desc
|
2024-01-24 04:54:26 +00:00
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
if [ -f "$BOOT" ]; then
|
|
|
|
error "File $BOOT does already exist?!" && return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
base=$(basename "$BOOT")
|
|
|
|
local out="$TMP/${base%.*}.tmp"
|
2024-01-24 04:38:16 +00:00
|
|
|
rm -f "$out"
|
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
desc=$(printVersion "$DETECTED" "ISO")
|
2024-01-27 13:52:58 +00:00
|
|
|
|
|
|
|
local msg="Building $desc image..."
|
2024-01-24 04:38:16 +00:00
|
|
|
info "$msg" && html "$msg"
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-05-28 14:39:57 +00:00
|
|
|
[ -z "$LABEL" ] && LABEL="Windows"
|
|
|
|
|
|
|
|
if [ ! -f "$dir/$ETFS" ]; then
|
|
|
|
error "Failed to locate file \"$ETFS\" in ISO image!" && return 1
|
|
|
|
fi
|
|
|
|
|
2024-01-24 04:54:26 +00:00
|
|
|
size=$(du -h -b --max-depth=0 "$dir" | cut -f1)
|
|
|
|
size_gb=$(( (size + 1073741823)/1073741824 ))
|
|
|
|
space=$(df --output=avail -B 1 "$TMP" | tail -n 1)
|
|
|
|
space_gb=$(( (space + 1073741823)/1073741824 ))
|
2024-01-24 04:38:16 +00:00
|
|
|
|
|
|
|
if (( size > space )); then
|
2024-04-24 18:16:43 +00:00
|
|
|
error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1
|
2024-01-25 15:15:18 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${BOOT_MODE,,}" != "windows_legacy" ]]; then
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -c "$cat" -iso-level 4 -J -l -D -N -joliet-long -relaxed-filenames -V "${LABEL::30}" \
|
|
|
|
-udf -boot-info-table -eltorito-alt-boot -eltorito-boot "$EFISYS" -no-emul-boot -allow-limited-size -quiet "$dir" 2> "$log" && failed="y"
|
2024-01-25 15:15:18 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
case "${DETECTED,,}" in
|
2024-05-27 23:00:16 +00:00
|
|
|
"win2k"* | "winxp"* | "win2003"* )
|
2024-05-27 10:40:19 +00:00
|
|
|
! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -boot-load-seg 1984 -boot-load-size 4 -c "$cat" -iso-level 2 -J -l -D -N -joliet-long \
|
|
|
|
-relaxed-filenames -V "${LABEL::30}" -quiet "$dir" 2> "$log" && failed="y" ;;
|
|
|
|
"win9"* )
|
|
|
|
! genisoimage -o "$out" -b "$ETFS" -J -r -V "${LABEL::30}" -quiet "$dir" 2> "$log" && failed="y" ;;
|
|
|
|
* )
|
|
|
|
! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -c "$cat" -iso-level 2 -J -l -D -N -joliet-long -relaxed-filenames -V "${LABEL::30}" \
|
|
|
|
-udf -allow-limited-size -quiet "$dir" 2> "$log" && failed="y" ;;
|
|
|
|
esac
|
2024-02-01 13:16:54 +00:00
|
|
|
|
2024-01-22 19:44:38 +00:00
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
if [ -n "$failed" ]; then
|
2024-04-24 18:16:43 +00:00
|
|
|
[ -s "$log" ] && echo "$(<"$log")"
|
|
|
|
error "Failed to build image!" && return 1
|
|
|
|
fi
|
|
|
|
|
2024-01-25 15:15:18 +00:00
|
|
|
local error=""
|
|
|
|
local hide="Warning: creating filesystem that does not conform to ISO-9660."
|
2024-01-24 04:38:16 +00:00
|
|
|
|
2024-04-16 14:22:28 +00:00
|
|
|
[ -s "$log" ] && error="$(<"$log")"
|
2024-01-25 15:15:18 +00:00
|
|
|
[[ "$error" != "$hide" ]] && echo "$error"
|
2024-01-24 04:38:16 +00:00
|
|
|
|
2024-05-10 16:21:41 +00:00
|
|
|
! mv -f "$out" "$BOOT" && return 1
|
2024-01-24 04:38:16 +00:00
|
|
|
return 0
|
|
|
|
}
|
2024-01-22 01:56:28 +00:00
|
|
|
|
2024-04-19 23:45:13 +00:00
|
|
|
bootWindows() {
|
2024-01-25 15:15:18 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
rm -rf "$TMP"
|
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
[[ "${PLATFORM,,}" == "arm64" ]] && VGA="virtio-gpu"
|
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
if [ -s "$STORAGE/windows.type" ] && [ -f "$STORAGE/windows.type" ]; then
|
|
|
|
DISK_TYPE=$(<"$STORAGE/windows.type")
|
|
|
|
fi
|
|
|
|
|
2024-04-27 16:46:09 +00:00
|
|
|
if [ -s "$STORAGE/windows.mode" ] && [ -f "$STORAGE/windows.mode" ]; then
|
|
|
|
BOOT_MODE=$(<"$STORAGE/windows.mode")
|
|
|
|
if [ -s "$STORAGE/windows.old" ] && [ -f "$STORAGE/windows.old" ]; then
|
2024-04-30 20:57:44 +00:00
|
|
|
[[ "${PLATFORM,,}" == "x64" ]] && MACHINE=$(<"$STORAGE/windows.old")
|
2024-04-27 16:46:09 +00:00
|
|
|
fi
|
2024-04-22 13:50:01 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2024-04-27 16:46:09 +00:00
|
|
|
# Migrations
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
[[ "${PLATFORM,,}" != "x64" ]] && return 0
|
|
|
|
|
2024-04-27 16:46:09 +00:00
|
|
|
if [ -f "$STORAGE/windows.old" ]; then
|
|
|
|
MACHINE=$(<"$STORAGE/windows.old")
|
|
|
|
[ -z "$MACHINE" ] && MACHINE="q35"
|
|
|
|
BOOT_MODE="windows_legacy"
|
|
|
|
echo "$BOOT_MODE" > "$STORAGE/windows.mode"
|
2024-04-22 13:50:01 +00:00
|
|
|
return 0
|
2024-01-25 15:15:18 +00:00
|
|
|
fi
|
|
|
|
|
2024-04-19 23:45:13 +00:00
|
|
|
local creation="1.10"
|
|
|
|
local minimal="2.14"
|
|
|
|
|
|
|
|
if [ -f "$STORAGE/windows.ver" ]; then
|
|
|
|
creation=$(<"$STORAGE/windows.ver")
|
|
|
|
[[ "${creation}" != *"."* ]] && creation="$minimal"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Force secure boot on installs created prior to v2.14
|
|
|
|
if (( $(echo "$creation < $minimal" | bc -l) )); then
|
|
|
|
if [[ "${BOOT_MODE,,}" == "windows" ]]; then
|
|
|
|
BOOT_MODE="windows_secure"
|
2024-04-22 13:50:01 +00:00
|
|
|
echo "$BOOT_MODE" > "$STORAGE/windows.mode"
|
2024-04-19 23:45:13 +00:00
|
|
|
if [ -f "$STORAGE/windows.rom" ] && [ ! -f "$STORAGE/$BOOT_MODE.rom" ]; then
|
2024-05-10 16:21:41 +00:00
|
|
|
mv -f "$STORAGE/windows.rom" "$STORAGE/$BOOT_MODE.rom"
|
2024-04-19 23:45:13 +00:00
|
|
|
fi
|
|
|
|
if [ -f "$STORAGE/windows.vars" ] && [ ! -f "$STORAGE/$BOOT_MODE.vars" ]; then
|
2024-05-10 16:21:41 +00:00
|
|
|
mv -f "$STORAGE/windows.vars" "$STORAGE/$BOOT_MODE.vars"
|
2024-04-19 23:45:13 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
! parseVersion && exit 58
|
2024-05-18 14:33:12 +00:00
|
|
|
! parseLanguage && exit 56
|
2024-04-30 20:57:44 +00:00
|
|
|
! detectCustom && exit 59
|
|
|
|
|
2024-04-19 23:45:13 +00:00
|
|
|
if ! startInstall; then
|
2024-04-24 18:16:43 +00:00
|
|
|
bootWindows && return 0
|
|
|
|
exit 68
|
2024-01-22 01:56:28 +00:00
|
|
|
fi
|
2024-01-19 03:28:03 +00:00
|
|
|
|
2024-04-18 22:00:17 +00:00
|
|
|
if [ ! -s "$ISO" ] || [ ! -f "$ISO" ]; then
|
2024-05-18 14:33:12 +00:00
|
|
|
if ! downloadImage "$ISO" "$VERSION" "$LANGUAGE"; then
|
2024-04-30 20:57:44 +00:00
|
|
|
rm -f "$ISO" 2> /dev/null || true
|
2024-01-25 15:15:18 +00:00
|
|
|
exit 61
|
|
|
|
fi
|
2024-01-24 04:38:16 +00:00
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if ! extractImage "$ISO" "$DIR" "$VERSION"; then
|
|
|
|
rm -f "$ISO" 2> /dev/null || true
|
2024-04-24 18:16:43 +00:00
|
|
|
exit 62
|
2024-01-25 15:15:18 +00:00
|
|
|
fi
|
2024-01-22 01:56:28 +00:00
|
|
|
|
2024-05-04 11:28:12 +00:00
|
|
|
if ! detectImage "$DIR" "$VERSION"; then
|
2024-05-27 10:40:19 +00:00
|
|
|
abortInstall "$DIR" "$ISO" && return 0
|
2024-04-24 18:16:43 +00:00
|
|
|
exit 60
|
2024-01-25 15:15:18 +00:00
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-01-25 15:15:18 +00:00
|
|
|
if ! prepareImage "$ISO" "$DIR"; then
|
2024-05-27 10:40:19 +00:00
|
|
|
abortInstall "$DIR" "$ISO" && return 0
|
|
|
|
exit 66
|
2024-01-22 19:44:38 +00:00
|
|
|
fi
|
|
|
|
|
2024-05-18 14:33:12 +00:00
|
|
|
if ! updateImage "$DIR" "$XML" "$LANGUAGE"; then
|
2024-05-27 10:40:19 +00:00
|
|
|
abortInstall "$DIR" "$ISO" && return 0
|
|
|
|
exit 63
|
2024-01-25 15:15:18 +00:00
|
|
|
fi
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-05-27 10:40:19 +00:00
|
|
|
if ! removeImage "$ISO"; then
|
2024-05-05 19:24:47 +00:00
|
|
|
exit 64
|
2024-04-22 13:50:01 +00:00
|
|
|
fi
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-01-25 15:15:18 +00:00
|
|
|
if ! buildImage "$DIR"; then
|
|
|
|
exit 65
|
|
|
|
fi
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-05-05 19:24:47 +00:00
|
|
|
if ! finishInstall "$BOOT" "N"; then
|
2024-04-22 13:50:01 +00:00
|
|
|
exit 69
|
|
|
|
fi
|
2024-01-20 16:03:59 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
html "Successfully prepared image for installation..."
|
2024-01-14 14:19:58 +00:00
|
|
|
return 0
|