From 87055558b8642f1b4c01932d2f6f016543d706a1 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Sun, 10 Sep 2023 22:23:02 +0800 Subject: [PATCH] =?UTF-8?q?core:=20test=5Furl=20curl=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=20-f?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reinstall.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/reinstall.sh b/reinstall.sh index 8dac069..22f9278 100644 --- a/reinstall.sh +++ b/reinstall.sh @@ -46,7 +46,8 @@ error_and_exit() { } curl() { - command curl --connect-timeout 5 --retry 3 --retry-delay 0 "$@" + # 添加 -f, --fail,不然 404 退出码也为0 + command curl --connect-timeout 5 --retry 2 --retry-delay 1 -f "$@" } is_in_china() { @@ -131,8 +132,8 @@ test_url() { echo $url tmp_file=/tmp/reinstall-img-test - http_code=$(command curl --connect-timeout 5 --retry 3 -Ls -r 0-1048575 -w "%{http_code}" -o $tmp_file $url) - if [ "$http_code" != 200 ] && [ "$http_code" != 206 ]; then + + if ! curl -r 0-1048575 -Lo $tmp_file $url; then error "$url not accessible" return 1 fi @@ -148,8 +149,8 @@ test_url() { real_type=$(file -b $tmp_file | sed 's/^# //' | cut -d' ' -f1 | tr '[:upper:]' '[:lower:]') [ -n "$var_to_eval" ] && eval $var_to_eval=$real_type - if ! echo $expect_type | grep -wo "$real_type"; then - error "$url expect: $expect_type. real: $real_type." + if ! grep -wo "$real_type" <<<"$expect_type"; then + error "$url expected: $expect_type. actual: $real_type." return 1 fi fi