feat: Improve Windows media detection and selection (#1946)

This commit is contained in:
Kroese
2026-07-24 16:52:14 +02:00
committed by GitHub
parent 99ac4035c7
commit c739e41e7e
6 changed files with 1025 additions and 256 deletions
+259 -6
View File
@@ -853,8 +853,8 @@ verifyFile() {
fi
fi
local hash=""
local algo="SHA256"
local hash="" rc=0
[ -z "$check" ] && return 0
! enabled "$VERIFY" && return 0
@@ -864,15 +864,31 @@ verifyFile() {
info "$msg" && html "$msg"
if [[ "${algo,,}" != "sha256" ]]; then
if ! hash=$(sha1sum "$iso" | cut -f1 -d' '); then
hash=$(sha1sum "$iso" | cut -f1 -d' ') || {
rc=$?
if (( rc >= 129 )); then
exit "$rc"
fi
error "Failed to calculate SHA1 checksum for $iso!"
return 1
fi
}
else
if ! hash=$(sha256sum "$iso" | cut -f1 -d' '); then
hash=$(sha256sum "$iso" | cut -f1 -d' ') || {
rc=$?
if (( rc >= 129 )); then
exit "$rc"
fi
error "Failed to calculate SHA256 checksum for $iso!"
return 1
fi
}
fi
if [[ "$hash" == "$check" ]]; then
@@ -993,11 +1009,237 @@ fallbackEnglish() {
downloadImage "$iso" "$version" "$LANGUAGE"
}
testDownload() {
local file="$1"
local url="$2"
local sum="$3"
local size="$4"
local desc="$5"
local web_desc="$6"
local total failed=""
if ! rm -f -- "$file" "$file.aria2"; then
error "Failed to remove previous test download: $file"
return 1
fi
# Call downloadFile() directly so downloadRetry(), delays and retries
# from the normal installation path are not used.
if ! downloadFile \
"$file" \
"$url" \
"$size" \
"$desc" \
"$web_desc" \
"${CONNECTIONS:-1}"; then
failed="Y"
elif ! total=$(stat -c%s -- "$file" 2>/dev/null); then
error "Failed to determine downloaded file size: $file"
failed="Y"
else
if [ -n "$size" ] && [[ "$size" != "0" && "$total" != "$size" ]]; then
error "The downloaded file has a different size ( $total bytes) than expected ( $size bytes)."
failed="Y"
fi
# Size was checked strictly above. Passing an empty expected size avoids
# the normal warning-only size handling while still verifying the hash.
if ! verifyFile "$file" "" "$total" "$sum"; then
failed="Y"
fi
fi
if ! rm -f -- "$file" "$file.aria2"; then
error "Failed to remove test download: $file"
failed="Y"
fi
[ -z "$failed" ]
}
downloadTest() {
local version="$1"
local lang="$2"
local normal="$version"
local dir="$STORAGE/tmp/download-test"
local file="$dir/test.iso"
local tested=0 failed=0
local url sum size base desc web_desc language i
# Dynamically scoped, so verifyFile() validates every available checksum.
local VERIFY="Y"
if ! rm -rf -- "$dir" || ! makeDir "$dir"; then
error "Failed to create download test directory: $dir"
return 1
fi
if [[ "${version,,}" == "http"* ]]; then
base=$(basename "${version%%\?*}")
desc=$(fromFile "$base")
web_desc="$desc"
tested=$((tested + 1))
info "Testing custom download..."
if ! testDownload "$file" "$version" "" "" "$desc" "$web_desc"; then
failed=$((failed + 1))
fi
else
if ! validVersion "$version" "en"; then
error "Invalid VERSION specified, value \"$version\" is not recognized!"
rm -rf -- "$dir" 2>/dev/null || true
return 1
fi
desc=$(printVariant "$version" "" "Y")
web_desc=$(printVariant "$version" "")
if [[ "${lang,,}" != "en" && "${lang,,}" != "en-"* ]]; then
language=$(getLanguage "$lang" "desc")
desc+=" in $language"
web_desc+=" in $language"
fi
if isMido "$version" "$lang"; then
tested=$((tested + 1))
MIDO_URL=""
info "Testing MIDO download..."
if ! getWindows "$version" "$lang" "$desc" "$web_desc" ||
[ -z "$MIDO_URL" ]; then
failed=$((failed + 1))
else
url=$(getMido "$version" "$lang" "")
sum=""
size=""
# Skip static verification if Microsoft returned a different URL.
if [[ "${MIDO_URL%%\?*}" == "${url%%\?*}" ]]; then
size=$(getMido "$version" "$lang" "size")
sum=$(getMido "$version" "$lang" "sum")
fi
if ! testDownload \
"$file" \
"$MIDO_URL" \
"$sum" \
"$size" \
"$desc" \
"$web_desc"; then
failed=$((failed + 1))
fi
fi
fi
# Evaluation media only exists through MIDO. ESD and mirrors use the
# corresponding normal version.
[[ "${normal,,}" == *"-eval" ]] && normal="${normal::-5}"
desc=$(printVariant "$normal" "" "Y")
web_desc=$(printVariant "$normal" "")
if [[ "${lang,,}" != "en" && "${lang,,}" != "en-"* ]]; then
desc+=" in $language"
web_desc+=" in $language"
fi
if isESD "$normal" "$lang"; then
tested=$((tested + 1))
ESD=""
info "Testing ESD download..."
if ! getESD "$dir/esd" "$normal" "$lang" "$desc"; then
failed=$((failed + 1))
elif ! testDownload \
"$dir/test.esd" \
"$ESD" \
"$ESD_SUM" \
"$ESD_SIZE" \
"$desc" \
"$web_desc"; then
failed=$((failed + 1))
fi
fi
for ((i=1;i<=MIRRORS;i++)); do
url=$(getLink "$i" "$normal" "$lang")
[ -z "$url" ] && continue
tested=$((tested + 1))
size=$(getSize "$i" "$normal" "$lang")
sum=$(getHash "$i" "$normal" "$lang")
info "Testing download mirror $i: $(getHost "$url")..."
if ! testDownload \
"$file" \
"$url" \
"$sum" \
"$size" \
"$desc" \
"$web_desc"; then
failed=$((failed + 1))
fi
done
fi
if ! rm -rf -- "$dir"; then
error "Failed to remove download test directory: $dir"
failed=$((failed + 1))
fi
if (( tested == 0 )); then
error "No download methods are available for $version."
return 1
fi
if (( failed > 0 )); then
error "$failed of $tested download methods failed."
return 1
fi
info "All $tested download methods completed successfully."
return 0
}
testImages() {
disabled "${TEST:-}" && return 0
if downloadTest "$VERSION" "$LANGUAGE"; then
info "Download test completed successfully."
exit 0
fi
error "Download test failed."
exit 61
}
downloadImage() {
local iso="$1"
local version="$2"
local lang="$3"
local requested="$version"
local tried="n"
local success="n"
local seconds="5"
@@ -1073,6 +1315,17 @@ downloadImage() {
fi
fi
if switchEdition version; then
desc=$(printVariant "$DETECTED" "" "Y")
web_desc=$(printVariant "$DETECTED" "")
if [[ "${lang,,}" != "en" && "${lang,,}" != "en-"* ]]; then
desc+=" in $language"
fi
fi
if isESD "$version" "$lang"; then
if [[ "$tried" != "n" ]]; then
@@ -1122,7 +1375,7 @@ downloadImage() {
done
if [[ "${lang,,}" != "en" && "${lang,,}" != "en-"* ]]; then
if fallbackEnglish "$iso" "$version" "$lang" "$desc" "$web_desc"; then
if fallbackEnglish "$iso" "$requested" "$lang" "$desc" "$web_desc"; then
return 0
fi
fi