Created
December 10, 2022 06:03
-
-
Save intrnl/94eaf8d5c2b68bd9df631634916a3aae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env -S bash | |
## credits to https://paste.sh/1QS8Tgf6#aHTfRy1dOG4rcA5x_6kauwq3 | |
#pkg=current/xbps-0.59.1_6.x86_64.xbps | |
pkg=current/dolphin-22.08.2_1.x86_64.xbps | |
otime=current/otime | |
file="${XDG_CACHE_HOME:-$HOME/.cache}/${0##*/}-results" | |
mirrormsg() { printf '%s\n' "getting mirrors from void-docs..." ; } | |
get() { | |
rm "$file" | |
while read -r syntax mirror _ loc; do | |
case $syntax in | |
\|) | |
case $mirror in | |
Repository) ;; | |
*) | |
mirror="${mirror#<}" | |
mirror="${mirror%>}" | |
loc="${loc% |}" | |
loc="${loc%%,*}" | |
[ -n "${REGION}" ] && { | |
[ "${REGION}" = get ] && printf '%s\n' "$loc" && continue | |
[ ! "${loc%%:*}" = "${REGION}" ] && continue | |
} | |
printf '%s\n' "$mirror" | |
dlspeed="$(curl --connect-timeout 10 --max-time 30 -# -w "%{speed_download}" "$mirror/$pkg" -o/dev/null)" | |
connect=$(printf "%.2fs" "$(curl --connect-timeout 2 -sw "%{time_appconnect}" "$mirror" -o/dev/null)") | |
lastupdated=$(date -d @$(curl --connect-timeout 2 -s "$mirror/$otime") -Iseconds) | |
echo "${mirror},${loc},${dlspeed},${connect},${lastupdated}" >> "$file" | |
;; | |
esac | |
;; | |
esac | |
done <<< "$(curl -# https://raw.githubusercontent.com/void-linux/void-docs/master/src/xbps/repositories/mirrors/index.md)" | |
#echo "finished writing results of mirrors to $file" | |
} | |
format() { | |
sort -t, -nrk3 < "$file" | numfmt -d , --field 3 --to=iec-i --suffix=B/s | sed '1s/^/mirror,location,dlspeed,connect,lastupdated\n/' | column -s, -t | |
} | |
case "$1" in | |
-g) mirrormsg && get ;; | |
-f) format ;; | |
-r) REGION="$2"; mirrormsg && get ;; | |
-p) REGION="get"; mirrormsg && get | sed '1s/^/region: location\n/' | column -s: -t ;; | |
*) cat <<EOF | |
usage: ${0##*/} [-g] [-f] | |
-g get results and write to file | |
-f format results file | |
-r get results from specific region if available | |
-p print available regions and locations | |
file: $file | |
EOF | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment