fix: Stop falling back to manual setup on errors (#2101)

This commit is contained in:
Kroese
2026-08-07 07:48:25 +02:00
committed by GitHub
parent 84eabc07fb
commit 543060fd95
3 changed files with 106 additions and 72 deletions
+8 -8
View File
@@ -69,7 +69,7 @@ setXML() {
CUSTOM_XML="" CUSTOM_XML=""
removeGeneratedXML "$target" || return 1 removeGeneratedXML "$target" || return 2
if [ -d "${custom_files[0]}" ]; then if [ -d "${custom_files[0]}" ]; then
error "The bind ${custom_files[0]} maps to a file that does not exist!" error "The bind ${custom_files[0]} maps to a file that does not exist!"
@@ -98,7 +98,7 @@ setXML() {
if [[ "${DETECTED,,}" == *"-eval" ]] && if [[ "${DETECTED,,}" == *"-eval" ]] &&
{ [ ! -f "$file" ] || [ ! -s "$file" ]; }; then { [ ! -f "$file" ] || [ ! -s "$file" ]; }; then
generateEvalXML "$DETECTED" "$index" || return 1 generateEvalXML "$DETECTED" "$index" || return $?
file="$target" file="$target"
elif [ ! -f "$file" ] || [ ! -s "$file" ]; then elif [ ! -f "$file" ] || [ ! -s "$file" ]; then
@@ -107,7 +107,7 @@ setXML() {
elif [[ "$file" != "$target" ]]; then elif [[ "$file" != "$target" ]]; then
generateFallbackXML "$DETECTED" "$index" || return 1 generateFallbackXML "$DETECTED" "$index" || return $?
file="$target" file="$target"
fi fi
@@ -340,12 +340,12 @@ generateEvalXML() {
local target="/run/assets/$id.xml" local target="/run/assets/$id.xml"
local source="/run/assets/$normal.xml" local source="/run/assets/$normal.xml"
removeGeneratedXML "$source" || return 1 removeGeneratedXML "$source" || return 2
if [ ! -s "$source" ]; then if [ ! -s "$source" ]; then
source="/run/assets/${normal%%-*}.xml" source="/run/assets/${normal%%-*}.xml"
removeGeneratedXML "$source" || return 1 removeGeneratedXML "$source" || return 2
fi fi
@@ -361,7 +361,7 @@ generateEvalXML() {
esac esac
fi fi
generateAnswerFile "$id" "$source" "$target" "$index" "evaluation" "$remove_selector" || return 1 generateAnswerFile "$id" "$source" "$target" "$index" "evaluation" "$remove_selector" || return 2
return 0 return 0
} }
@@ -379,11 +379,11 @@ generateFallbackXML() {
[ "$source" != "$target" ] || return 1 [ "$source" != "$target" ] || return 1
removeGeneratedXML "$source" || return 1 removeGeneratedXML "$source" || return 2
[ -s "$source" ] || return 1 [ -s "$source" ] || return 1
generateAnswerFile "$id" "$source" "$target" "$index" "fallback" "Y" || return 1 generateAnswerFile "$id" "$source" "$target" "$index" "fallback" "Y" || return 2
return 0 return 0
} }
+58 -34
View File
@@ -796,28 +796,28 @@ detectLegacy() {
# Legacy media is identified from setup marker files rather than WIM # Legacy media is identified from setup marker files rather than WIM
# metadata. The order is intentional because several releases share markers. # metadata. The order is intentional because several releases share markers.
marker=$(find "$dir" -maxdepth 1 -type d -iname 'ia64' -print -quit) || return 1 marker=$(find "$dir" -maxdepth 1 -type d -iname 'ia64' -print -quit) || return 2
if [ -n "$marker" ]; then if [ -n "$marker" ]; then
error "Windows IA-64 (Itanium) images are not supported by this container!" error "Windows IA-64 (Itanium) images are not supported by this container!"
exit 67 exit 67
fi fi
marker=$(find "$dir" -maxdepth 1 -type d -iname WIN95 -print -quit) || return 1 marker=$(find "$dir" -maxdepth 1 -type d -iname WIN95 -print -quit) || return 2
if [ -n "$marker" ]; then if [ -n "$marker" ]; then
DETECTED="win95" DETECTED="win95"
return 0 return 0
fi fi
marker=$(find "$dir" -maxdepth 1 -type d -iname WIN98 -print -quit) || return 1 marker=$(find "$dir" -maxdepth 1 -type d -iname WIN98 -print -quit) || return 2
if [ -n "$marker" ]; then if [ -n "$marker" ]; then
DETECTED="win98" DETECTED="win98"
return 0 return 0
fi fi
marker=$(find "$dir" -maxdepth 1 -type d -iname WIN9X -print -quit) || return 1 marker=$(find "$dir" -maxdepth 1 -type d -iname WIN9X -print -quit) || return 2
if [ -n "$marker" ]; then if [ -n "$marker" ]; then
DETECTED="win9x" DETECTED="win9x"
@@ -830,14 +830,14 @@ detectLegacy() {
-iname CDROM_S.40 -o \ -iname CDROM_S.40 -o \
-iname CDROM_TS.40 \ -iname CDROM_TS.40 \
\) \ \) \
-print -quit) || return 1 -print -quit) || return 2
if [ -n "$marker" ]; then if [ -n "$marker" ]; then
DETECTED="winnt4" DETECTED="winnt4"
return 0 return 0
fi fi
marker=$(find "$dir" -maxdepth 1 -type f -iname CDROM_NT.5 -print -quit) || return 1 marker=$(find "$dir" -maxdepth 1 -type f -iname CDROM_NT.5 -print -quit) || return 2
if [ -n "$marker" ]; then if [ -n "$marker" ]; then
@@ -848,7 +848,7 @@ detectLegacy() {
-iname CDROM_IP.5 -o \ -iname CDROM_IP.5 -o \
-iname CDROM_IS.5 \ -iname CDROM_IS.5 \
\) \ \) \
-print -quit) || return 1 -print -quit) || return 2
if [ -n "$marker" ]; then if [ -n "$marker" ]; then
DETECTED="win2k" DETECTED="win2k"
@@ -859,10 +859,10 @@ detectLegacy() {
# WIN51 identifies the NT 5.1/5.2 media family; the companion marker then # WIN51 identifies the NT 5.1/5.2 media family; the companion marker then
# distinguishes XP x86, XP x64, and Server 2003. # distinguishes XP x86, XP x64, and Server 2003.
marker=$(find "$dir" -maxdepth 1 -iname WIN51 -print -quit) || return 1 marker=$(find "$dir" -maxdepth 1 -iname WIN51 -print -quit) || return 2
[ -n "$marker" ] || return 1 [ -n "$marker" ] || return 1
marker=$(find "$dir" -maxdepth 1 -type f -iname WIN51AP -print -quit) || return 1 marker=$(find "$dir" -maxdepth 1 -type f -iname WIN51AP -print -quit) || return 2
if [ -n "$marker" ]; then if [ -n "$marker" ]; then
DETECTED="winxpx64" DETECTED="winxpx64"
@@ -875,7 +875,7 @@ detectLegacy() {
-iname WIN51IP -o \ -iname WIN51IP -o \
-iname setupxp.htm \ -iname setupxp.htm \
\) \ \) \
-print -quit) || return 1 -print -quit) || return 2
if [ -n "$marker" ]; then if [ -n "$marker" ]; then
DETECTED="winxpx86" DETECTED="winxpx86"
@@ -896,7 +896,7 @@ detectLegacy() {
-iname WIN51MD -o \ -iname WIN51MD -o \
-iname WIN51MP \ -iname WIN51MP \
\) \ \) \
-print -quit) || return 1 -print -quit) || return 2
if [ -n "$marker" ]; then if [ -n "$marker" ]; then
DETECTED="win2003r2" DETECTED="win2003r2"
@@ -913,7 +913,7 @@ detectReactOS() {
local marker local marker
marker=$(find "$dir" -maxdepth 2 -type f \ marker=$(find "$dir" -maxdepth 2 -type f \
\( -ipath '*/reactos/reactos.inf' -o -ipath '*/reactos/unattend.inf' \) -print -quit) || return 1 \( -ipath '*/reactos/reactos.inf' -o -ipath '*/reactos/unattend.inf' \) -print -quit) || return 2
[ -n "$marker" ] || return 1 [ -n "$marker" ] || return 1
@@ -1183,7 +1183,7 @@ findImage() {
local dir="$1" local dir="$1"
local name sources result local name sources result
sources=$(find "$dir" -maxdepth 1 -type d -iname sources -print -quit) || return 1 sources=$(find "$dir" -maxdepth 1 -type d -iname sources -print -quit) || return 2
if [ ! -d "$sources" ]; then if [ ! -d "$sources" ]; then
warn "failed to locate 'sources' folder in ISO image, $FB" warn "failed to locate 'sources' folder in ISO image, $FB"
@@ -1191,7 +1191,7 @@ findImage() {
fi fi
for name in install.wim install.esd; do for name in install.wim install.esd; do
result=$(find "$sources" -maxdepth 1 -type f -iname "$name" -print -quit) || return 1 result=$(find "$sources" -maxdepth 1 -type f -iname "$name" -print -quit) || return 2
[ -n "$result" ] && break [ -n "$result" ] && break
done done
@@ -1220,8 +1220,8 @@ readImageInfo() {
} }
if [ -z "$result" ]; then if [ -z "$result" ]; then
warn "failed to read Windows image information, $FB" error "Failed to read Windows image information!"
return 1 return 2
fi fi
printf '%s' "$result" printf '%s' "$result"
@@ -1261,16 +1261,21 @@ validateEdition() {
unknownImage() { unknownImage() {
local msg="Failed to determine Windows version from image" local msg="Failed to determine Windows version from image"
local rc=0
# Unknown media can continue when a custom answer file or manual mode already setXML "" || rc=$?
# provides the required installation path; otherwise force manual fallback.
if setXML "" || enabled "$MANUAL"; then if (( rc == 0 )) || enabled "$MANUAL"; then
info "${msg}!" info "${msg}!"
else return 0
MANUAL="Y"
warn "${msg}, $FB."
fi fi
# Only absence of a usable answer file is a supported manual fallback.
(( rc == 1 )) || return "$rc"
MANUAL="Y"
warn "${msg}, $FB."
return 0 return 0
} }
@@ -1294,9 +1299,20 @@ configureImage() {
local index="$1" local index="$1"
local desc="$2" local desc="$2"
local rc=0
# Prefer the exact answer file, then a family-level fallback. Manual mode is # Prefer the exact answer file, then a family-level fallback. Manual mode is
# the final supported path when neither can be generated. # the final supported path only when no usable template exists.
setXML "" "$index" && return 0 setXML "" "$index" || rc=$?
if (( rc == 0 )); then
return 0
fi
enabled "$MANUAL" && return 0
# Generation or preparation errors must not be hidden by another fallback.
(( rc == 1 )) || return "$rc"
if [[ "$DETECTED" == "win81x86"* || "$DETECTED" == "win10x86"* ]]; then if [[ "$DETECTED" == "win81x86"* || "$DETECTED" == "win10x86"* ]]; then
error "The 32-bit version of $desc is not supported!" error "The 32-bit version of $desc is not supported!"
@@ -1306,15 +1322,19 @@ configureImage() {
local msg="the answer file for $desc was not found ($DETECTED.xml)" local msg="the answer file for $desc was not found ($DETECTED.xml)"
local fallback="/run/assets/${DETECTED%%-*}.xml" local fallback="/run/assets/${DETECTED%%-*}.xml"
if setXML "$fallback" "$index"; then rc=0
if ! enabled "$MANUAL"; then setXML "$fallback" "$index" || rc=$?
warn "${msg}."
fi if (( rc == 0 )); then
warn "${msg}."
return 0 return 0
fi fi
enabled "$MANUAL" && return 0 enabled "$MANUAL" && return 0
# The family-level template was present but could not be generated/prepared.
(( rc == 1 )) || return "$rc"
MANUAL="Y" MANUAL="Y"
warn "${msg}, $FB." warn "${msg}, $FB."
@@ -1361,14 +1381,18 @@ detectIsoImage() {
local iso="$1" local iso="$1"
local image header image_info local image header image_info rc
# Return 1 when direct ISO inspection is unavailable so the caller may fall
# back to extraction; return 2 when metadata was read but configuration failed.
# Return 1 only when no directly inspectable WIM/ESD payload is available so
# the caller may extract the media. Metadata parsing/configuration errors use 2.
image=$(findIsoImage "$iso") || return 1 image=$(findIsoImage "$iso") || return 1
header=$(readWimHeader "$iso" "$image") || return 1 header=$(readWimHeader "$iso" "$image") || return 2
image_info=$(readIsoImageInfo "$iso" "$image" "$header") || return $?
image_info=$(readIsoImageInfo "$iso" "$image" "$header") || {
rc=$?
(( rc >= 129 )) && return "$rc"
return 2
}
info "Detecting version from ISO image..." info "Detecting version from ISO image..."
detectImageInfo "$image_info" || return 2 detectImageInfo "$image_info" || return 2
+40 -30
View File
@@ -79,9 +79,7 @@ selectWindowsImage() {
# Only code 1 indicates that extraction may recover detection. # Only code 1 indicates that extraction may recover detection.
if (( detect_rc != 1 )); then if (( detect_rc != 1 )); then
skipUnattended "$dir" "$iso" "$boot" || return 76 return 76
handled=1
return 0
fi fi
if ! extractImage "$iso" "$dir" "$VERSION"; then if ! extractImage "$iso" "$dir" "$VERSION"; then
@@ -102,6 +100,10 @@ selectWindowsImage() {
return "$detect_rc" return "$detect_rc"
fi fi
if (( detect_rc != 1 )); then
return 76
fi
skipUnattended "$dir" "$iso" "$boot" || return 76 skipUnattended "$dir" "$iso" "$boot" || return 76
handled=1 handled=1
@@ -116,11 +118,7 @@ configureMachine() {
local desc local desc
if ! desc=$(printVariant "$DETECTED" "$DETECTED"); then desc=$(printVariant "$DETECTED" "$DETECTED") || return 78
skipUnattended "$dir" "$iso" "$boot" || return 78
handled=1
return 0
fi
if ! checkMemory "$DETECTED" "$desc"; then if ! checkMemory "$DETECTED" "$desc"; then
if [ -n "${REUSED_ISO:-}" ]; then if [ -n "${REUSED_ISO:-}" ]; then
@@ -130,15 +128,11 @@ configureMachine() {
fi fi
if ! setMachine "$DETECTED" "$iso" "$dir" "$desc"; then if ! setMachine "$DETECTED" "$iso" "$dir" "$desc"; then
skipUnattended "$dir" "$iso" "$boot" || return 80 return 80
handled=1
return 0
fi fi
if ! restoreMachineState; then if ! restoreMachineState; then
skipUnattended "$dir" "$iso" "$boot" || return 82 return 82
handled=1
return 0
fi fi
if ! supportsUnattended "$DETECTED"; then if ! supportsUnattended "$DETECTED"; then
@@ -160,9 +154,7 @@ prepareWindowsImage() {
if supportsXML "$DETECTED"; then if supportsXML "$DETECTED"; then
if ! createOverlay "$XML" "$LANGUAGE" "$TMP/setup"; then if ! createOverlay "$XML" "$LANGUAGE" "$TMP/setup"; then
skipUnattended "$dir" "$iso" "$boot" || return 84 return 84
handled=1
return 0
fi fi
if ! createSetupImage "$TMP/setup" "$STORAGE/setup.img"; then if ! createSetupImage "$TMP/setup" "$STORAGE/setup.img"; then
@@ -186,9 +178,7 @@ prepareWindowsImage() {
fi fi
if ! prepareImage "$iso" "$dir"; then if ! prepareImage "$iso" "$dir"; then
skipUnattended "$dir" "$iso" "$boot" || return 92 return 92
handled=1
return 0
fi fi
removeImage "$iso" || return 96 removeImage "$iso" || return 96
@@ -684,14 +674,19 @@ setImage() {
supportsXML "${DETECTED,,}" || return 0 supportsXML "${DETECTED,,}" || return 0
setXML "" && return 0 local rc=0
setXML "" || rc=$?
if (( rc == 0 )); then
return 0
fi
enabled "$MANUAL" && return 0 enabled "$MANUAL" && return 0
# If a usable source template exists, setXML failed while preparing it. # Only a genuinely missing answer file may fall back to manual setup.
# That is an installation error and must not fall back to manual setup. (( rc == 1 )) || return "$rc"
hasAnswerFile "$DETECTED" && return 1
# A genuinely missing answer file is a supported manual-install path.
MANUAL="Y" MANUAL="Y"
local desc local desc
@@ -906,24 +901,39 @@ detectImage() {
local dir="$1" local dir="$1"
local desc local desc detect_rc=0
info "Detecting version from ISO image..." info "Detecting version from ISO image..."
# Marker-based legacy and ReactOS detection must run before looking for a WIM. # Marker-based legacy and ReactOS detection must run before looking for a WIM.
if detectLegacy "$dir" || detectReactOS "$dir"; then detectLegacy "$dir" || detect_rc=$?
desc=$(printEdition "$DETECTED" "$DETECTED" "Y") || return 1
if (( detect_rc == 0 )); then
desc=$(printEdition "$DETECTED" "$DETECTED" "Y") || return 2
info "Detected: $desc" info "Detected: $desc"
return 0 return 0
fi fi
(( detect_rc == 1 )) || return "$detect_rc"
detect_rc=0
detectReactOS "$dir" || detect_rc=$?
if (( detect_rc == 0 )); then
desc=$(printEdition "$DETECTED" "$DETECTED" "Y") || return 2
info "Detected: $desc"
return 0
fi
(( detect_rc == 1 )) || return "$detect_rc"
local wim local wim
wim=$(findImage "$dir") || return 1 wim=$(findImage "$dir") || return $?
local image_info local image_info
image_info=$(readImageInfo "$wim") || return $? image_info=$(readImageInfo "$wim") || return $?
detectImageInfo "$image_info" detectImageInfo "$image_info" || return 2
} }
prepareImage() { prepareImage() {