feat: Centralize image and boot state checks (#2137)

This commit is contained in:
Kroese
2026-08-14 11:07:46 +02:00
committed by GitHub
parent 019c70dbaa
commit a3461db9a8
5 changed files with 49 additions and 30 deletions
+6 -6
View File
@@ -400,9 +400,9 @@ extractImage() {
local archive="${dir}.archive"
local file size required archiveSize rc
if [ -z "$CUSTOM" ]; then
if ! isCustomImage; then
desc="downloaded ISO"
if [[ "$version" != "http"* ]]; then
if ! isURL "$version"; then
desc=$(printVariant "$version" "$desc")
fi
fi
@@ -1652,7 +1652,7 @@ extractESD() {
index=""
if [[ "${version,,}" == "http"* ]]; then
if isURL "$version"; then
# Direct ESD URLs have no catalog identity. Restrict automatic detection
# to installable images because indexes 1-3 contain setup components.
@@ -1758,7 +1758,7 @@ extractESD() {
return 1
fi
if [[ "${version,,}" != "http"* ]] &&
if ! isURL "$version" &&
[[ "${resultEdition,,}" != "${edition,,}" ]]; then
error "Prepared install.esd does not contain only '$edition' at index 1!"
return 1
@@ -1925,7 +1925,7 @@ buildImage() {
checkFreeSpace "$TMP" "$size" || return 1
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]] && [ -z "${BOOT_LOAD_SIZE:-}" ]; then
if isLegacyBoot && [ -z "${BOOT_LOAD_SIZE:-}" ]; then
if [[ "${DETECTED,,}" != "win9"* && "${DETECTED,,}" != "winnt4" ]]; then
error "Failed to determine the boot image load size!"
return 1
@@ -1951,7 +1951,7 @@ buildImage() {
# Use separate layouts for modern hybrid media, NT 5.x legacy media, Win9x,
# and other legacy releases because their El Torito requirements differ.
if [[ "${BOOT_MODE,,}" != "windows_legacy" ]]; then
if ! isLegacyBoot; then
args+=(
-no-emul-boot
+36 -17
View File
@@ -151,7 +151,7 @@ configureMachine() {
if ! checkMemory "$DETECTED"; then
if [ -z "$CUSTOM" ]; then
if ! isCustomImage; then
useOriginalImage "$iso" || {
error "Failed to preserve the original installation image!"
return 79
@@ -295,12 +295,12 @@ startInstall() {
html "Starting $APP..."
if [ -z "$CUSTOM" ]; then
if ! isCustomImage; then
local file="${VERSION//\//}.iso"
local boot="$file"
if [[ "${VERSION,,}" == "http"* ]]; then
if isURL "$VERSION"; then
file=$(basename "${VERSION%%[\?#]*}")
printf -v file '%b' "${file//%/\\x}"
@@ -385,7 +385,7 @@ startInstall() {
return 50
fi
if [ -z "$CUSTOM" ]; then
if ! isCustomImage; then
if [ -s "$BOOT" ]; then
ISO="$TMP/$(basename "$BOOT")"
@@ -397,7 +397,7 @@ startInstall() {
# Keep existing media at its persistent path until all storage cleanup has
# completed successfully, so a later failure cannot strand it under $TMP.
if [ -n "$CUSTOM" ] || [ ! -s "$BOOT" ]; then
if isCustomImage || [ ! -s "$BOOT" ]; then
if ! rm -f -- "$BOOT"; then
error "Failed to remove obsolete ISO file \"$BOOT\" !"
return 50
@@ -419,14 +419,14 @@ startInstall() {
return 50
fi
if [ -z "$CUSTOM" ] && [[ "${VERSION,,}" != "http"* ]]; then
if ! isCustomImage && ! isURL "$VERSION"; then
checkMemory "$VERSION" || return 67
setDiskMinimum "$VERSION" || return 67
fi
# Work from the temporary directory so the persistent source path can
# later contain either the preserved ISO or the rebuilt installation image.
if [ -z "$CUSTOM" ] && [ -f "$BOOT" ] && [ -s "$BOOT" ]; then
if ! isCustomImage && [ -f "$BOOT" ] && [ -s "$BOOT" ]; then
if ! mv -f -- "$BOOT" "$ISO"; then
error "Failed to move ISO file from \"$BOOT\" to \"$ISO\" !"
return 50
@@ -603,7 +603,7 @@ finishInstall() {
fi
if [[ "$boot" == "$STORAGE/"* ]]; then
if [[ "$aborted" != [Yy1]* ]] || [ -z "$CUSTOM" ]; then
if [[ "$aborted" != [Yy1]* ]] || ! isCustomImage; then
base=$(basename "$boot")
writeState "base" "$base" || {
@@ -615,7 +615,7 @@ finishInstall() {
fi
if [[ "${PLATFORM,,}" == "x64" ]]; then
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
if isLegacyBoot; then
writeState "mode" "$BOOT_MODE" || {
error "Failed to save the Windows boot mode!"
@@ -707,7 +707,7 @@ findFile() {
file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$fname" -print -quit) || return 1
fi
if [ ! -s "$file" ] && [[ "${VERSION,,}" != "http"* ]]; then
if [ ! -s "$file" ] && ! isURL "$VERSION"; then
base=$(basename "$VERSION")
file="$STORAGE/$base"
fi
@@ -736,7 +736,7 @@ findFile() {
normalizeDetected() {
# Known catalog versions already provide the required image metadata.
if [ -z "$DETECTED" ] && [ -z "$CUSTOM" ] && [[ "${VERSION,,}" != "http"* ]]; then
if [ -z "$DETECTED" ] && ! isCustomImage && ! isURL "$VERSION"; then
DETECTED="$VERSION"
fi
@@ -752,14 +752,14 @@ detectCustom() {
findFile "custom.iso" || return 1
if [ -n "$CUSTOM" ]; then
if isCustomImage; then
DETECTED=""
return 0
fi
findFile "boot.iso" || return 1
if [ -n "$CUSTOM" ]; then
if isCustomImage; then
DETECTED=""
return 0
fi
@@ -767,6 +767,25 @@ detectCustom() {
return 0
}
isCustomImage() {
[ -n "${CUSTOM:-}" ]
}
isURL() {
local value="$1"
[[ "${value,,}" == "http"* ]]
}
isLegacyBoot() {
local mode="${BOOT_MODE:-}"
[[ "${mode,,}" == "windows_legacy" ]]
}
hasImage() {
local iso="$1"
@@ -837,7 +856,7 @@ useOriginalImage() {
local iso="$1"
if [ -n "$CUSTOM" ]; then
if isCustomImage; then
BOOT="$iso"
elif [[ "$iso" != "$BOOT" ]]; then
if ! mv -f -- "$iso" "$BOOT"; then
@@ -858,7 +877,7 @@ removeImage() {
local iso="$1"
[ -n "$CUSTOM" ] && return 0
isCustomImage && return 0
if ! rm -f -- "$iso" 2>/dev/null; then
warn "failed to remove image \"$iso\"!"
@@ -953,7 +972,7 @@ prepareImage() {
ETFS="${ETFS:-boot/etfsboot.com}"
# Legacy rebuilt media must retain the source ISO's El Torito boot-load size.
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
if isLegacyBoot; then
getBootLoadSize "$iso" "$dir" "$desc" || return 1
@@ -961,7 +980,7 @@ prepareImage() {
supportsXML "$DETECTED" || return 0
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
if isLegacyBoot; then
extractBootImage "$iso" "$dir" "$desc" && return 0
+1 -1
View File
@@ -1277,7 +1277,7 @@ downloadImage() {
local tried="n" success="n" seconds="5"
local i url sum size base language desc web_desc rc
if [[ "${version,,}" == "http"* ]]; then
if isURL "$version"; then
base=$(basename "$iso")
desc=$(fromFile "$base")
+5 -5
View File
@@ -28,7 +28,7 @@ bootStatus() {
[ ! -s "$QEMU_PTY" ] && return 1
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
if isLegacyBoot; then
local line last recent
# Only inspect output produced after the most recent BIOS boot attempt so
@@ -130,7 +130,7 @@ waitForBoot() {
elif bootKeyReady; then
(( keyWait += 1 ))
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
if isLegacyBoot; then
# Keep the legacy fallback at about one second after the DVD marker.
if (( keyWait >= 5 )); then
if sendKey ret 0 100 6 0.25; then
@@ -265,7 +265,7 @@ ready() {
[ ! -s "$QEMU_PTY" ] && return 1
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
if isLegacyBoot; then
legacyBootReady && return 0
return 1
fi
@@ -358,7 +358,7 @@ bootKeyReady() {
[ ! -s "$QEMU_PTY" ] && return 1
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
if isLegacyBoot; then
grep -Fq "Booting from DVD/CD" "$QEMU_PTY"
return $?
fi
@@ -372,7 +372,7 @@ bootKeyReady() {
getBootMarker() {
if [[ "${BOOT_MODE,,}" == "windows_legacy" ]]; then
if isLegacyBoot; then
grep -nE "$LEGACY_BOOT_PATTERN" "$QEMU_PTY" | tail -1
return 0
fi
+1 -1
View File
@@ -388,7 +388,7 @@ isUserMode && return 0
# Older Windows versions discover shares through NetBIOS, while modern Windows
# uses Web Services Discovery.
if [[ "${BOOT_MODE:-}" == "windows_legacy" ]]; then
if isLegacyBoot; then
startNetbios || :
else
startWsddn || :