2024-01-14 15:39:24 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-01-14 14:19:58 +00:00
|
|
|
set -Eeuo pipefail
|
|
|
|
|
2024-02-04 18:45:32 +00:00
|
|
|
ESD_URL=""
|
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
|
|
|
hasDisk() {
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
[ -b "${DEVICE:-}" ] && return 0
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-04-16 14:22:28 +00:00
|
|
|
if [ -s "$STORAGE/data.img" ] || [ -s "$STORAGE/data.qcow2" ]; then
|
2024-01-24 04:38:16 +00:00
|
|
|
return 0
|
2024-01-22 01:56:28 +00:00
|
|
|
fi
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
return 1
|
|
|
|
}
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
skipInstall() {
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
if hasDisk && [ -f "$STORAGE/windows.boot" ]; then
|
|
|
|
return 0
|
|
|
|
fi
|
2024-01-19 03:28:03 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
return 1
|
|
|
|
}
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
finishInstall() {
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
local iso="$1"
|
2024-04-18 22:00:17 +00:00
|
|
|
local aborted="$2"
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-04-22 13:50:01 +00:00
|
|
|
if [ ! -s "$iso" ] || [ ! -f "$iso" ]; then
|
2024-04-30 20:57:44 +00:00
|
|
|
error "Failed to find ISO file: $iso" && return 1
|
2024-04-22 13:50:01 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -w "$iso" ] && [[ "$aborted" != [Yy1]* ]]; then
|
|
|
|
# Mark ISO as prepared via magic byte
|
|
|
|
if ! printf '\x16' | dd of="$iso" bs=1 seek=0 count=1 conv=notrunc status=none; then
|
2024-04-30 20:57:44 +00:00
|
|
|
error "Failed to set magic byte in ISO file: $iso" && return 1
|
2024-04-22 13:50:01 +00:00
|
|
|
fi
|
|
|
|
fi
|
2024-01-22 01:56:28 +00:00
|
|
|
|
2024-04-27 16:46:09 +00:00
|
|
|
rm -f "$STORAGE/windows.ver"
|
|
|
|
rm -f "$STORAGE/windows.old"
|
2024-01-24 04:38:16 +00:00
|
|
|
rm -f "$STORAGE/windows.boot"
|
2024-04-27 16:46:09 +00:00
|
|
|
rm -f "$STORAGE/windows.mode"
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
cp /run/version "$STORAGE/windows.ver"
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-04-30 20:57:44 +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
|
2024-04-27 16:46:09 +00:00
|
|
|
fi
|
2024-04-22 13:50:01 +00:00
|
|
|
fi
|
2024-04-18 22:00:17 +00:00
|
|
|
fi
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
rm -rf "$TMP"
|
|
|
|
return 0
|
|
|
|
}
|
2024-01-22 01:56:28 +00:00
|
|
|
|
2024-01-25 15:15:18 +00:00
|
|
|
abortInstall() {
|
|
|
|
|
|
|
|
local iso="$1"
|
|
|
|
|
|
|
|
if [[ "$iso" != "$STORAGE/$BASE" ]]; then
|
2024-04-22 13:50:01 +00:00
|
|
|
if ! mv -f "$iso" "$STORAGE/$BASE"; then
|
2024-04-30 20:57:44 +00:00
|
|
|
error "Failed to move ISO file: $iso" && return 1
|
2024-04-22 13:50:01 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
finishInstall "$STORAGE/$BASE" "Y" && return 0
|
2024-01-25 15:15:18 +00:00
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
return 1
|
2024-01-25 15:15:18 +00:00
|
|
|
}
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
startInstall() {
|
2024-01-16 18:58:55 +00:00
|
|
|
|
2024-01-29 04:19:23 +00:00
|
|
|
html "Starting Windows..."
|
2024-01-22 22:31:35 +00:00
|
|
|
|
2024-04-22 13:50:01 +00:00
|
|
|
[ -z "$MANUAL" ] && MANUAL="N"
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
if [ -f "$STORAGE/$CUSTOM" ]; then
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
EXTERNAL="Y"
|
|
|
|
BASE="$CUSTOM"
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
else
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
CUSTOM=""
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if [[ "${VERSION,,}" != "http"* ]]; then
|
2024-01-24 04:38:16 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
EXTERNAL="N"
|
2024-01-24 04:38:16 +00:00
|
|
|
BASE="$VERSION.iso"
|
|
|
|
|
|
|
|
else
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
EXTERNAL="Y"
|
2024-01-24 04:38:16 +00:00
|
|
|
BASE=$(basename "${VERSION%%\?*}")
|
|
|
|
: "${BASE//+/ }"; printf -v BASE '%b' "${_//%/\\x}"
|
|
|
|
BASE=$(echo "$BASE" | sed -e 's/[^A-Za-z0-9._-]/_/g')
|
|
|
|
|
2024-01-22 19:44:38 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
|
|
|
! migrateFiles "$BASE" "$VERSION" && error "Migration failed!" && exit 57
|
|
|
|
fi
|
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
if skipInstall; then
|
|
|
|
[ ! -f "$STORAGE/$BASE" ] && BASE=""
|
2024-04-30 20:57:44 +00:00
|
|
|
[[ "${PLATFORM,,}" == "arm64" ]] && VGA="virtio-gpu"
|
2024-04-24 18:16:43 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
if [ -f "$STORAGE/$BASE" ]; then
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
# Check if the ISO was already processed by our script
|
2024-01-29 04:19:23 +00:00
|
|
|
local magic=""
|
2024-01-24 04:54:26 +00:00
|
|
|
magic=$(dd if="$STORAGE/$BASE" seek=0 bs=1 count=1 status=none | tr -d '\000')
|
2024-01-24 04:38:16 +00:00
|
|
|
magic="$(printf '%s' "$magic" | od -A n -t x1 -v | tr -d ' \n')"
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
if [[ "$magic" == "16" ]]; then
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-04-18 22:00:17 +00:00
|
|
|
if hasDisk || [[ "$MANUAL" == [Yy1]* ]]; then
|
2024-01-24 04:38:16 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2024-01-22 19:44:38 +00:00
|
|
|
|
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
|
|
|
EXTERNAL="Y"
|
|
|
|
CUSTOM="$BASE"
|
2024-01-15 14:15:12 +00:00
|
|
|
|
2024-04-22 13:50:01 +00:00
|
|
|
fi
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-04-13 14:58:04 +00:00
|
|
|
rm -rf "$TMP"
|
2024-01-24 04:38:16 +00:00
|
|
|
mkdir -p "$TMP"
|
2024-01-22 01:56:28 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
if [ ! -f "$STORAGE/$CUSTOM" ]; then
|
|
|
|
CUSTOM=""
|
|
|
|
ISO="$TMP/$BASE"
|
|
|
|
else
|
|
|
|
ISO="$STORAGE/$CUSTOM"
|
2024-01-22 01:56:28 +00:00
|
|
|
fi
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
return 0
|
|
|
|
}
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
detectCustom() {
|
|
|
|
|
|
|
|
CUSTOM=$(find "$STORAGE" -maxdepth 1 -type f -iname windows.iso -printf "%f\n" | head -n 1)
|
|
|
|
[ -z "$CUSTOM" ] && CUSTOM=$(find "$STORAGE" -maxdepth 1 -type f -iname custom.iso -printf "%f\n" | head -n 1)
|
|
|
|
[ -z "$CUSTOM" ] && CUSTOM=$(find "$STORAGE" -maxdepth 1 -type f -iname boot.iso -printf "%f\n" | head -n 1)
|
|
|
|
[ -z "$CUSTOM" ] && CUSTOM=$(find "$STORAGE" -maxdepth 1 -type f -iname custom.img -printf "%f\n" | head -n 1)
|
|
|
|
|
|
|
|
if [ -z "$CUSTOM" ] && [[ "${VERSION,,}" != "http"* ]]; then
|
|
|
|
FN="${VERSION/\/storage\//}"
|
|
|
|
[[ "$FN" == "."* ]] && FN="${FN:1}"
|
|
|
|
CUSTOM=$(find "$STORAGE" -maxdepth 1 -type f -iname "$FN" -printf "%f\n" | head -n 1)
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-02-04 18:45:32 +00:00
|
|
|
getESD() {
|
|
|
|
|
|
|
|
local dir="$1"
|
2024-04-30 20:57:44 +00:00
|
|
|
local version="$2"
|
2024-02-04 18:45:32 +00:00
|
|
|
local winCatalog size
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
case "${version,,}" in
|
2024-04-24 18:16:43 +00:00
|
|
|
"win11${PLATFORM,,}")
|
2024-02-04 18:45:32 +00:00
|
|
|
winCatalog="https://go.microsoft.com/fwlink?linkid=2156292"
|
|
|
|
;;
|
2024-04-24 18:16:43 +00:00
|
|
|
"win10${PLATFORM,,}")
|
2024-02-04 18:45:32 +00:00
|
|
|
winCatalog="https://go.microsoft.com/fwlink/?LinkId=841361"
|
|
|
|
;;
|
|
|
|
*)
|
2024-04-30 20:57:44 +00:00
|
|
|
error "Invalid VERSION specified, value \"$version\" is not recognized!" && return 1
|
2024-02-04 18:45:32 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
local msg="Downloading product information from Microsoft..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
|
|
|
rm -rf "$dir"
|
|
|
|
mkdir -p "$dir"
|
|
|
|
|
|
|
|
local wFile="catalog.cab"
|
2024-04-30 20:57:44 +00:00
|
|
|
local xFile="products.xml"
|
|
|
|
local eFile="esd_edition.xml"
|
|
|
|
local fFile="products_filter.xml"
|
2024-02-04 18:45:32 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
{ wget "$winCatalog" -O "$dir/$wFile" -q; rc=$?; } || :
|
2024-02-04 18:45:32 +00:00
|
|
|
(( rc != 0 )) && error "Failed to download $winCatalog , reason: $rc" && return 1
|
|
|
|
|
|
|
|
cd "$dir"
|
|
|
|
|
|
|
|
if ! cabextract "$wFile" > /dev/null; then
|
|
|
|
cd /run
|
2024-04-30 20:57:44 +00:00
|
|
|
error "Failed to extract $wFile!" && return 1
|
2024-02-04 18:45:32 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd /run
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if [ ! -s "$dir/$xFile" ]; then
|
|
|
|
error "Failed to find $xFile in $wFile!" && return 1
|
2024-02-04 18:45:32 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
local esdLang="en-us"
|
|
|
|
local editionName="Professional"
|
2024-04-24 18:16:43 +00:00
|
|
|
local edQuery='//File[Architecture="'${PLATFORM}'"][Edition="'${editionName}'"]'
|
2024-02-04 18:45:32 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
echo -e '<Catalog>' > "$dir/$fFile"
|
|
|
|
xmllint --nonet --xpath "${edQuery}" "$dir/$xFile" >> "$dir/$fFile" 2>/dev/null
|
|
|
|
echo -e '</Catalog>'>> "$dir/$fFile"
|
|
|
|
xmllint --nonet --xpath '//File[LanguageCode="'${esdLang}'"]' "$dir/$fFile" >"$dir/$eFile"
|
2024-02-04 18:45:32 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
size=$(stat -c%s "$dir/$eFile")
|
2024-02-04 18:45:32 +00:00
|
|
|
if ((size<20)); then
|
2024-04-30 20:57:44 +00:00
|
|
|
error "Failed to find Windows product in $eFile!" && return 1
|
2024-02-04 18:45:32 +00:00
|
|
|
fi
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
ESD_URL=$(xmllint --nonet --xpath '//FilePath' "$dir/$eFile" | sed -E -e 's/<[\/]?FilePath>//g')
|
2024-02-04 18:45:32 +00:00
|
|
|
|
|
|
|
if [ -z "$ESD_URL" ]; then
|
2024-04-30 20:57:44 +00:00
|
|
|
error "Failed to find ESD URL in $eFile!" && return 1
|
2024-02-04 18:45:32 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf "$dir"
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
doMido() {
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
local iso="$1"
|
2024-04-30 20:57:44 +00:00
|
|
|
local version="$2"
|
2024-04-24 18:16:43 +00:00
|
|
|
local desc="$3"
|
|
|
|
local rc
|
2024-01-29 04:19:23 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
rm -f "$iso"
|
2024-04-24 18:16:43 +00:00
|
|
|
rm -f "$iso.PART"
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
local msg="Downloading $desc..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
/run/progress.sh "$iso.PART" "Downloading $desc ([P])..." &
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
cd "$TMP"
|
2024-04-30 20:57:44 +00:00
|
|
|
{ /run/mido.sh "${version,,}"; rc=$?; } || :
|
2024-04-24 18:16:43 +00:00
|
|
|
cd /run
|
2024-01-22 01:56:28 +00:00
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
fKill "progress.sh"
|
|
|
|
|
|
|
|
if (( rc == 0 )) && [ -f "$iso" ]; then
|
|
|
|
if [ "$(stat -c%s "$iso")" -gt 100000000 ]; then
|
|
|
|
html "Download finished successfully..." && return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f "$iso"
|
|
|
|
rm -f "$iso.PART"
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
2024-01-29 06:36:13 +00:00
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
downloadFile() {
|
2024-01-29 06:36:13 +00:00
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
local iso="$1"
|
|
|
|
local url="$2"
|
|
|
|
local desc="$3"
|
2024-04-30 20:57:44 +00:00
|
|
|
local rc progress domain
|
2024-04-24 18:16:43 +00:00
|
|
|
|
|
|
|
rm -f "$iso"
|
|
|
|
|
|
|
|
# Check if running with interactive TTY or redirected to docker log
|
|
|
|
if [ -t 1 ]; then
|
|
|
|
progress="--progress=bar:noscroll"
|
|
|
|
else
|
|
|
|
progress="--progress=dot:giga"
|
2024-01-24 04:38:16 +00:00
|
|
|
fi
|
2024-01-22 01:56:28 +00:00
|
|
|
|
2024-01-29 04:19:23 +00:00
|
|
|
local msg="Downloading $desc..."
|
2024-04-30 20:57:44 +00:00
|
|
|
|
|
|
|
domain=$(echo "$url" | awk -F/ '{print $3}')
|
|
|
|
domain=$(expr "$domain" : '.*\.\(.*\..*\)')
|
|
|
|
[[ "${domain,,}" != *"microsoft.com" ]] && msg="Downloading $desc from $domain..."
|
|
|
|
|
2024-01-29 04:19:23 +00:00
|
|
|
info "$msg" && html "$msg"
|
2024-04-24 18:16:43 +00:00
|
|
|
/run/progress.sh "$iso" "Downloading $desc ([P])..." &
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
{ wget "$url" -O "$iso" -q --show-progress "$progress"; rc=$?; } || :
|
2024-04-24 18:16:43 +00:00
|
|
|
|
|
|
|
fKill "progress.sh"
|
|
|
|
|
|
|
|
if (( rc == 0 )) && [ -f "$iso" ]; then
|
|
|
|
if [ "$(stat -c%s "$iso")" -gt 100000000 ]; then
|
|
|
|
html "Download finished successfully..." && return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f "$iso"
|
|
|
|
error "Failed to download $url , reason: $rc"
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadImage() {
|
|
|
|
|
|
|
|
local iso="$1"
|
2024-04-30 20:57:44 +00:00
|
|
|
local version="$2"
|
|
|
|
local tried="n"
|
|
|
|
local url desc
|
2024-01-29 04:19:23 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if [[ "${version,,}" == "http"* ]]; then
|
2024-01-29 04:19:23 +00:00
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
desc=$(getName "$BASE" "$BASE")
|
2024-04-30 20:57:44 +00:00
|
|
|
downloadFile "$iso" "$version" "$desc" && return 0
|
|
|
|
return 1
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
fi
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if ! validVersion "$version"; then
|
|
|
|
error "Invalid VERSION specified, value \"$version\" is not recognized!" && return 1
|
|
|
|
fi
|
2024-02-04 18:45:32 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
|
|
|
desc=$(printVersion "$version" "Windows")
|
|
|
|
else
|
|
|
|
desc=$(printVersion "$version" "Windows for ${PLATFORM}")
|
|
|
|
fi
|
2024-02-04 18:45:32 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
|
|
|
if isMido "$version"; then
|
|
|
|
tried="y"
|
|
|
|
doMido "$iso" "$version" "$desc" && return 0
|
2024-01-29 04:19:23 +00:00
|
|
|
fi
|
2024-04-30 20:57:44 +00:00
|
|
|
switchEdition "$version"
|
|
|
|
fi
|
2024-01-29 04:19:23 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if isESD "$version"; then
|
2024-01-29 04:19:23 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if [[ "$tried" != "n" ]]; then
|
|
|
|
info "Failed to download $desc using Mido, will try a diferent method now..."
|
|
|
|
fi
|
2024-04-13 14:58:04 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
tried="y"
|
2024-02-04 18:45:32 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if getESD "$TMP/esd" "$version"; then
|
|
|
|
ISO="$TMP/$version.esd"
|
|
|
|
downloadFile "$ISO" "$ESD_URL" "$desc" && return 0
|
|
|
|
ISO="$TMP/$BASE"
|
2024-02-04 18:45:32 +00:00
|
|
|
fi
|
|
|
|
|
2024-01-29 04:19:23 +00:00
|
|
|
fi
|
2024-01-19 14:18:56 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
url=$(getLink "$version")
|
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
if [ -n "$url" ]; then
|
2024-04-30 20:57:44 +00:00
|
|
|
|
|
|
|
if [[ "$tried" != "n" ]]; then
|
|
|
|
info "Failed to download $desc from Microsoft, will try another mirror now..."
|
|
|
|
fi
|
|
|
|
|
|
|
|
tried="y"
|
2024-04-24 18:16:43 +00:00
|
|
|
downloadFile "$iso" "$url" "$desc" && return 0
|
2024-02-04 18:45:32 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
fi
|
2024-02-04 18:45:32 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
url=$(secondLink "$version")
|
2024-02-04 18:45:32 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if [ -n "$url" ]; then
|
2024-01-29 04:19:23 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if [[ "$tried" != "n" ]]; then
|
|
|
|
info "Failed to download $desc, will try another mirror now..."
|
|
|
|
fi
|
2024-04-24 18:16:43 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
tried="y"
|
|
|
|
downloadFile "$iso" "$url" "$desc" && return 0
|
2024-04-24 18:16:43 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
fi
|
2024-04-24 18:16:43 +00:00
|
|
|
|
|
|
|
return 1
|
2024-01-24 04:38:16 +00:00
|
|
|
}
|
2024-01-22 19:44:38 +00:00
|
|
|
|
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
|
|
|
|
esdImageCount=$(wimlib-imagex info "${iso}" | awk '/Image Count:/ {print $3}')
|
|
|
|
|
|
|
|
wimlib-imagex apply "$iso" 1 "${dir}" --quiet 2>/dev/null || {
|
|
|
|
retVal=$?
|
2024-04-30 20:57:44 +00:00
|
|
|
error "Extracting $desc bootdisk failed" && return $retVal
|
2024-02-04 18:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
local bootWimFile="${dir}/sources/boot.wim"
|
|
|
|
local installWimFile="${dir}/sources/install.wim"
|
|
|
|
|
|
|
|
local msg="Extracting $desc environment..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
|
|
|
wimlib-imagex export "${iso}" 2 "${bootWimFile}" --compress=LZX --chunk-size 32K --quiet || {
|
|
|
|
retVal=$?
|
|
|
|
error "Adding WinPE failed" && return ${retVal}
|
|
|
|
}
|
|
|
|
|
|
|
|
local msg="Extracting $desc setup..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
|
|
|
wimlib-imagex export "${iso}" 3 "$bootWimFile" --compress=LZX --chunk-size 32K --boot --quiet || {
|
|
|
|
retVal=$?
|
|
|
|
error "Adding Windows Setup failed" && return ${retVal}
|
|
|
|
}
|
|
|
|
|
|
|
|
local msg="Extracting $desc image..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
|
|
|
local edition imageIndex imageEdition
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
case "${version,,}" in
|
2024-04-24 18:16:43 +00:00
|
|
|
"win11${PLATFORM,,}")
|
2024-02-04 18:45:32 +00:00
|
|
|
edition="11 pro"
|
|
|
|
;;
|
2024-04-24 18:16:43 +00:00
|
|
|
"win10${PLATFORM,,}")
|
2024-02-04 18:45:32 +00:00
|
|
|
edition="10 pro"
|
|
|
|
;;
|
|
|
|
*)
|
2024-04-30 20:57:44 +00:00
|
|
|
error "Invalid VERSION specified, value \"$version\" is not recognized!" && return 1
|
2024-02-04 18:45:32 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
for (( imageIndex=4; imageIndex<=esdImageCount; imageIndex++ )); do
|
|
|
|
imageEdition=$(wimlib-imagex info "${iso}" ${imageIndex} | grep '^Description:' | sed 's/Description:[ \t]*//')
|
|
|
|
[[ "${imageEdition,,}" != *"$edition"* ]] && continue
|
|
|
|
wimlib-imagex export "${iso}" ${imageIndex} "${installWimFile}" --compress=LZMS --chunk-size 128K --quiet || {
|
|
|
|
retVal=$?
|
2024-04-30 20:57:44 +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-04-24 18:16:43 +00:00
|
|
|
error "Failed to find product 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-01-27 13:52:58 +00:00
|
|
|
local desc="downloaded 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-04-30 20:57:44 +00:00
|
|
|
if [[ "$EXTERNAL" != [Yy1]* ]] && [ -z "$CUSTOM" ]; then
|
|
|
|
desc=$(printVersion "$version" "downloaded ISO")
|
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
|
|
|
[ -n "$CUSTOM" ] && msg="Extracting local ISO image..."
|
|
|
|
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-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-01-25 15:15:18 +00:00
|
|
|
detectImage() {
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
XML=""
|
2024-04-30 20:57:44 +00:00
|
|
|
local dsc
|
2024-02-01 13:16:54 +00:00
|
|
|
local dir="$1"
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-01-26 21:11:12 +00:00
|
|
|
if [ -n "$CUSTOM" ]; then
|
2024-05-01 18:42:37 +00:00
|
|
|
if [ -f "/run/assets/custom.xml" ]; then
|
|
|
|
DETECTED="custom"
|
|
|
|
else
|
|
|
|
DETECTED=""
|
|
|
|
fi
|
2024-01-26 21:11:12 +00:00
|
|
|
else
|
|
|
|
if [ -z "$DETECTED" ] && [[ "$EXTERNAL" != [Yy1]* ]]; then
|
2024-01-26 05:05:01 +00:00
|
|
|
DETECTED="$VERSION"
|
|
|
|
fi
|
2024-01-26 21:11:12 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$DETECTED" ]; then
|
2024-01-27 13:52:58 +00:00
|
|
|
|
2024-04-18 22:00:17 +00:00
|
|
|
if [ -f "/run/assets/$DETECTED.xml" ]; then
|
2024-01-26 21:11:12 +00:00
|
|
|
[[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml"
|
|
|
|
return 0
|
2024-01-25 15:15:18 +00:00
|
|
|
fi
|
2024-01-27 13:52:58 +00:00
|
|
|
|
2024-02-01 13:16:54 +00:00
|
|
|
if [[ "${DETECTED,,}" != "winxp"* ]]; then
|
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
dsc=$(printVersion "$DETECTED" "$DETECTED")
|
2024-02-01 13:16:54 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
warn "got $dsc, but no matching file called $DETECTED.xml exists, $FB."
|
2024-02-01 13:16:54 +00:00
|
|
|
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-01-24 04:38:16 +00:00
|
|
|
info "Detecting Windows version from ISO image..."
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
|
|
|
if [ -f "$dir/WIN51" ] || [ -f "$dir/SETUPXP.HTM" ]; then
|
|
|
|
if [ -d "$dir/AMD64" ]; then
|
|
|
|
DETECTED="winxpx64"
|
|
|
|
else
|
|
|
|
DETECTED="winxpx86"
|
|
|
|
fi
|
|
|
|
dsc=$(printVersion "$DETECTED" "$DETECTED")
|
|
|
|
info "Detected: $dsc"
|
|
|
|
return 0
|
|
|
|
fi
|
2024-02-01 13:16:54 +00:00
|
|
|
fi
|
|
|
|
|
2024-02-16 13:43:03 +00:00
|
|
|
local src loc tag result name name2 desc
|
|
|
|
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-30 20:57:44 +00:00
|
|
|
[[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
|
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-02-16 13:43:03 +00:00
|
|
|
loc=$(find "$src" -maxdepth 1 -type f -iname install.wim | head -n 1)
|
2024-04-18 22:00:17 +00:00
|
|
|
[ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1)
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-04-18 22:00:17 +00:00
|
|
|
if [ ! -f "$loc" ]; then
|
2024-04-30 20:57:44 +00:00
|
|
|
[[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
|
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-01-24 04:54:26 +00:00
|
|
|
tag="DISPLAYNAME"
|
|
|
|
result=$(wimlib-imagex info -xml "$loc" | tr -d '\000')
|
|
|
|
name=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$result")
|
2024-01-27 13:52:58 +00:00
|
|
|
DETECTED=$(getVersion "$name")
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-01-25 15:15:18 +00:00
|
|
|
if [ -z "$DETECTED" ]; then
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
tag="PRODUCTNAME"
|
2024-01-24 04:54:26 +00:00
|
|
|
name2=$(sed -n "/$tag/{s/.*<$tag>\(.*\)<\/$tag>.*/\1/;p}" <<< "$result")
|
2024-01-24 04:38:16 +00:00
|
|
|
[ -z "$name" ] && name="$name2"
|
2024-01-27 13:52:58 +00:00
|
|
|
DETECTED=$(getVersion "$name2")
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-01-27 13:52:58 +00:00
|
|
|
if [ -z "$DETECTED" ]; then
|
2024-04-24 18:16:43 +00:00
|
|
|
warn "failed to determine Windows version from string '$name', $FB" && return 0
|
2024-01-27 13:52:58 +00:00
|
|
|
fi
|
2024-01-22 01:56:28 +00:00
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
desc=$(printVersion "$DETECTED" "$DETECTED")
|
2024-01-24 04:38:16 +00:00
|
|
|
|
2024-04-18 22:00:17 +00:00
|
|
|
if [ -f "/run/assets/$DETECTED.xml" ]; then
|
2024-01-27 13:52:58 +00:00
|
|
|
[[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml"
|
|
|
|
info "Detected: $desc"
|
2024-01-24 04:38:16 +00:00
|
|
|
else
|
2024-04-30 20:57:44 +00:00
|
|
|
warn "detected $desc, but no matching file called $DETECTED.xml exists, $FB."
|
2024-01-25 15:15:18 +00:00
|
|
|
fi
|
2024-01-15 22:45:35 +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-03-13 09:20:18 +00:00
|
|
|
if [[ "${BOOT_MODE,,}" != "windows_legacy" ]]; then
|
2024-02-01 13:16:54 +00:00
|
|
|
if [[ "${DETECTED,,}" != "winxp"* ]] && [[ "${DETECTED,,}" != "win2008"* ]]; then
|
|
|
|
if [[ "${DETECTED,,}" != "winvista"* ]] && [[ "${DETECTED,,}" != "win7"* ]]; then
|
|
|
|
|
2024-04-18 22:00:17 +00:00
|
|
|
if [ -f "$dir/$ETFS" ] && [ -f "$dir/$EFISYS" ]; then
|
2024-02-01 13:16:54 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$dir/$ETFS" ]; then
|
|
|
|
warn "failed to locate file 'etfsboot.com' in ISO image, falling back to legacy boot!"
|
|
|
|
else
|
|
|
|
warn "failed to locate file 'efisys_noprompt.bin' in ISO image, falling back to legacy boot!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
[[ "${PLATFORM,,}" == "arm64" ]] && return 1
|
|
|
|
|
2024-02-01 13:16:54 +00:00
|
|
|
if [[ "${DETECTED,,}" == "winxp"* ]]; then
|
|
|
|
if ! prepareXP "$iso" "$dir"; then
|
2024-04-24 18:16:43 +00:00
|
|
|
error "Failed to prepare Windows XP ISO!" && return 1
|
2024-02-01 13:16:54 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
if ! prepareLegacy "$iso" "$dir"; then
|
2024-04-24 18:16:43 +00:00
|
|
|
error "Failed to prepare Windows ISO!" && return 1
|
2024-02-01 13:16:54 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
updateImage() {
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-01-25 15:15:18 +00:00
|
|
|
local iso="$1"
|
|
|
|
local dir="$2"
|
|
|
|
local asset="/run/assets/$3"
|
2024-04-30 20:57:44 +00:00
|
|
|
local path src loc xml index result
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-04-18 22:00:17 +00:00
|
|
|
[ ! -s "$asset" ] || [ ! -f "$asset" ] && return 0
|
2024-01-17 02:40:19 +00:00
|
|
|
|
2024-02-16 13:43:03 +00:00
|
|
|
path=$(find "$dir" -maxdepth 1 -type f -iname autounattend.xml | head -n 1)
|
2024-02-16 13:38:00 +00:00
|
|
|
[ -n "$path" ] && cp "$asset" "$path"
|
|
|
|
|
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-30 20:57:44 +00:00
|
|
|
[[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
|
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-02-16 13:43:03 +00:00
|
|
|
loc=$(find "$src" -maxdepth 1 -type f -iname boot.wim | head -n 1)
|
2024-04-18 22:00:17 +00:00
|
|
|
[ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1)
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-04-18 22:00:17 +00:00
|
|
|
if [ ! -f "$loc" ]; then
|
2024-04-30 20:57:44 +00:00
|
|
|
[[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
|
2024-04-24 18:16:43 +00:00
|
|
|
warn "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-04-30 20:57:44 +00:00
|
|
|
xml=$(basename "$asset")
|
|
|
|
info "Adding $xml for automatic installation..."
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-01-24 04:54:26 +00:00
|
|
|
index="1"
|
|
|
|
result=$(wimlib-imagex info -xml "$loc" | 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-01-25 15:15:18 +00:00
|
|
|
if ! wimlib-imagex update "$loc" "$index" --command "add $asset /autounattend.xml" > /dev/null; then
|
2024-04-30 20:57:44 +00:00
|
|
|
warn "failed to add $xml to ISO image, $FB" && return 1
|
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-04-28 11:03:37 +00:00
|
|
|
copyOEM() {
|
|
|
|
local dir="$1"
|
|
|
|
local folder="$STORAGE/oem"
|
|
|
|
local src
|
|
|
|
|
|
|
|
[ ! -d "$folder" ] && folder="$STORAGE/OEM"
|
|
|
|
[ ! -d "$folder" ] && folder="$STORAGE/shared/oem"
|
|
|
|
[ ! -d "$folder" ] && folder="$STORAGE/shared/OEM"
|
|
|
|
[ ! -d "$folder" ] && return 0
|
|
|
|
|
|
|
|
local msg="Copying OEM folder to image..."
|
|
|
|
info "$msg" && html "$msg"
|
|
|
|
|
|
|
|
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
|
|
|
|
|
|
|
|
if [ ! -d "$src" ]; then
|
|
|
|
error "failed to locate 'sources' folder in ISO image!" && return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
local dest="$src/\$OEM\$/\$1/"
|
|
|
|
mkdir -p "$dest"
|
|
|
|
|
|
|
|
if ! cp -r "$folder" "$dest"; then
|
|
|
|
error "Failed to copy OEM folder!" && return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
buildImage() {
|
|
|
|
|
|
|
|
local dir="$1"
|
2024-04-24 18:16:43 +00:00
|
|
|
local failed="N"
|
2024-01-24 04:38:16 +00:00
|
|
|
local cat="BOOT.CAT"
|
|
|
|
local label="${BASE%.*}"
|
2024-01-25 15:15:18 +00:00
|
|
|
local log="/run/shm/iso.log"
|
2024-01-27 13:52:58 +00:00
|
|
|
local size size_gb space space_gb desc
|
2024-01-24 04:54:26 +00:00
|
|
|
|
2024-01-24 04:38:16 +00:00
|
|
|
label="${label::30}"
|
|
|
|
local out="$TMP/$label.tmp"
|
|
|
|
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-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
|
|
|
|
|
|
|
|
if ! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -c "$cat" -iso-level 4 -J -l -D -N -joliet-long -relaxed-filenames -V "$label" \
|
|
|
|
-udf -boot-info-table -eltorito-alt-boot -eltorito-boot "$EFISYS" -no-emul-boot -allow-limited-size -quiet "$dir" 2> "$log"; then
|
2024-04-24 18:16:43 +00:00
|
|
|
failed="Y"
|
2024-01-25 15:15:18 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
|
2024-02-01 13:16:54 +00:00
|
|
|
if [[ "${DETECTED,,}" != "winxp"* ]]; then
|
2024-01-25 15:15:18 +00:00
|
|
|
|
2024-02-01 13:16:54 +00:00
|
|
|
if ! genisoimage -o "$out" -b "$ETFS" -no-emul-boot -c "$cat" -iso-level 2 -J -l -D -N -joliet-long -relaxed-filenames -V "$label" \
|
|
|
|
-udf -allow-limited-size -quiet "$dir" 2> "$log"; then
|
2024-04-24 18:16:43 +00:00
|
|
|
failed="Y"
|
2024-02-01 13:16:54 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
if ! 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" -quiet "$dir" 2> "$log"; then
|
2024-04-24 18:16:43 +00:00
|
|
|
failed="Y"
|
2024-02-01 13:16:54 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
2024-01-22 19:44:38 +00:00
|
|
|
fi
|
2024-01-19 00:25:39 +00:00
|
|
|
|
2024-04-24 18:16:43 +00:00
|
|
|
if [[ "$failed" != "N" ]]; then
|
|
|
|
[ -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
|
|
|
|
|
|
|
if [ -f "$STORAGE/$BASE" ]; then
|
2024-04-24 18:16:43 +00:00
|
|
|
error "File $STORAGE/$BASE does already exist?!" && return 1
|
2024-01-24 04:38:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
mv "$out" "$STORAGE/$BASE"
|
|
|
|
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-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
|
|
|
|
mv "$STORAGE/windows.rom" "$STORAGE/$BOOT_MODE.rom"
|
|
|
|
fi
|
|
|
|
if [ -f "$STORAGE/windows.vars" ] && [ ! -f "$STORAGE/$BOOT_MODE.vars" ]; then
|
|
|
|
mv "$STORAGE/windows.vars" "$STORAGE/$BOOT_MODE.vars"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
######################################
|
|
|
|
|
2024-04-30 20:57:44 +00:00
|
|
|
! parseVersion && exit 58
|
|
|
|
! 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-01-25 15:15:18 +00:00
|
|
|
if ! downloadImage "$ISO" "$VERSION"; 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-01-25 15:15:18 +00:00
|
|
|
if ! detectImage "$DIR"; then
|
2024-04-24 18:16:43 +00:00
|
|
|
abortInstall "$ISO" && return 0
|
|
|
|
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-04-24 18:16:43 +00:00
|
|
|
abortInstall "$ISO" && return 0
|
|
|
|
exit 60
|
2024-01-22 19:44:38 +00:00
|
|
|
fi
|
|
|
|
|
2024-01-25 15:15:18 +00:00
|
|
|
if ! updateImage "$ISO" "$DIR" "$XML"; then
|
2024-04-24 18:16:43 +00:00
|
|
|
abortInstall "$ISO" && return 0
|
|
|
|
exit 60
|
2024-01-25 15:15:18 +00:00
|
|
|
fi
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-04-22 13:50:01 +00:00
|
|
|
if ! rm -f "$ISO" 2> /dev/null; then
|
|
|
|
BASE="windows.iso"
|
|
|
|
ISO="$STORAGE/$BASE"
|
|
|
|
rm -f "$ISO"
|
|
|
|
fi
|
2024-01-22 19:44:38 +00:00
|
|
|
|
2024-04-28 11:03:37 +00:00
|
|
|
if ! copyOEM "$DIR"; then
|
|
|
|
exit 63
|
|
|
|
fi
|
|
|
|
|
2024-01-25 15:15:18 +00:00
|
|
|
if ! buildImage "$DIR"; then
|
|
|
|
exit 65
|
|
|
|
fi
|
2024-01-14 14:19:58 +00:00
|
|
|
|
2024-04-22 13:50:01 +00:00
|
|
|
if ! finishInstall "$STORAGE/$BASE" "N"; then
|
|
|
|
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
|