Skip to content

Commit 3ea7192

Browse files
committed
handle non-existant sha256 files
1 parent fc99292 commit 3ea7192

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

adoptopenjdk.sh

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/bin/bash
2-
# requires: curl, sha256sum, awk
2+
# requires: curl, sha256sum, awk, jq
33
set -e
44

55
BASE_PATH="${TUNASYNC_WORKING_DIR}"
66

77
# 参数为版本,比如8,11等
88
function downloadRelease() {
99
remote_filelist="$BASE_PATH/$1/filelist"
10+
mkdir -p "$BASE_PATH/$1"
1011
echo -n "" >$remote_filelist
1112
curl -s "https://api.adoptopenjdk.net/v2/latestAssets/releases/openjdk$1" | \
1213
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() {
2021
echo "Skiping $binary_name"
2122
downloaded=true
2223
fi
23-
while [[ $downloaded != true ]]; do
24+
local retry=0
25+
while [[ $retry -lt 3 && $downloaded != true ]]; do
2426
echo "Downloading ${dest_filename}"
2527
link="$binary_link"
2628
download_and_check && {
27-
downloaded=true
29+
downloaded=true
2830
}
31+
((retry+=1))
2932
done
3033
if [[ ! -z "$installer_name" ]]; then
3134
dest_filename="$BASE_PATH/$version/$binary_type/$architecture/$os/$installer_name"
@@ -36,13 +39,15 @@ function downloadRelease() {
3639
echo "Skiping $installer_name"
3740
downloaded=true
3841
fi
39-
while [[ $downloaded != true ]]; do
42+
retry=0
43+
while [[ $retry -lt 3 && $downloaded != true ]]; do
4044
echo "Downloading ${dest_filename}"
4145
link="$installer_link"
4246
checksum_link="$installer_checksum_link"
4347
download_and_check && {
4448
downloaded=true
4549
}
50+
((retry+=1))
4651
done
4752
fi
4853
done
@@ -51,12 +56,13 @@ function downloadRelease() {
5156
function clean_old_releases() {
5257
declare version=$1
5358
declare remote_filelist="$BASE_PATH/$version/filelist"
54-
declare local_filelist="/tmp/filelist.local"
55-
find "$BASE_PATH/$version" -type f > ${local_filelist}
56-
comm <(sort $remote_filelist) <(sort $local_filelist) -13 | while read file; do
57-
echo "deleting ${file}"
58-
rm "${file}"
59-
done
59+
declare local_filelist="/tmp/filelist.local"
60+
[[ ! -f "$remote_filelist" ]] && return 0
61+
find "$BASE_PATH/$version" -type f > ${local_filelist}
62+
comm <(sort $remote_filelist) <(sort $local_filelist) -13 | while read file; do
63+
echo "deleting ${file}"
64+
# rm "${file}"
65+
done
6066
}
6167

6268
function download_and_check() {
@@ -67,7 +73,11 @@ function download_and_check() {
6773
"$link"
6874
curl -s -S --fail -L ${CURL_OPTIONS:-} \
6975
-o "${dest_filename}.sha256.txt.tmp" \
70-
"$checksum_link"
76+
"$checksum_link" || {
77+
echo "Warning: ${dest_filename}.sha256.txt not exist, skipping SHA256 check"
78+
mv "${dest_filename}.tmp" "${dest_filename}"
79+
return 0
80+
}
7181
sha256sum_check && {
7282
mv "${dest_filename}.sha256.txt.tmp" "${dest_filename}.sha256.txt"
7383
mv "${dest_filename}.tmp" "${dest_filename}"
@@ -78,7 +88,7 @@ function download_and_check() {
7888
function sha256sum_check() {
7989
expected=$(cat "${dest_filename}.sha256.txt.tmp" | awk '{print $1}')
8090
actual=$(sha256sum "${dest_filename}.tmp" | awk '{print $1}')
81-
if [ "$expected" = "$actual" ]; then
91+
if [[ "$expected" = "$actual" ]]; then
8292
return 0
8393
else
8494
return 1

0 commit comments

Comments
 (0)