core: 修复下载失败时返回值为 0

This commit is contained in:
bin456789 2024-07-23 23:00:18 +08:00
parent e92dcb86a9
commit 048ee61ecc
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
2 changed files with 25 additions and 27 deletions

View File

@ -2587,7 +2587,7 @@ mod_initrd_alpine() {
# hack 1 v3.19 和之前的 virt 内核需添加 ipv6 模块
if virt_dir=$(ls -d $initrd_dir/lib/modules/*-virt 2>/dev/null); then
ipv6_dir=$virt_dir/kernel/net/ipv6
if ! [ -f $ipv6_dir/ipv6.ko ] || ! grep -q ipv6 $initrd_dir/lib/modules/*/modules.builtin; then
if ! [ -f $ipv6_dir/ipv6.ko ] && ! grep -q ipv6 $initrd_dir/lib/modules/*/modules.builtin; then
mkdir -p $ipv6_dir
modloop_file=$tmp/modloop_file
modloop_dir=$tmp/modloop_dir

View File

@ -64,27 +64,13 @@ add_community_repo() {
# 有时网络问题下载失败,导致脚本中断
# 因此需要重试
apk() {
for i in $(seq 5); do
command apk "$@" && return
sleep 1
done
retry 5 command apk "$@"
}
# busybox 的 wget 没有重试功能
wget() {
echo "$@" | grep -o 'http[^ ]*' >&2
for i in $(seq 5); do
if command wget "$@"; then
return
else
ret=$?
# 错误,或者达到重试次数
if [ $i -eq 5 ]; then
return $ret
fi
sleep 1
fi
done
retry 5 command wget "$@"
}
is_have_cmd() {
@ -103,6 +89,23 @@ is_have_cmd_on_disk() {
return 1
}
retry() {
max_try=$1
shift
for i in $(seq $max_try); do
if "$@"; then
return
else
ret=$?
if [ $i -ge $max_try ]; then
return $ret
fi
sleep 1
fi
done
}
download() {
url=$1
path=$2
@ -153,15 +156,11 @@ download() {
# --user-agent=Wget/1.21.1 \
echo "$url"
for i in $(seq 5); do
stdbuf -oL -eL \
aria2c -x4 \
--allow-overwrite=true \
--summary-interval=0 \
--max-tries 1 \
$save $url && return
sleep 1
done
retry 5 stdbuf -oL -eL aria2c -x4 \
--allow-overwrite=true \
--summary-interval=0 \
--max-tries 1 \
$save "$url"
}
update_part() {
@ -1057,7 +1056,6 @@ EOF
if ! is_virt; then
chroot $os_dir pacman -Syu --noconfirm linux-firmware
# amd microcode 包括在 linux-firmware 里面
if [ "$(uname -m)" = x86_64 ]; then
cpu_vendor="$(get_cpu_vendor)"
case "$cpu_vendor" in