install_mirrors() { local codename codename=$(ubuntu_codename) local candidates candidates=$(curl -fsSL --max-time 5 https://mirrors.ubuntu.com/mirrors.txt) || { err "could not fetch the official Ubuntu mirror list" return 1 } log "benchmarking mirrors for speed + freshness (this takes a few seconds)" local best_url="" best_time="" url resp t last_modified age_hours checked=0 while IFS= read -r url; do if [[ -z "$url" || "$url" == \#* ]]; then continue; fi if [[ $checked -ge 12 ]]; then break; fi checked=$((checked + 1)) resp=$(curl -o /dev/null -sD - --max-time 3 -w '\n%{time_total}' "${url}dists/${codename}/Release" 2>/dev/null) || continue if [[ -z "$resp" ]]; then continue; fi t=$(tail -n1 <<< "$resp") if [[ -z "$t" ]]; then continue; fi last_modified=$(grep -i '^Last-Modified:' <<< "$resp" | head -n1 | cut -d' ' -f2- | tr -d '\r') if [[ -n "$last_modified" ]]; then age_hours=$(( ($(date +%s) - $(date -d "$last_modified" +%s 2>/dev/null || echo 0)) / 3600 )) if [[ $age_hours -gt 72 ]]; then continue; fi fi if [[ -z "$best_time" ]] || awk -v a="$t" -v b="$best_time" 'BEGIN{exit !(a