mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-04-20 12:42:50 +00:00
check sha2 only after downloaded
This commit is contained in:
parent
67e31a907b
commit
2b1dd2bd60
@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# requires: wget, timeout, sha256sum, awk
|
# requires: curl, sha256sum, awk
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
BASE_PATH="${TUNASYNC_WORKING_DIR}"
|
BASE_PATH="${TUNASYNC_WORKING_DIR}"
|
||||||
@ -13,30 +13,31 @@ function downloadRelease() {
|
|||||||
dest_filename="$BASE_PATH/$version/$binary_type/$architecture/$os/$binary_name"
|
dest_filename="$BASE_PATH/$version/$binary_type/$architecture/$os/$binary_name"
|
||||||
declare downloaded=false
|
declare downloaded=false
|
||||||
if [[ -f $dest_filename ]]; then
|
if [[ -f $dest_filename ]]; then
|
||||||
sha256sum_check && {
|
echo "Skiping $binary_name"
|
||||||
downloaded=true
|
downloaded=true
|
||||||
echo "Skiping $binary_name"
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
while [[ $downloaded != true ]]; do
|
while [[ $downloaded != true ]]; do
|
||||||
echo "Downloading ${dest_filename}"
|
echo "Downloading ${dest_filename}"
|
||||||
rm ${dest_filename} ${dest_filename}.sha256.txt 2>/dev/null || true
|
rm "${dest_filename}" "${dest_filename}.sha256.txt" 2>/dev/null || true
|
||||||
wget -t 2 -T 30 ${WGET_OPTIONS:-} \
|
rm "${dest_filename}.tmp" "${dest_filename}.sha256.txt.tmp" 2>/dev/null || true
|
||||||
-O "${dest_filename}" \
|
curl -s -S --fail -L ${CURL_OPTIONS:-} \
|
||||||
|
-o "${dest_filename}.tmp" \
|
||||||
"$binary_link"
|
"$binary_link"
|
||||||
wget -t 2 -T 30 ${WGET_OPTIONS:-} \
|
curl -s -S --fail -L ${CURL_OPTIONS:-} \
|
||||||
-O "${dest_filename}.sha256.txt" \
|
-o "${dest_filename}.sha256.txt.tmp" \
|
||||||
"$checksum_link"
|
"$checksum_link"
|
||||||
sha256sum_check && {
|
sha256sum_check && {
|
||||||
downloaded=true
|
mv "${dest_filename}.sha256.txt.tmp" "${dest_filename}.sha256.txt"
|
||||||
|
mv "${dest_filename}.tmp" "${dest_filename}"
|
||||||
|
downloaded=true
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function sha256sum_check() {
|
function sha256sum_check() {
|
||||||
expected=$(cat "${dest_filename}.sha256.txt" | awk '{print $1}')
|
expected=$(cat "${dest_filename}.sha256.txt.tmp" | awk '{print $1}')
|
||||||
actual=$(sha256sum "${dest_filename}" | awk '{print $1}')
|
actual=$(sha256sum "${dest_filename}.tmp" | awk '{print $1}')
|
||||||
if [ "$expected" = "$actual" ]; then
|
if [ "$expected" = "$actual" ]; then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user