mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-19 04:49:13 +08:00
core: test_url curl 添加 -f
This commit is contained in:
parent
9d42a6dd73
commit
87055558b8
11
reinstall.sh
11
reinstall.sh
@ -46,7 +46,8 @@ error_and_exit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
curl() {
|
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() {
|
is_in_china() {
|
||||||
@ -131,8 +132,8 @@ test_url() {
|
|||||||
echo $url
|
echo $url
|
||||||
|
|
||||||
tmp_file=/tmp/reinstall-img-test
|
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"
|
error "$url not accessible"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -148,8 +149,8 @@ test_url() {
|
|||||||
real_type=$(file -b $tmp_file | sed 's/^# //' | cut -d' ' -f1 | tr '[:upper:]' '[:lower:]')
|
real_type=$(file -b $tmp_file | sed 's/^# //' | cut -d' ' -f1 | tr '[:upper:]' '[:lower:]')
|
||||||
[ -n "$var_to_eval" ] && eval $var_to_eval=$real_type
|
[ -n "$var_to_eval" ] && eval $var_to_eval=$real_type
|
||||||
|
|
||||||
if ! echo $expect_type | grep -wo "$real_type"; then
|
if ! grep -wo "$real_type" <<<"$expect_type"; then
|
||||||
error "$url expect: $expect_type. real: $real_type."
|
error "$url expected: $expect_type. actual: $real_type."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user