feat: Show download percentage
This commit is contained in:
parent
fe45fd5f5a
commit
861dfbb47c
1 changed files with 79 additions and 26 deletions
105
src/install.sh
105
src/install.sh
|
|
@ -210,7 +210,7 @@ getESD() {
|
||||||
local eFile="esd_edition.xml"
|
local eFile="esd_edition.xml"
|
||||||
local fFile="products_filter.xml"
|
local fFile="products_filter.xml"
|
||||||
|
|
||||||
{ wget "$winCatalog" -O "$dir/$wFile" -q; rc=$?; } || :
|
{ wget "$winCatalog" -O "$dir/$wFile" -q --timeout=10; rc=$?; } || :
|
||||||
(( rc != 0 )) && error "Failed to download $winCatalog , reason: $rc" && return 1
|
(( rc != 0 )) && error "Failed to download $winCatalog , reason: $rc" && return 1
|
||||||
|
|
||||||
cd "$dir"
|
cd "$dir"
|
||||||
|
|
@ -240,34 +240,86 @@ getESD() {
|
||||||
error "Failed to find Windows product in $eFile!" && return 1
|
error "Failed to find Windows product in $eFile!" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ESD=$(xmllint --nonet --xpath '//FilePath' "$dir/$eFile" | sed -E -e 's/<[\/]?FilePath>//g')
|
local tag="FilePath"
|
||||||
|
ESD=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" | sed -E -e "s/<[\/]?$tag>//g")
|
||||||
|
|
||||||
if [ -z "$ESD" ]; then
|
if [ -z "$ESD" ]; then
|
||||||
error "Failed to find ESD URL in $eFile!" && return 1
|
error "Failed to find ESD URL in $eFile!" && return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
tag="Sha1"
|
||||||
|
ESD_SUM=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" | sed -E -e "s/<[\/]?$tag>//g")
|
||||||
|
tag="Size"
|
||||||
|
ESD_SIZE=$(xmllint --nonet --xpath "//$tag" "$dir/$eFile" | sed -E -e "s/<[\/]?$tag>//g")
|
||||||
|
|
||||||
rm -rf "$dir"
|
rm -rf "$dir"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doMido() {
|
||||||
|
|
||||||
|
local iso="$1"
|
||||||
|
local version="$2"
|
||||||
|
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 "${version,,}"; 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
|
||||||
|
}
|
||||||
|
|
||||||
verifyFile() {
|
verifyFile() {
|
||||||
|
|
||||||
local iso="$1"
|
local iso="$1"
|
||||||
local check="$2"
|
local size="$2"
|
||||||
|
local total="$3"
|
||||||
|
local check="$4"
|
||||||
|
|
||||||
|
if [ -n "$size" ] && [[ "$total" != "$size" ]]; then
|
||||||
|
[[ "$size" != "0" ]] && warn "The download file has an unexpected size: $total"
|
||||||
|
fi
|
||||||
|
|
||||||
local hash=""
|
local hash=""
|
||||||
|
local algo="SHA256"
|
||||||
|
|
||||||
[ -z "$check" ] && return 0
|
[ -z "$check" ] && return 0
|
||||||
|
[[ "$VERIFY" != [Yy1]* ]] && return 0
|
||||||
|
[[ "${#check}" == "40" ]] && algo="SHA1"
|
||||||
|
|
||||||
html "Verifying downloaded ISO..."
|
local msg="Verifying downloaded ISO..."
|
||||||
info "Calculating SHA256 checksum of the ISO file..."
|
info "$msg" && html "$msg"
|
||||||
|
|
||||||
hash=$(sha256sum "$iso" | cut -f1 -d' ')
|
if [[ "${algo,,}" != "sha256" ]]; then
|
||||||
|
hash=$(sha1sum "$iso" | cut -f1 -d' ')
|
||||||
|
else
|
||||||
|
hash=$(sha256sum "$iso" | cut -f1 -d' ')
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ "$hash" == "$check" ]]; then
|
if [[ "$hash" == "$check" ]]; then
|
||||||
info "Succesfully verified that the checksum was correct!" && return 0
|
info "Succesfully verified that the checksum was correct!" && return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
error "Invalid sha256 checksum: $hash , but expected value is: $check ! Please report this at $SUPPORT/issues"
|
error "Invalid $algo checksum: $hash , but expected value is: $check ! Please report this at $SUPPORT/issues"
|
||||||
|
|
||||||
rm -f "$iso"
|
rm -f "$iso"
|
||||||
return 1
|
return 1
|
||||||
|
|
@ -278,8 +330,9 @@ downloadFile() {
|
||||||
local iso="$1"
|
local iso="$1"
|
||||||
local url="$2"
|
local url="$2"
|
||||||
local sum="$3"
|
local sum="$3"
|
||||||
local desc="$4"
|
local size="$4"
|
||||||
local rc progress domain dots
|
local desc="$5"
|
||||||
|
local rc total progress domain dots
|
||||||
|
|
||||||
rm -f "$iso"
|
rm -f "$iso"
|
||||||
|
|
||||||
|
|
@ -291,6 +344,7 @@ downloadFile() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local msg="Downloading $desc..."
|
local msg="Downloading $desc..."
|
||||||
|
html "$msg"
|
||||||
|
|
||||||
domain=$(echo "$url" | awk -F/ '{print $3}')
|
domain=$(echo "$url" | awk -F/ '{print $3}')
|
||||||
dots=$(echo "$domain" | tr -cd '.' | wc -c)
|
dots=$(echo "$domain" | tr -cd '.' | wc -c)
|
||||||
|
|
@ -300,18 +354,17 @@ downloadFile() {
|
||||||
msg="Downloading $desc from $domain..."
|
msg="Downloading $desc from $domain..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "$msg" && html "$msg"
|
info "$msg"
|
||||||
/run/progress.sh "$iso" "Downloading $desc ([P])..." &
|
/run/progress.sh "$iso" "$size" "Downloading $desc ([P])..." &
|
||||||
|
|
||||||
{ wget "$url" -O "$iso" -q --show-progress "$progress"; rc=$?; } || :
|
{ wget "$url" -O "$iso" -q --timeout=10 --show-progress "$progress"; rc=$?; } || :
|
||||||
|
|
||||||
fKill "progress.sh"
|
fKill "progress.sh"
|
||||||
|
|
||||||
if (( rc == 0 )) && [ -f "$iso" ]; then
|
if (( rc == 0 )) && [ -f "$iso" ]; then
|
||||||
if [ "$(stat -c%s "$iso")" -gt 100000000 ]; then
|
total=$(stat -c%s "$iso")
|
||||||
if [[ "$VERIFY" == [Yy1]* ]] && [ -n "$sum" ]; then
|
if [ "$total" -gt 100000000 ]; then
|
||||||
! verifyFile "$iso" "$sum" && return 1
|
! verifyFile "$iso" "$size" "$total" "$sum" && return 1
|
||||||
fi
|
|
||||||
html "Download finished successfully..." && return 0
|
html "Download finished successfully..." && return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
@ -327,11 +380,11 @@ downloadImage() {
|
||||||
local iso="$1"
|
local iso="$1"
|
||||||
local version="$2"
|
local version="$2"
|
||||||
local tried="n"
|
local tried="n"
|
||||||
local url sum desc
|
local url sum size desc
|
||||||
|
|
||||||
if [[ "${version,,}" == "http"* ]]; then
|
if [[ "${version,,}" == "http"* ]]; then
|
||||||
desc=$(fromFile "$BASE")
|
desc=$(fromFile "$BASE")
|
||||||
downloadFile "$iso" "$version" "" "$desc" && return 0
|
downloadFile "$iso" "$version" "" "" "$desc" && return 0
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -341,14 +394,13 @@ downloadImage() {
|
||||||
|
|
||||||
desc=$(printVersion "$version" "")
|
desc=$(printVersion "$version" "")
|
||||||
|
|
||||||
if [[ "${PLATFORM,,}" == "x64" ]]; then
|
if isMido "$version"; then
|
||||||
if isMido "$version"; then
|
tried="y"
|
||||||
tried="y"
|
doMido "$iso" "$version" "$desc" && return 0
|
||||||
doMido "$iso" "$version" "$desc" && return 0
|
|
||||||
fi
|
|
||||||
switchEdition "$version"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
switchEdition "$version"
|
||||||
|
|
||||||
if isESD "$version"; then
|
if isESD "$version"; then
|
||||||
|
|
||||||
if [[ "$tried" != "n" ]]; then
|
if [[ "$tried" != "n" ]]; then
|
||||||
|
|
@ -359,7 +411,7 @@ downloadImage() {
|
||||||
|
|
||||||
if getESD "$TMP/esd" "$version"; then
|
if getESD "$TMP/esd" "$version"; then
|
||||||
ISO="$TMP/$version.esd"
|
ISO="$TMP/$version.esd"
|
||||||
downloadFile "$ISO" "$ESD" "" "$desc" && return 0
|
downloadFile "$ISO" "$ESD" "$ESD_SUM" "$ESD_SIZE" "$desc" && return 0
|
||||||
ISO="$TMP/$BASE"
|
ISO="$TMP/$BASE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -374,8 +426,9 @@ downloadImage() {
|
||||||
info "Failed to download $desc, will try another mirror now..."
|
info "Failed to download $desc, will try another mirror now..."
|
||||||
fi
|
fi
|
||||||
tried="y"
|
tried="y"
|
||||||
|
size=$(getSize "$i" "$version")
|
||||||
sum=$(getHash "$i" "$version")
|
sum=$(getHash "$i" "$version")
|
||||||
downloadFile "$iso" "$url" "$sum" "$desc" && return 0
|
downloadFile "$iso" "$url" "$sum" "$size" "$desc" && return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue