Finding the fastest mirror: Difference between revisions

From Alpine Linux
(Only try the mirror's once - Certain errors will retry inf and hang the script. sh version of echo does not support -e option corrupting the output.)
mNo edit summary
Line 1: Line 1:
After you install Alpine, you may be wondering how do I figure out the fastest mirror again?
After you install Alpine, you may be wondering how do I figure out the fastest mirror again?


'''Don't use this script, it's broken'''
{{Cat|/home/user/fastestmirror|<nowiki>
{{Cat|/home/user/fastestmirror|<nowiki>
data=""
data=""
Line 17: Line 18:


This is more advanced implementation.
This is more advanced implementation.
'''Don't use this script, it's broken'''
{{Cat|/etc/apk/fastest-mirror|<nowiki>
{{Cat|/etc/apk/fastest-mirror|<nowiki>
#!/bin/sh
#!/bin/sh

Revision as of 18:47, 10 November 2022

After you install Alpine, you may be wondering how do I figure out the fastest mirror again?

Don't use this script, it's broken

Contents of /home/user/fastestmirror

data="" for s in $(wget -qO- http://rsync.alpinelinux.org/alpine/MIRRORS.txt); do t=$(time -f "%E" wget -q $s/MIRRORS.txt -O /dev/null 2>&1) echo "$s was $t" data="$data$t $s\n" done echo "===RESULTS===" echo -e $data | sort


This is more advanced implementation.

Don't use this script, it's broken

Contents of /etc/apk/fastest-mirror

#!/bin/sh get_hostname_url() { local n=${1#*://} echo ${n%%/*} } time_cmd() { local proc=$(cut -d ' ' -f1 /proc/uptime) local start="$(echo $proc | cut -d . -f1)$(echo $proc | cut -d . -f2)" $@ >/dev/null 2>&1 || return proc=$(cut -d ' ' -f1 /proc/uptime) local end="$(echo $proc | cut -d . -f1)$(echo $proc | cut -d . -f2)" echo $(( $end - $start )) } DATA="" MIRRORS=$(wget -qO- "http://rsync.alpinelinux.org/alpine/MIRRORS.txt") DST=/etc/apk/mirrors.txt #find best for URL in $MIRRORS; do TIME=$(time_cmd wget -T 1 -t 1 -q ${URL%/} -O /dev/null) if [ -n "$TIME" ]; then echo "$(get_hostname_url $URL) was $TIME" DATA="$DATA$TIME $URL\n" fi done echo $DATA | sort -n | tail -n +2 > $DST [ $? = 0 ] && echo file $DST created BEST=$(head -n1 $DST | cut -d ' ' -f2) echo "Best mirror is: $BEST" sed -i -r 's#^http.+/(.+/main)#'${BEST%/}'/\1#' /etc/apk/repositories sed -i -r 's#^http.+/(.+/community)#'${BEST%/}'/\1#' /etc/apk/repositories sed -i -r 's#^http.+/(.+/testing)#'${BEST%/}'/\1#' /etc/apk/repositories