From adece2e5595866e1ba8f4efdacfed79db615cfde Mon Sep 17 00:00:00 2001 From: Kroese Date: Wed, 24 Apr 2024 20:16:43 +0200 Subject: [PATCH] feat: Disabled sleep mode and improved download (#413) --- assets/win10x64-enterprise-eval.xml | 7 +- assets/win10x64-iot.xml | 7 +- assets/win10x64-ltsc.xml | 7 +- assets/win10x64.xml | 7 +- assets/win11x64-enterprise-eval.xml | 9 +- assets/win11x64.xml | 9 +- assets/win2008r2.xml | 7 +- assets/win2012r2-eval.xml | 7 +- assets/win2016-eval.xml | 7 +- assets/win2019-eval.xml | 7 +- assets/win2022-eval.xml | 7 +- assets/win7x64.xml | 7 +- assets/win81x64-enterprise-eval.xml | 7 +- assets/win81x64.xml | 7 +- assets/winvistax64.xml | 15 +- src/entry.sh | 2 +- src/install.sh | 345 +++++++++++++++------------- 17 files changed, 283 insertions(+), 181 deletions(-) diff --git a/assets/win10x64-enterprise-eval.xml b/assets/win10x64-enterprise-eval.xml index db51ceb..2e2330b 100644 --- a/assets/win10x64-enterprise-eval.xml +++ b/assets/win10x64-enterprise-eval.xml @@ -390,7 +390,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/win10x64-iot.xml b/assets/win10x64-iot.xml index d0c3518..72d4a95 100644 --- a/assets/win10x64-iot.xml +++ b/assets/win10x64-iot.xml @@ -398,7 +398,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/win10x64-ltsc.xml b/assets/win10x64-ltsc.xml index 606b417..88845ae 100644 --- a/assets/win10x64-ltsc.xml +++ b/assets/win10x64-ltsc.xml @@ -396,7 +396,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/win10x64.xml b/assets/win10x64.xml index af4da13..a8e6911 100644 --- a/assets/win10x64.xml +++ b/assets/win10x64.xml @@ -392,7 +392,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/win11x64-enterprise-eval.xml b/assets/win11x64-enterprise-eval.xml index 9a2e177..476cde8 100644 --- a/assets/win11x64-enterprise-eval.xml +++ b/assets/win11x64-enterprise-eval.xml @@ -408,15 +408,20 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep + + + 14 reg.exe add "HKCU\Control Panel\UnsupportedHardwareNotificationCache" /v SV1 /d 0 /t REG_DWORD /f Disable unsupported hardware notifications - 14 + 15 reg.exe add "HKCU\Control Panel\UnsupportedHardwareNotificationCache" /v SV2 /d 0 /t REG_DWORD /f Disable unsupported hardware notifications diff --git a/assets/win11x64.xml b/assets/win11x64.xml index 3fa19df..8f2809f 100644 --- a/assets/win11x64.xml +++ b/assets/win11x64.xml @@ -410,15 +410,20 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep + + + 14 reg.exe add "HKCU\Control Panel\UnsupportedHardwareNotificationCache" /v SV1 /d 0 /t REG_DWORD /f Disable unsupported hardware notifications - 14 + 15 reg.exe add "HKCU\Control Panel\UnsupportedHardwareNotificationCache" /v SV2 /d 0 /t REG_DWORD /f Disable unsupported hardware notifications diff --git a/assets/win2008r2.xml b/assets/win2008r2.xml index 275a8b9..1af605f 100644 --- a/assets/win2008r2.xml +++ b/assets/win2008r2.xml @@ -280,7 +280,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/win2012r2-eval.xml b/assets/win2012r2-eval.xml index 7b22e00..14a9b79 100644 --- a/assets/win2012r2-eval.xml +++ b/assets/win2012r2-eval.xml @@ -319,7 +319,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/win2016-eval.xml b/assets/win2016-eval.xml index e2200a0..289f3f7 100644 --- a/assets/win2016-eval.xml +++ b/assets/win2016-eval.xml @@ -319,7 +319,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/win2019-eval.xml b/assets/win2019-eval.xml index b01d491..ab4222f 100644 --- a/assets/win2019-eval.xml +++ b/assets/win2019-eval.xml @@ -323,7 +323,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/win2022-eval.xml b/assets/win2022-eval.xml index 3bfc483..6b553b4 100644 --- a/assets/win2022-eval.xml +++ b/assets/win2022-eval.xml @@ -323,7 +323,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/win7x64.xml b/assets/win7x64.xml index e9050e5..398116b 100644 --- a/assets/win7x64.xml +++ b/assets/win7x64.xml @@ -283,7 +283,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/win81x64-enterprise-eval.xml b/assets/win81x64-enterprise-eval.xml index 4c25d10..adc9fff 100644 --- a/assets/win81x64-enterprise-eval.xml +++ b/assets/win81x64-enterprise-eval.xml @@ -304,7 +304,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/win81x64.xml b/assets/win81x64.xml index f201a16..8788142 100644 --- a/assets/win81x64.xml +++ b/assets/win81x64.xml @@ -313,7 +313,12 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation + + + 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep diff --git a/assets/winvistax64.xml b/assets/winvistax64.xml index 06ceea7..c15f547 100644 --- a/assets/winvistax64.xml +++ b/assets/winvistax64.xml @@ -222,30 +222,35 @@ 12 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Power" /v "HibernateEnabled" /t REG_DWORD /d 0 /f - Disable Hibernation Mode + Disable Hibernation 13 + cmd /C POWERCFG -X -standby-timeout-ac 0 + Disable Sleep + + + 14 netsh.exe advfirewall firewall set rule group="Remote Desktop" new enable=Yes Add RDP in firewall - 14 + 15 netsh.exe Advfirewall set allprofiles state off Disable firewall - 15 + 16 reg.exe add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f Enable RDP - 16 + 17 reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Windows\Sidebar" /v "TurnOffSidebar" /t REG_DWORD /d 1 /f Turn off sidebar - 17 + 18 reg.exe add "HKCU\Control Panel\Desktop" /v "ScreenSaveActive" /t REG_DWORD /d 0 /f Disable screensaver diff --git a/src/entry.sh b/src/entry.sh index 3c30e5e..1e081eb 100644 --- a/src/entry.sh +++ b/src/entry.sh @@ -29,7 +29,7 @@ info "Booting ${APP}${BOOT_DESC} on a ${CPU} using QEMU v${VERS} with kernel $(u terminal tail -fn +0 "$QEMU_LOG" 2>/dev/null & -( sleep 6; [ ! -f "$QEMU_END" ] && info "Windows started succesfully, visit http://localhost:8006/ to view the screen..." ) & +( sleep 10; [ ! -f "$QEMU_END" ] && info "Windows started succesfully, visit http://localhost:8006/ to view the screen..." ) & cat "$QEMU_TERM" 2> /dev/null | tee "$QEMU_PTY" & wait $! || : diff --git a/src/install.sh b/src/install.sh index 1065d75..7ecbb86 100644 --- a/src/install.sh +++ b/src/install.sh @@ -2,8 +2,10 @@ set -Eeuo pipefail : "${MANUAL:=""}" +: "${VERSION:=""}" : "${DETECTED:=""}" -: "${VERSION:="win11x64"}" + +[ -z "$VERSION" ] && VERSION="win11x64" if [[ "${VERSION}" == \"*\" || "${VERSION}" == \'*\' ]]; then VERSION="${VERSION:1:-1}" @@ -103,6 +105,7 @@ fi ESD_URL="" MACHINE="q35" +PLATFORM="x64" TMP="$STORAGE/tmp" DIR="$TMP/unpack" FB="falling back to manual installation!" @@ -112,7 +115,7 @@ EFISYS="efi/microsoft/boot/efisys_noprompt.bin" printVersion() { local id="$1" - local desc="" + local desc="$2" [[ "$id" == "win7"* ]] && desc="Windows 7" [[ "$id" == "win8"* ]] && desc="Windows 8" @@ -134,6 +137,8 @@ printVersion() { [[ "$id" == "win10x64-enterprise-eval" ]] && desc="Windows 10 Enterprise" [[ "$id" == "win11x64-enterprise-eval" ]] && desc="Windows 11 Enterprise" + [ -z "$desc" ] && desc="Windows" + echo "$desc" return 0 } @@ -141,7 +146,7 @@ printVersion() { getName() { local file="$1" - local desc="" + local desc="$2" [[ "${file,,}" == "win11"* ]] && desc="Windows 11" [[ "${file,,}" == "win10"* ]] && desc="Windows 10" @@ -177,6 +182,8 @@ getName() { [[ "${file,,}" == *"server_2022"* ]] && desc="Windows Server 2022" [[ "${file,,}" == *"server_2025"* ]] && desc="Windows Server 2025" + [ -z "$desc" ] && desc="Windows" + echo "$desc" return 0 } @@ -258,15 +265,13 @@ finishInstall() { local aborted="$2" if [ ! -s "$iso" ] || [ ! -f "$iso" ]; then - error "Failed to find ISO: $iso" - return 1 + error "Failed to find ISO: $iso" && return 1 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 - error "Failed to set magic byte!" - return 1 + error "Failed to set magic byte!" && return 1 fi fi @@ -297,17 +302,13 @@ abortInstall() { if [[ "$iso" != "$STORAGE/$BASE" ]]; then if ! mv -f "$iso" "$STORAGE/$BASE"; then - error "Failed to move ISO: $iso" - exit 69 + error "Failed to move ISO: $iso" && return 1 fi fi - if ! finishInstall "$STORAGE/$BASE" "Y"; then - error "Failed to finish installation!" - exit 69 - fi + finishInstall "$STORAGE/$BASE" "Y" && return 0 - return 0 + return 1 } startInstall() { @@ -344,6 +345,11 @@ startInstall() { fi fi + if skipInstall; then + [ ! -f "$STORAGE/$BASE" ] && BASE="" + return 1 + fi + if [ -f "$STORAGE/$BASE" ]; then # Check if the ISO was already processed by our script @@ -364,11 +370,6 @@ startInstall() { fi - if skipInstall; then - [ ! -f "$STORAGE/$BASE" ] && BASE="" - return 1 - fi - rm -rf "$TMP" mkdir -p "$TMP" @@ -385,20 +386,17 @@ startInstall() { getESD() { local dir="$1" - local file="$2" - local architecture="x64" local winCatalog size case "${VERSION,,}" in - win11x64) + "win11${PLATFORM,,}") winCatalog="https://go.microsoft.com/fwlink?linkid=2156292" ;; - win10x64) + "win10${PLATFORM,,}") winCatalog="https://go.microsoft.com/fwlink/?LinkId=841361" ;; *) - error "Invalid ESD version specified: $VERSION" - return 1 + error "Invalid ESD version specified: $VERSION" && return 1 ;; esac @@ -428,7 +426,7 @@ getESD() { local esdLang="en-us" local editionName="Professional" - local edQuery='//File[Architecture="'${architecture}'"][Edition="'${editionName}'"]' + local edQuery='//File[Architecture="'${PLATFORM}'"][Edition="'${editionName}'"]' echo -e '' > "${dir}/products_filter.xml" xmllint --nonet --xpath "${edQuery}" "${dir}/products.xml" >> "${dir}/products_filter.xml" 2>/dev/null @@ -443,56 +441,102 @@ getESD() { ESD_URL=$(xmllint --nonet --xpath '//FilePath' "${dir}/esd_edition.xml" | sed -E -e 's/<[\/]?FilePath>//g') if [ -z "$ESD_URL" ]; then - error "Failed to find ESD url!" && return 1 + error "Failed to find ESD URL!" && return 1 fi rm -rf "$dir" return 0 } -downloadImage() { +doMido() { local iso="$1" local url="$2" - local file="$iso" - local desc rc progress + local desc="$3" + local rc + + rm -f "$iso" + rm -f "$iso.PART" + + local msg="Downloading $desc..." + info "$msg" && html "$msg" + /run/progress.sh "$iso.PART" "Downloading $desc ([P])..." & + + cd "$TMP" + { /run/mido.sh "$url"; rc=$?; } || : + cd /run + + 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 +} + +downloadFile() { + + local iso="$1" + local url="$2" + local desc="$3" + local rc progress rm -f "$iso" - if [[ "$EXTERNAL" != [Yy1]* ]]; then - - file="$iso.PART" - desc=$(printVersion "$VERSION") - [ -z "$desc" ] && desc="Windows" - + # Check if running with interactive TTY or redirected to docker log + if [ -t 1 ]; then + progress="--progress=bar:noscroll" else - - desc=$(getName "$BASE") - [ -z "$desc" ] && desc="$BASE" - + progress="--progress=dot:giga" fi local msg="Downloading $desc..." info "$msg" && html "$msg" - /run/progress.sh "$file" "Downloading $desc ([P])..." & + /run/progress.sh "$iso" "Downloading $desc ([P])..." & + + { wget "$url" -O "$iso" -q --no-check-certificate --show-progress "$progress"; rc=$?; } || : + + 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" + local url="$2" + local rc desc if [[ "$EXTERNAL" != [Yy1]* ]]; then - cd "$TMP" - { /run/mido.sh "$url"; rc=$?; } || : - cd /run + desc=$(printVersion "$VERSION" "Windows") - fKill "progress.sh" + else - if (( rc == 0 )); then + desc=$(getName "$BASE" "$BASE") - [ ! -s "$iso" ] || [ ! -f "$iso" ] && return 1 + fi - html "Download finished successfully..." - return 0 - fi + if [[ "$EXTERNAL" != [Yy1]* ]]; then - if [[ "$VERSION" != "win10x64"* ]] && [[ "$VERSION" != "win11x64" ]]; then + doMido "$iso" "$url" "$desc" && return 0 + + if [[ "$VERSION" != "win10${PLATFORM,,}" ]] && [[ "$VERSION" != "win11${PLATFORM,,}" ]]; then return 1 fi @@ -503,36 +547,44 @@ downloadImage() { ISO="$TMP/$VERSION.esd" iso="$ISO" - file="$ISO" - rm -f "$iso" - if ! getESD "$TMP/esd" "$iso"; then - return 1 + if ! getESD "$TMP/esd"; then + url="" + else + url="$ESD_URL" fi - url="$ESD_URL" - msg="Downloading $desc..." - info "$msg" && html "$msg" - /run/progress.sh "$iso" "Downloading $desc ([P])..." & - fi - # Check if running with interactive TTY or redirected to docker log - if [ -t 1 ]; then - progress="--progress=bar:noscroll" - else - progress="--progress=dot:giga" + if [ -n "$url" ]; then + downloadFile "$iso" "$url" "$desc" && return 0 fi - { wget "$url" -O "$iso" -q --no-check-certificate --show-progress "$progress"; rc=$?; } || : + [[ "$EXTERNAL" == [Yy1]* ]] && return 1 - fKill "progress.sh" - (( rc != 0 )) && error "Failed to download $url , reason: $rc" && exit 60 + case "${VERSION,,}" in + "win11${PLATFORM,,}") + url="https://dl.bobpony.com/windows/11/en-us_windows_11_23h2_${PLATFORM,,}.iso" + ;; + "win10${PLATFORM,,}") + url="https://dl.bobpony.com/windows/10/en-us_windows_10_22h2_${PLATFORM,,}.iso" + ;; + *) + return 1 + ;; + esac - [ ! -s "$iso" ] || [ ! -f "$iso" ] && return 1 + info "Failed to download $desc from Microsoft, will try another mirror now..." - html "Download finished successfully..." - return 0 + rm -rf "$TMP" + mkdir -p "$TMP" + + ISO="$TMP/$BASE" + iso="$ISO" + + downloadFile "$iso" "$url" "$desc" && return 0 + + return 1 } extractESD() { @@ -541,26 +593,26 @@ extractESD() { local dir="$2" local size size_gb space space_gb desc - desc=$(printVersion "$VERSION") + desc=$(printVersion "$VERSION" "Windows") local msg="Extracting $desc bootdisk..." info "$msg" && html "$msg" - size=16106127360 - size_gb=$(( (size + 1073741823)/1073741824 )) - space=$(df --output=avail -B 1 "$TMP" | tail -n 1) - space_gb=$(( (space + 1073741823)/1073741824 )) - - if ((size<10000000)); then - error "Invalid ESD file: Size is smaller than 10 MB" && exit 62 - fi - - if (( size > space )); then - error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && exit 63 + 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" + size=16106127360 + size_gb=$(( (size + 1073741823)/1073741824 )) + space=$(df --output=avail -B 1 "$dir" | tail -n 1) + space_gb=$(( (space + 1073741823)/1073741824 )) + + if (( size > space )); then + error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1 + fi + local esdImageCount esdImageCount=$(wimlib-imagex info "${iso}" | awk '/Image Count:/ {print $3}') @@ -594,15 +646,14 @@ extractESD() { local edition imageIndex imageEdition case "${VERSION,,}" in - win11x64) + "win11${PLATFORM,,}") edition="11 pro" ;; - win10x64) + "win10${PLATFORM,,}") edition="10 pro" ;; *) - error "Invalid version specified: $VERSION" - return 1 + error "Invalid version specified: $VERSION" && return 1 ;; esac @@ -616,8 +667,7 @@ extractESD() { return 0 done - error "Failed to find product in install.wim!" - return 1 + error "Failed to find product in install.wim!" && return 1 } extractImage() { @@ -628,42 +678,38 @@ extractImage() { local size size_gb space space_gb if [[ "${iso,,}" == *".esd" ]]; then - if ! extractESD "$iso" "$dir"; then - rm -f "$iso" - error "Failed to extract ESD file!" - exit 67 - fi - return 0 + extractESD "$iso" "$dir" && return 0 + return 1 fi if [[ "$EXTERNAL" != [Yy1]* ]] && [ -z "$CUSTOM" ]; then - desc=$(printVersion "$VERSION") - [ -z "$desc" ] && desc="downloaded ISO" + desc=$(printVersion "$VERSION" "downloaded ISO") fi local msg="Extracting $desc image..." [ -n "$CUSTOM" ] && msg="Extracting local ISO image..." info "$msg" && html "$msg" + rm -rf "$dir" + mkdir -p "$dir" + size=$(stat -c%s "$iso") size_gb=$(( (size + 1073741823)/1073741824 )) - space=$(df --output=avail -B 1 "$TMP" | tail -n 1) + space=$(df --output=avail -B 1 "$dir" | tail -n 1) space_gb=$(( (space + 1073741823)/1073741824 )) - if ((size<10000000)); then - error "Invalid ISO file: Size is smaller than 10 MB" && exit 62 + if ((size<100000000)); then + error "Invalid ISO file: Size is smaller than 100 MB" && return 1 fi if (( size > space )); then - error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && exit 63 + error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1 fi rm -rf "$dir" if ! 7z x "$iso" -o"$dir" > /dev/null; then - rm -f "$iso" - error "Failed to extract ISO file!" - exit 66 + error "Failed to extract ISO file: $iso" && return 1 fi return 0 @@ -692,8 +738,7 @@ detectImage() { if [[ "${DETECTED,,}" != "winxp"* ]]; then local dsc - dsc=$(printVersion "$DETECTED") - [ -z "$dsc" ] && dsc="$DETECTED" + dsc=$(printVersion "$DETECTED" "$DETECTED") warn "got $dsc, but no matching XML file exists, $FB." fi @@ -705,26 +750,23 @@ detectImage() { if [ -f "$dir/WIN51" ] || [ -f "$dir/SETUPXP.HTM" ]; then DETECTED="winxpx86" - info "Detected: Windows XP" - return 0 + info "Detected: Windows XP" && return 0 fi local src loc tag result name name2 desc src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1) if [ ! -d "$src" ]; then - warn "failed to locate 'sources' folder in ISO image, $FB" BOOT_MODE="windows_legacy" - return 1 + warn "failed to locate 'sources' folder in ISO image, $FB" && return 1 fi loc=$(find "$src" -maxdepth 1 -type f -iname install.wim | head -n 1) [ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1) if [ ! -f "$loc" ]; then - warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" BOOT_MODE="windows_legacy" - return 1 + warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1 fi tag="DISPLAYNAME" @@ -742,12 +784,10 @@ detectImage() { fi if [ -z "$DETECTED" ]; then - warn "failed to determine Windows version from string '$name', $FB" - return 0 + warn "failed to determine Windows version from string '$name', $FB" && return 0 fi - desc=$(printVersion "$DETECTED") - [ -z "$desc" ] && desc="$DETECTED" + desc=$(printVersion "$DETECTED" "$DETECTED") if [ -f "/run/assets/$DETECTED.xml" ]; then [[ "$MANUAL" != [Yy1]* ]] && XML="$DETECTED.xml" @@ -781,8 +821,7 @@ prepareXP() { rm -rf "$drivers" if ! 7z x /run/drivers.iso -o"$drivers" > /dev/null; then - error "Failed to extract driver ISO file!" - exit 66 + error "Failed to extract driver ISO file!" && exit 66 fi cp "$drivers/viostor/xp/$arch/viostor.sys" "$target" @@ -953,8 +992,7 @@ prepareLegacy() { offset=$(isoinfo -d -i "$iso" | grep "Bootoff " | grep -o "[^ ]*$") if ! dd "if=$iso" "of=$dir/$ETFS" bs=2048 "count=$len" "skip=$offset" status=none; then - error "Failed to extract boot image from ISO!" - exit 67 + error "Failed to extract boot image from ISO!" && exit 67 fi return 0 @@ -985,13 +1023,11 @@ prepareImage() { if [[ "${DETECTED,,}" == "winxp"* ]]; then if ! prepareXP "$iso" "$dir"; then - error "Failed to prepare Windows XP ISO!" - return 1 + error "Failed to prepare Windows XP ISO!" && return 1 fi else if ! prepareLegacy "$iso" "$dir"; then - error "Failed to prepare Windows ISO!" - return 1 + error "Failed to prepare Windows ISO!" && return 1 fi fi @@ -1013,18 +1049,16 @@ updateImage() { src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1) if [ ! -d "$src" ]; then - warn "failed to locate 'sources' folder in ISO image, $FB" BOOT_MODE="windows_legacy" - return 1 + warn "failed to locate 'sources' folder in ISO image, $FB" && return 1 fi loc=$(find "$src" -maxdepth 1 -type f -iname boot.wim | head -n 1) [ ! -f "$loc" ] && loc=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1) if [ ! -f "$loc" ]; then - warn "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" BOOT_MODE="windows_legacy" - return 1 + warn "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1 fi info "Adding XML file for automatic installation..." @@ -1037,8 +1071,7 @@ updateImage() { fi if ! wimlib-imagex update "$loc" "$index" --command "add $asset /autounattend.xml" > /dev/null; then - warn "failed to add XML to ISO image, $FB" - return 1 + warn "failed to add XML to ISO image, $FB" && return 1 fi return 0 @@ -1047,6 +1080,7 @@ updateImage() { buildImage() { local dir="$1" + local failed="N" local cat="BOOT.CAT" local label="${BASE%.*}" local log="/run/shm/iso.log" @@ -1056,8 +1090,7 @@ buildImage() { local out="$TMP/$label.tmp" rm -f "$out" - desc=$(printVersion "$DETECTED") - [ -z "$desc" ] && desc="ISO" + desc=$(printVersion "$DETECTED" "ISO") local msg="Building $desc image..." info "$msg" && html "$msg" @@ -1068,16 +1101,14 @@ buildImage() { space_gb=$(( (space + 1073741823)/1073741824 )) if (( size > space )); then - error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." - return 1 + error "Not enough free space in $STORAGE, have $space_gb GB available but need at least $size_gb GB." && return 1 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 - [ -s "$log" ] && echo "$(<"$log")" - return 1 + failed="Y" fi else @@ -1086,21 +1117,24 @@ buildImage() { 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 - [ -s "$log" ] && echo "$(<"$log")" - return 1 + failed="Y" 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 - [ -s "$log" ] && echo "$(<"$log")" - return 1 + failed="Y" fi fi fi + if [[ "$failed" != "N" ]]; then + [ -s "$log" ] && echo "$(<"$log")" + error "Failed to build image!" && return 1 + fi + local error="" local hide="Warning: creating filesystem that does not conform to ISO-9660." @@ -1108,8 +1142,7 @@ buildImage() { [[ "$error" != "$hide" ]] && echo "$error" if [ -f "$STORAGE/$BASE" ]; then - error "File $STORAGE/$BASE does already exist?!" - return 1 + error "File $STORAGE/$BASE does already exist?!" && return 1 fi mv "$out" "$STORAGE/$BASE" @@ -1161,39 +1194,35 @@ bootWindows() { ###################################### if ! startInstall; then - if ! bootWindows; then - error "Failed to boot Windows!" - exit 68 - fi - return 0 + bootWindows && return 0 + exit 68 fi if [ ! -s "$ISO" ] || [ ! -f "$ISO" ]; then - rm -f "$ISO" if ! downloadImage "$ISO" "$VERSION"; then - error "Failed to download $VERSION" + rm -f "$ISO" exit 61 fi fi if ! extractImage "$ISO" "$DIR"; then - abortInstall "$ISO" - return 0 + rm -f "$ISO" + exit 62 fi if ! detectImage "$DIR"; then - abortInstall "$ISO" - return 0 + abortInstall "$ISO" && return 0 + exit 60 fi if ! prepareImage "$ISO" "$DIR"; then - abortInstall "$ISO" - return 0 + abortInstall "$ISO" && return 0 + exit 60 fi if ! updateImage "$ISO" "$DIR" "$XML"; then - abortInstall "$ISO" - return 0 + abortInstall "$ISO" && return 0 + exit 60 fi if ! rm -f "$ISO" 2> /dev/null; then @@ -1203,12 +1232,10 @@ if ! rm -f "$ISO" 2> /dev/null; then fi if ! buildImage "$DIR"; then - error "Failed to build image!" exit 65 fi if ! finishInstall "$STORAGE/$BASE" "N"; then - error "Failed to finish installation!" exit 69 fi