fix: Improved download

This commit is contained in:
Kroese 2024-04-24 19:28:06 +02:00 committed by GitHub
parent 26ec1de22b
commit f5212897cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -386,7 +386,6 @@ startInstall() {
getESD() { getESD() {
local dir="$1" local dir="$1"
local file="$2"
local winCatalog size local winCatalog size
case "${VERSION,,}" in case "${VERSION,,}" in
@ -449,35 +448,17 @@ getESD() {
return 0 return 0
} }
downloadImage() { doMido() {
local iso="$1" local iso="$1"
local url="$2" local url="$2"
local rc=99 local desc="$3"
local msg desc progress local rc
rm -f "$iso" rm -f "$iso"
rm -f "$iso.PART"
# Check if running with interactive TTY or redirected to docker log local msg="Downloading $desc..."
if [ -t 1 ]; then
progress="--progress=bar:noscroll"
else
progress="--progress=dot:giga"
fi
if [[ "$EXTERNAL" != [Yy1]* ]]; then
desc=$(printVersion "$VERSION" "Windows")
else
desc=$(getName "$BASE" "$BASE")
fi
if [[ "$EXTERNAL" != [Yy1]* ]]; then
msg="Downloading $desc..."
info "$msg" && html "$msg" info "$msg" && html "$msg"
/run/progress.sh "$iso.PART" "Downloading $desc ([P])..." & /run/progress.sh "$iso.PART" "Downloading $desc ([P])..." &
@ -493,32 +474,29 @@ downloadImage() {
fi fi
fi fi
if [[ "$VERSION" != "win10x64" ]] && [[ "$VERSION" != "win11x64" ]]; then rm -f "$iso"
rm -f "$iso.PART"
return 1 return 1
fi }
info "Failed to download $desc using Mido, will try a different method now..." downloadFile() {
local iso="$1"
local url="$2"
local desc="$3"
local rc progress
rm -f "$iso" rm -f "$iso"
rm -rf "$TMP"
mkdir -p "$TMP"
rc=99 # Check if running with interactive TTY or redirected to docker log
ISO="$TMP/$VERSION.esd" if [ -t 1 ]; then
iso="$ISO" progress="--progress=bar:noscroll"
rm -f "$iso" else
progress="--progress=dot:giga"
url=""
if getESD "$TMP/esd" "$iso"; then
url="$ESD_URL"
fi fi
fi local msg="Downloading $desc..."
if [ -n "$url" ]; then
msg="Downloading $desc..."
info "$msg" && html "$msg" info "$msg" && html "$msg"
/run/progress.sh "$iso" "Downloading $desc ([P])..." & /run/progress.sh "$iso" "Downloading $desc ([P])..." &
@ -532,10 +510,58 @@ downloadImage() {
fi fi
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
desc=$(printVersion "$VERSION" "Windows")
else
desc=$(getName "$BASE" "$BASE")
fi fi
if [[ "$EXTERNAL" != [Yy1]* ]]; then if [[ "$EXTERNAL" != [Yy1]* ]]; then
doMido "$iso" "$url" "$desc" && return 0
if [[ "$VERSION" != "win10${PLATFORM,,}" ]] && [[ "$VERSION" != "win11${PLATFORM,,}" ]]; then
return 1
fi
info "Failed to download $desc using Mido, will try a different method now..."
rm -rf "$TMP"
mkdir -p "$TMP"
ISO="$TMP/$VERSION.esd"
iso="$ISO"
if ! getESD "$TMP/esd"; then
url=""
else
url="$ESD_URL"
fi
fi
if [ -n "$url" ]; then
downloadFile "$iso" "$url" "$desc" && return 0
fi
[[ "$EXTERNAL" == [Yy1]* ]] && return 1
case "${VERSION,,}" in case "${VERSION,,}" in
"win11${PLATFORM,,}") "win11${PLATFORM,,}")
url="https://dl.bobpony.com/windows/11/en-us_windows_11_23h2_${PLATFORM,,}.iso" url="https://dl.bobpony.com/windows/11/en-us_windows_11_23h2_${PLATFORM,,}.iso"
@ -544,38 +570,20 @@ downloadImage() {
url="https://dl.bobpony.com/windows/10/en-us_windows_10_22h2_${PLATFORM,,}.iso" url="https://dl.bobpony.com/windows/10/en-us_windows_10_22h2_${PLATFORM,,}.iso"
;; ;;
*) *)
(( rc != 99 )) && error "Failed to download $url , reason: $rc"
return 1 return 1
;; ;;
esac esac
info "Failed to download $desc from Microsoft, will try another mirror now..." info "Failed to download $desc from Microsoft, will try another mirror now..."
rm -f "$iso"
rm -rf "$TMP" rm -rf "$TMP"
mkdir -p "$TMP" mkdir -p "$TMP"
ISO="$TMP/$BASE" ISO="$TMP/$BASE"
iso="$ISO" iso="$ISO"
rm -f "$iso"
msg="Downloading $desc..." downloadFile "$iso" "$url" "$desc" && return 0
info "$msg" && html "$msg"
/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
fi
(( rc != 99 )) && error "Failed to download $url , reason: $rc"
return 1 return 1
} }