debian

FetchDebian如何处理网络不稳定情况

小樊
40
2025-12-28 23:18:15
栏目: 智能运维

FetchDebian在网络不稳定时的处理策略

一 工具内置能力

二 配套的网络优化

三 常见故障的快速排查

四 建议的稳健用法脚本

#!/usr/bin/env bash
set -Eeuo pipefail

pkg="${1:-}"
mirrors=(
  "http://deb.debian.org/debian"
  "https://mirrors.ustc.edu.cn/debian"
  "https://mirrors.tuna.tsinghua.edu.cn/debian"
)
max_retries=4
timeout=30

if [[ -z "${pkg}" ]]; then
  echo "用法: $0 <package_name>"
  exit 1
fi

for ((i=0; i<max_retries; i++)); do
  m="${mirrors[i % ${#mirrors[@]}]}"
  echo "[$((i+1))/$max_retries] 使用镜像: $m"
  if fetchdebian "$pkg" --mirror "$m" --proxy "$http_proxy" -v; then
    echo "下载成功: $pkg"
    exit 0
  else
    echo "第 $((i+1)) 次失败,$((2**i)) 秒后重试..."
    sleep $((2**i))
  fi
done

echo "所有镜像均尝试失败: $pkg"
exit 1

0
看了该问题的人还看了