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
|
#!/bin/bash
|
||||||
# requires: curl, sha256sum, awk
|
# requires: curl, sha256sum, awk, jq
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
BASE_PATH="${TUNASYNC_WORKING_DIR}"
|
BASE_PATH="${TUNASYNC_WORKING_DIR}"
|
||||||
@ -7,6 +7,7 @@ BASE_PATH="${TUNASYNC_WORKING_DIR}"
|
|||||||
# 参数为版本,比如8,11等
|
# 参数为版本,比如8,11等
|
||||||
function downloadRelease() {
|
function downloadRelease() {
|
||||||
remote_filelist="$BASE_PATH/$1/filelist"
|
remote_filelist="$BASE_PATH/$1/filelist"
|
||||||
|
mkdir -p "$BASE_PATH/$1"
|
||||||
echo -n "" >$remote_filelist
|
echo -n "" >$remote_filelist
|
||||||
curl -s "https://api.adoptopenjdk.net/v2/latestAssets/releases/openjdk$1" | \
|
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' | \
|
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"
|
echo "Skiping $binary_name"
|
||||||
downloaded=true
|
downloaded=true
|
||||||
fi
|
fi
|
||||||
while [[ $downloaded != true ]]; do
|
local retry=0
|
||||||
|
while [[ $retry -lt 3 && $downloaded != true ]]; do
|
||||||
echo "Downloading ${dest_filename}"
|
echo "Downloading ${dest_filename}"
|
||||||
link="$binary_link"
|
link="$binary_link"
|
||||||
download_and_check && {
|
download_and_check && {
|
||||||
downloaded=true
|
downloaded=true
|
||||||
}
|
}
|
||||||
|
((retry+=1))
|
||||||
done
|
done
|
||||||
if [[ ! -z "$installer_name" ]]; then
|
if [[ ! -z "$installer_name" ]]; then
|
||||||
dest_filename="$BASE_PATH/$version/$binary_type/$architecture/$os/$installer_name"
|
dest_filename="$BASE_PATH/$version/$binary_type/$architecture/$os/$installer_name"
|
||||||
@ -36,13 +39,15 @@ function downloadRelease() {
|
|||||||
echo "Skiping $installer_name"
|
echo "Skiping $installer_name"
|
||||||
downloaded=true
|
downloaded=true
|
||||||
fi
|
fi
|
||||||
while [[ $downloaded != true ]]; do
|
retry=0
|
||||||
|
while [[ $retry -lt 3 && $downloaded != true ]]; do
|
||||||
echo "Downloading ${dest_filename}"
|
echo "Downloading ${dest_filename}"
|
||||||
link="$installer_link"
|
link="$installer_link"
|
||||||
checksum_link="$installer_checksum_link"
|
checksum_link="$installer_checksum_link"
|
||||||
download_and_check && {
|
download_and_check && {
|
||||||
downloaded=true
|
downloaded=true
|
||||||
}
|
}
|
||||||
|
((retry+=1))
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -51,12 +56,13 @@ function downloadRelease() {
|
|||||||
function clean_old_releases() {
|
function clean_old_releases() {
|
||||||
declare version=$1
|
declare version=$1
|
||||||
declare remote_filelist="$BASE_PATH/$version/filelist"
|
declare remote_filelist="$BASE_PATH/$version/filelist"
|
||||||
declare local_filelist="/tmp/filelist.local"
|
declare local_filelist="/tmp/filelist.local"
|
||||||
find "$BASE_PATH/$version" -type f > ${local_filelist}
|
[[ ! -f "$remote_filelist" ]] && return 0
|
||||||
comm <(sort $remote_filelist) <(sort $local_filelist) -13 | while read file; do
|
find "$BASE_PATH/$version" -type f > ${local_filelist}
|
||||||
echo "deleting ${file}"
|
comm <(sort $remote_filelist) <(sort $local_filelist) -13 | while read file; do
|
||||||
rm "${file}"
|
echo "deleting ${file}"
|
||||||
done
|
# rm "${file}"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function download_and_check() {
|
function download_and_check() {
|
||||||
@ -67,7 +73,11 @@ function download_and_check() {
|
|||||||
"$link"
|
"$link"
|
||||||
curl -s -S --fail -L ${CURL_OPTIONS:-} \
|
curl -s -S --fail -L ${CURL_OPTIONS:-} \
|
||||||
-o "${dest_filename}.sha256.txt.tmp" \
|
-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 && {
|
sha256sum_check && {
|
||||||
mv "${dest_filename}.sha256.txt.tmp" "${dest_filename}.sha256.txt"
|
mv "${dest_filename}.sha256.txt.tmp" "${dest_filename}.sha256.txt"
|
||||||
mv "${dest_filename}.tmp" "${dest_filename}"
|
mv "${dest_filename}.tmp" "${dest_filename}"
|
||||||
@ -78,7 +88,7 @@ function download_and_check() {
|
|||||||
function sha256sum_check() {
|
function sha256sum_check() {
|
||||||
expected=$(cat "${dest_filename}.sha256.txt.tmp" | awk '{print $1}')
|
expected=$(cat "${dest_filename}.sha256.txt.tmp" | awk '{print $1}')
|
||||||
actual=$(sha256sum "${dest_filename}.tmp" | 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
|
||||||
return 1
|
return 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user