Skip to content

Commit 29a5ef3

Browse files
committed
fix(find): prevent Ubuntu ARM switching to non-ubuntu-ports mirrors
1 parent f3f6ac8 commit 29a5ef3

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

fast-apt-mirror.sh

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,10 @@ function find_fast_mirror() {
305305
mirrors=$(
306306
echo "$mirrors" | awk '{
307307
url=$0
308-
if (url ~ /\/ubuntu(-ports)?\/?$/) {
309-
sub(/\/ubuntu\/?$/, "/ubuntu-ports/", url)
310-
}
311-
print url
312-
}'
308+
if (url ~ /\/ubuntu-ports(\/|$)/) { print url; next }
309+
if (url ~ /\/ubuntu\//) { sub(/\/ubuntu\//, "/ubuntu-ports/", url); print url; next }
310+
if (url ~ /\/ubuntu\/?$/) { sub(/\/ubuntu\/?$/, "/ubuntu-ports/", url); print url; next }
311+
}' | awk 'NF'
313312
)
314313
mirrors+=$'\n'"$reference_mirror"
315314
# Some mirrors may not expose per-arch Contents files for all pockets, but InRelease should exist.
@@ -473,9 +472,9 @@ function find_fast_mirror() {
473472
local speedtest_mirrors=''
474473
if [[ ${#preferred_mirrors[@]} -gt 0 ]]; then
475474
for preferred_mirror in "${preferred_mirrors[@]}"; do
476-
if echo "$healthy_mirrors" | awk -v p="$preferred_mirror" 'BEGIN{sub(/\/+$/, "", p)} {u=$0; sub(/\/+$/, "", u); if (u==p) {found=1; exit}} END{exit !found}'; then
477-
speedtest_mirrors+=$preferred_mirror$'\n'
478-
fi
475+
local matched_preferred_mirror
476+
matched_preferred_mirror=$(echo "$healthy_mirrors" | awk -v p="$preferred_mirror" 'BEGIN{sub(/\/+$/, "", p)} {u=$0; key=u; sub(/\/+$/, "", key); if (key==p) {print u; exit}}')
477+
if [[ -n $matched_preferred_mirror ]]; then speedtest_mirrors+=$matched_preferred_mirror$'\n'; fi
479478
done
480479
fi
481480
speedtest_mirrors=$(echo "$speedtest_mirrors$healthy_mirrors" | awk 'NF' | unique | max_lines "$max_speedtests")
@@ -489,7 +488,7 @@ function find_fast_mirror() {
489488
echo "$speedtest_mirrors" \
490489
| awk 'NF' \
491490
| __xargs -P $((download_parallel)) -I{} bash -c \
492-
"printf '%s\t%s\n' \"\$(curl -r 0-$((sample_size_kb*1024)) --max-time $((sample_time_secs)) -sS -w '%{speed_download}' -o /dev/null \"\${1}ls-lR.gz\" 2>/dev/null || echo 0)\" \"\$1\"; >&2 echo -n '.'" _ {} \
491+
"printf '%s\t%s\n' \"\$(curl -fL -r 0-$((sample_size_kb*1024)) --max-time $((sample_time_secs)) -sS -w '%{speed_download}' -o /dev/null \"\${1}ls-lR.gz\" 2>/dev/null || echo 0)\" \"\$1\"; >&2 echo -n '.'" _ {} \
493492
| awk -F'\t' '$1 ~ /^[0-9.]+$/ && $2 ~ /^https?:\/\// { print }' \
494493
| sort -rg
495494
) || return $RC_MISC_ERROR

tests/fast-apt-mirror.bats

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ function get_dist_name() {
9090
@test "find: Find mirror if executed with arguments" {
9191
assert_exitcode $RC_OK find --sample-size 10 --healthchecks 8 --ignore-sync-state --speedtests 2 --country DE
9292
assert_regex "$output" 'Randomly selecting 8 mirrors...done'
93-
assert_regex "$output" 'Speed testing 2 of the available'
93+
arch=$(dpkg --print-architecture 2>/dev/null || echo amd64)
94+
if [[ $arch == arm64 || $arch == armhf ]]; then
95+
# On Ubuntu ARM, depending on country, there currently may be fewer than 2 reachable ubuntu-ports mirrors.
96+
assert_regex "$output" 'Speed testing [12] of the available'
97+
else
98+
assert_regex "$output" 'Speed testing 2 of the available'
99+
fi
94100
assert_regex "$output" '(sample download size: 10KB)'
95101
assert_regex "$output" '=> (https?|ftp)://.* determined as fastest mirror'
96102
refute_regex "$output" 'ERROR:'
@@ -99,7 +105,13 @@ function get_dist_name() {
99105
@test "find: Find mirror with --ignore-sync-state only" {
100106
assert_exitcode $RC_OK find --ignore-sync-state --speedtests 2 --healthchecks 8 --country DE
101107
assert_regex "$output" 'Randomly selecting 8 mirrors...done'
102-
assert_regex "$output" 'Speed testing 2 of the available'
108+
arch=$(dpkg --print-architecture 2>/dev/null || echo amd64)
109+
if [[ $arch == arm64 || $arch == armhf ]]; then
110+
# On Ubuntu ARM, depending on country, there currently may be fewer than 2 reachable ubuntu-ports mirrors.
111+
assert_regex "$output" 'Speed testing [12] of the available'
112+
else
113+
assert_regex "$output" 'Speed testing 2 of the available'
114+
fi
103115
assert_regex "$output" '=> (https?|ftp)://.* determined as fastest mirror'
104116
refute_regex "$output" 'Fastest mirror detection returned invalid URL'
105117
}
@@ -150,7 +162,9 @@ function get_dist_name() {
150162
arch=$(dpkg --print-architecture 2>/dev/null || echo amd64)
151163
if [[ $arch == arm64 || $arch == armhf ]]; then
152164
mirror_url1=http://ports.ubuntu.com/ubuntu-ports
153-
mirror_url2=http://ftp.tu-chemnitz.de/pub/linux/ubuntu-ports
165+
# Avoid flaky third-party mirrors on ARM (mirror sync in progress can break apt-get update).
166+
# Use ports.ubuntu.com with a trailing-slash variant to still test set changes.
167+
mirror_url2=http://ports.ubuntu.com/ubuntu-ports/
154168
else
155169
mirror_url1=http://archive.ubuntu.com/ubuntu
156170
mirror_url2=https://ftp.uni-stuttgart.de/ubuntu

0 commit comments

Comments
 (0)