build: improvements to download function
Don't list files when extracting to avoid excessive output in terminal
Be more explicit about which usages of the SHA256 hash are file paths
@@ -4,22 +4,37 @@ path="$1"
url="$2"
sha256="$3"
-curl --silent --show-error --location --compressed --output "$sha256" "$url"
-echo "$sha256 $sha256" | sha256sum -c -
+_verify_download() {
+ local hash="$1"
+ echo "${hash} ${hash}.download" | sha256sum -c -
+}
+
+curl --silent --show-error --location --compressed --output "${sha256}.download" "$url"
+
+if ! _verify_download "$sha256"; then
+ echo "Downloaded file does not match expected checksum!"
+ echo ""
+ echo " expected: ${sha256}"
+ echo " actual: $(sha256sum "${sha256}.download" | cut -d' ' -f1)"
+ echo ""
+
+ exit 1
+fi
+
file=$(basename "$url")
case "$file" in
*.tar.*) mkdir -p "$path"
- tar -xf "$sha256" -C "$path" --strip-components=1
- rm "$sha256"
+ tar -xf "$sha256.download" -C "$path" --strip-components=1
+ rm "$sha256.download"
;;
*.zip) temp=$(mktemp -d)
- unzip -d "$temp" "$sha256"
+ unzip -q -d "$temp" "$sha256.download"
mkdir -p "$path"
mv "$temp"/*/* "$path" # "$temp"/*/* has the same effect as tar's --strip-components=1
rm -rf "$temp"
- rm "$sha256"
+ rm "$sha256.download"
;;
- *) mv "$sha256" "$path"
+ *) mv "$sha256.download" "$path"
;;
esac
