Add compare_checksum function to raspi-flash

main
Ian Mancini 3 years ago
parent bd7a064b37
commit 05238c9556

@ -37,6 +37,17 @@ download() {
else exit 1; fi else exit 1; fi
} }
compare_checksum() {
echo "Checking sha256 hashes"
sum=$(sha256sum "$1" | cut -f 1 -d ' ')
if [ "$sum" = "$2" ]; then
echo "Checksum matches"
else
echo "Checksum doesn't match. Remove file and download again"
exit 1
fi
}
extract() { extract() {
printf "Will extract %s in %s\nExtracted size: %s\nAvailable space: %s\n\n" \ printf "Will extract %s in %s\nExtracted size: %s\nAvailable space: %s\n\n" \
"$1" "$DOWNLOADS_DIR" "$2" "$(check_available_space)" "$1" "$DOWNLOADS_DIR" "$2" "$(check_available_space)"
@ -46,14 +57,6 @@ extract() {
if [[ $continue =~ [yY] ]]; then if [[ $continue =~ [yY] ]]; then
echo "Extracting..." echo "Extracting..."
unzip "$DOWNLOADS_DIR/$1" -d "$DOWNLOADS_DIR" unzip "$DOWNLOADS_DIR/$1" -d "$DOWNLOADS_DIR"
echo "Checking sha256 hashes"
sum=$(sha256sum "$3" | cut -f 1 -d ' ')
if [ "$sum" = "$4" ]; then
echo "Checksum matches"
else
echo "Checksum doesn't match. Remove file and download again"
exit 1
fi
else exit 1; fi else exit 1; fi
} }
@ -108,7 +111,8 @@ else
fi fi
[ $should_download = TRUE ] && download "$ZIP_FILENAME" "${SELECTION_DATA[3]}M" "${SELECTION_DATA[2]}" [ $should_download = TRUE ] && download "$ZIP_FILENAME" "${SELECTION_DATA[3]}M" "${SELECTION_DATA[2]}"
[ $should_extract = TRUE ] && extract "$ZIP_FILENAME" "${SELECTION_DATA[4]}M" "$IMG_FILENAME" "${SELECTION_DATA[5]}" [ $should_extract = TRUE ] && extract "$ZIP_FILENAME" "${SELECTION_DATA[4]}M"
compare_checksum "$DOWNLOADS_DIR/$IMG_FILENAME" "${SELECTION_DATA[5]}"
# NOTE: Is there a cleaner way to do this? # NOTE: Is there a cleaner way to do this?
DEVICES=$(list_removable_devices) DEVICES=$(list_removable_devices)

Loading…
Cancel
Save