mirror of
https://github.com/tuna/tunasync-scripts.git
synced 2025-04-20 04:12:42 +00:00
handle non-existant sha256 files
This commit is contained in:
parent
fc9929258c
commit
3ea7192b65
@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
# requires: curl, sha256sum, awk
|
||||
# requires: curl, sha256sum, awk, jq
|
||||
set -e
|
||||
|
||||
BASE_PATH="${TUNASYNC_WORKING_DIR}"
|
||||
@ -7,6 +7,7 @@ BASE_PATH="${TUNASYNC_WORKING_DIR}"
|
||||
# 参数为版本,比如8,11等
|
||||
function downloadRelease() {
|
||||
remote_filelist="$BASE_PATH/$1/filelist"
|
||||
mkdir -p "$BASE_PATH/$1"
|
||||
echo -n "" >$remote_filelist
|
||||
curl -s "https://api.adoptopenjdk.net/v2/latestAssets/releases/openjdk$1" | \
|
||||
jq -r '.[]| [.version,.binary_type,.architecture,.os,.binary_name,.binary_link,.checksum_link,.installer_name,.installer_link,.installer_checksum_link]| @tsv' | \
|
||||
@ -20,12 +21,14 @@ function downloadRelease() {
|
||||
echo "Skiping $binary_name"
|
||||
downloaded=true
|
||||
fi
|
||||
while [[ $downloaded != true ]]; do
|
||||
local retry=0
|
||||
while [[ $retry -lt 3 && $downloaded != true ]]; do
|
||||
echo "Downloading ${dest_filename}"
|
||||
link="$binary_link"
|
||||
download_and_check && {
|
||||
downloaded=true
|
||||
}
|
||||
((retry+=1))
|
||||
done
|
||||
if [[ ! -z "$installer_name" ]]; then
|
||||
dest_filename="$BASE_PATH/$version/$binary_type/$architecture/$os/$installer_name"
|
||||
@ -36,13 +39,15 @@ function downloadRelease() {
|
||||
echo "Skiping $installer_name"
|
||||
downloaded=true
|
||||
fi
|
||||
while [[ $downloaded != true ]]; do
|
||||
retry=0
|
||||
while [[ $retry -lt 3 && $downloaded != true ]]; do
|
||||
echo "Downloading ${dest_filename}"
|
||||
link="$installer_link"
|
||||
checksum_link="$installer_checksum_link"
|
||||
download_and_check && {
|
||||
downloaded=true
|
||||
}
|
||||
((retry+=1))
|
||||
done
|
||||
fi
|
||||
done
|
||||
@ -52,10 +57,11 @@ function clean_old_releases() {
|
||||
declare version=$1
|
||||
declare remote_filelist="$BASE_PATH/$version/filelist"
|
||||
declare local_filelist="/tmp/filelist.local"
|
||||
[[ ! -f "$remote_filelist" ]] && return 0
|
||||
find "$BASE_PATH/$version" -type f > ${local_filelist}
|
||||
comm <(sort $remote_filelist) <(sort $local_filelist) -13 | while read file; do
|
||||
echo "deleting ${file}"
|
||||
rm "${file}"
|
||||
# rm "${file}"
|
||||
done
|
||||
}
|
||||
|
||||
@ -67,7 +73,11 @@ function download_and_check() {
|
||||
"$link"
|
||||
curl -s -S --fail -L ${CURL_OPTIONS:-} \
|
||||
-o "${dest_filename}.sha256.txt.tmp" \
|
||||
"$checksum_link"
|
||||
"$checksum_link" || {
|
||||
echo "Warning: ${dest_filename}.sha256.txt not exist, skipping SHA256 check"
|
||||
mv "${dest_filename}.tmp" "${dest_filename}"
|
||||
return 0
|
||||
}
|
||||
sha256sum_check && {
|
||||
mv "${dest_filename}.sha256.txt.tmp" "${dest_filename}.sha256.txt"
|
||||
mv "${dest_filename}.tmp" "${dest_filename}"
|
||||
@ -78,7 +88,7 @@ function download_and_check() {
|
||||
function sha256sum_check() {
|
||||
expected=$(cat "${dest_filename}.sha256.txt.tmp" | awk '{print $1}')
|
||||
actual=$(sha256sum "${dest_filename}.tmp" | awk '{print $1}')
|
||||
if [ "$expected" = "$actual" ]; then
|
||||
if [[ "$expected" = "$actual" ]]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user