feat: Verify downloads

This commit is contained in:
Kroese 2024-05-01 19:36:43 +02:00 committed by GitHub
parent 23e2f1cbb4
commit e8b3066bc6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -272,12 +272,37 @@ doMido() {
return 1 return 1
} }
verifyFile() {
local iso="$1"
local version="$2"
local hash check
info "Calculating SHA256 checksum of the downloaded ISO file..."
hash=$(sha256sum "$iso" | cut -f1 -d' ')
[ -n "$version" ] && check=$(getHash "$version")
if [ -z "$check" ]; then
info "The sha256 checksum is: $hash , but have no value available for comparison." && return 0
fi
if [[ "$hash" == "$check" ]]; then
info "Succesfully verified that the checksum was correct!" && return 0
fi
error "Invalid sha256 checksum: $hash , expected value is: $check"
rm -f "$iso"
return 1
}
downloadFile() { downloadFile() {
local iso="$1" local iso="$1"
local url="$2" local url="$2"
local desc="$3" local desc="$3"
local rc progress domain hash local version="$4"
local rc progress domain
rm -f "$iso" rm -f "$iso"
@ -304,17 +329,15 @@ downloadFile() {
if (( rc == 0 )) && [ -f "$iso" ]; then if (( rc == 0 )) && [ -f "$iso" ]; then
if [ "$(stat -c%s "$iso")" -gt 100000000 ]; then if [ "$(stat -c%s "$iso")" -gt 100000000 ]; then
if [[ "$VERIFY" == [Yy1]* ]]; then if [[ "$VERIFY" == [Yy1]* ]]; then
info "Calculating SHA256 sum of downloaded ISO..." ! verifyFile "$iso" "$version" && return 1
hash=$(sha256sum "$iso" | cut -f1 -d' ')
info "Result: $hash"
fi fi
html "Download finished successfully..." && return 0 html "Download finished successfully..." && return 0
fi fi
fi fi
rm -f "$iso"
error "Failed to download $url , reason: $rc" error "Failed to download $url , reason: $rc"
rm -f "$iso"
return 1 return 1
} }
@ -328,7 +351,7 @@ downloadImage() {
if [[ "${version,,}" == "http"* ]]; then if [[ "${version,,}" == "http"* ]]; then
desc=$(getName "$BASE") desc=$(getName "$BASE")
downloadFile "$iso" "$version" "$desc" && return 0 downloadFile "$iso" "$version" "$desc" "" && return 0
return 1 return 1
fi fi
@ -357,7 +380,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_URL" "$desc" && return 0 downloadFile "$ISO" "$ESD_URL" "$desc" "" && return 0
ISO="$TMP/$BASE" ISO="$TMP/$BASE"
fi fi
@ -372,7 +395,7 @@ 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"
downloadFile "$iso" "$url" "$desc" && return 0 downloadFile "$iso" "$url" "$desc" "$version" && return 0
fi fi
done done