Add Arch mirror manager: benchmark, apply, pin, restore, status
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp
This commit is contained in:
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
# omarchy:summary=Apply a mirror profile or pin one mirror for pacman
|
||||
# omarchy:args=<china|official|mirror-id>
|
||||
# omarchy:examples=omarchycn mirror apply china | omarchycn mirror apply official | omarchycn mirror apply tuna
|
||||
# omarchy:requires-sudo=true
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$OMARCHY_PATH/cn/lib/mirror.sh"
|
||||
|
||||
target="${1:?usage: omarchycn mirror apply <china|official|mirror-id>}"
|
||||
|
||||
case "$target" in
|
||||
china)
|
||||
echo "Benchmarking China mirrors..."
|
||||
mapfile -t ranked < <(cn_mirror_rank $(cn_mirror_ids_by_region cn))
|
||||
if (( ${#ranked[@]} == 0 )); then
|
||||
echo "No healthy China mirror reachable; keeping current mirrorlist" >&2
|
||||
exit 1
|
||||
fi
|
||||
# Primary + up to two backups
|
||||
cn_mirror_write_list china "${ranked[@]:0:3}"
|
||||
;;
|
||||
official)
|
||||
cn_mirror_write_list official geo worldwide
|
||||
;;
|
||||
*)
|
||||
url=$(cn_mirror_url "$target")
|
||||
if [[ -z $url ]]; then
|
||||
echo "Unknown mirror id: $target (see: omarchycn mirror benchmark)" >&2
|
||||
exit 1
|
||||
fi
|
||||
cn_mirror_write_list "pin:$target" "$target"
|
||||
;;
|
||||
esac
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
# omarchy:summary=Benchmark Arch mirrors for speed, latency, and sync freshness
|
||||
# omarchy:examples=omarchycn mirror benchmark
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$OMARCHY_PATH/cn/lib/mirror.sh"
|
||||
|
||||
printf '%-11s %-22s %12s %8s %10s\n' "ID" "NAME" "SPEED" "TTFB" "SYNC"
|
||||
|
||||
for id in $(cn_mirror_ids); do
|
||||
url=$(cn_mirror_url "$id")
|
||||
read -r speed ttfb age < <(cn_mirror_probe "$url")
|
||||
|
||||
if (( speed > 0 )); then
|
||||
speed_h="$((speed / 1024)) KB/s"
|
||||
else
|
||||
speed_h="FAIL"
|
||||
fi
|
||||
case "$age" in
|
||||
stale) sync_h="STALE" ;;
|
||||
unknown) sync_h="?" ;;
|
||||
*) sync_h="$((age / 60))m ago" ;;
|
||||
esac
|
||||
|
||||
printf '%-11s %-22s %12s %7ss %10s\n' "$id" "$(cn_mirror_name "$id")" "$speed_h" "${ttfb:0:5}" "$sync_h"
|
||||
done
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
# omarchy:summary=Pin pacman to a single mirror
|
||||
# omarchy:args=<mirror-id>
|
||||
# omarchy:examples=omarchycn mirror pin tuna
|
||||
# omarchy:requires-sudo=true
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
exec omarchy-cn-mirror-apply "${1:?usage: omarchycn mirror pin <mirror-id>}"
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
# omarchy:summary=Restore the most recent mirrorlist backup
|
||||
# omarchy:examples=omarchycn mirror restore
|
||||
# omarchy:requires-sudo=true
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$OMARCHY_PATH/cn/lib/mirror.sh"
|
||||
|
||||
backups=("$CN_MIRRORLIST".omarchycn-bak-*)
|
||||
if [[ ! -e ${backups[0]} ]]; then
|
||||
echo "No OmarchyCN mirrorlist backups found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
latest="${backups[-1]}"
|
||||
sudo cp "$latest" "$CN_MIRRORLIST"
|
||||
rm -f "$CN_PROFILE_FILE"
|
||||
echo "Restored $CN_MIRRORLIST from ${latest##*/}"
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
# omarchy:summary=Show current pacman mirror profile and servers
|
||||
# omarchy:examples=omarchycn mirror status
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$OMARCHY_PATH/cn/lib/mirror.sh"
|
||||
|
||||
if [[ -f $CN_PROFILE_FILE ]]; then
|
||||
echo "Profile: $(<"$CN_PROFILE_FILE")"
|
||||
else
|
||||
echo "Profile: not managed by OmarchyCN"
|
||||
fi
|
||||
|
||||
echo "Mirrorlist: $CN_MIRRORLIST"
|
||||
echo "Servers:"
|
||||
grep -E '^Server' "$CN_MIRRORLIST" | sed 's/^/ /'
|
||||
|
||||
backups=("$CN_MIRRORLIST".omarchycn-bak-*)
|
||||
if [[ -e ${backups[0]} ]]; then
|
||||
echo "Backups: ${#backups[@]} (latest: ${backups[-1]##*/})"
|
||||
fi
|
||||
Reference in New Issue
Block a user