You are not logged in.
I've written this basic script which can be used to select a mirror from pacman's mirrorlist file which minimizes the response time between you and the mirror. This often leads to satisfactory download speeds. You might have to change some of the variables at the beginning of the script to suit your needs.
#!/bin/bash
#
# mirrorize v0.1 - Fast mirror selector for pacman
# Copyright (C) 2009 sin
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
if [ ! "$UID" == "0" ]; then
echo "[+] you cannot perform this operation unless you are root." 1>&2
exit
fi
MIRROR_PATH="/etc/pacman.d/mirrorlist.pacorig"
BEST_MIRROR=""
BEST_TIME=300 # ms
TMP=$(mktemp)
function cleanup() {
rm -f $TMP
}
trap cleanup SIGINT SIGTERM
cp $MIRROR_PATH $MIRROR_PATH.backup
for mirror in `cat $MIRROR_PATH | sed 's/#//g' | grep ':' | sed 's/Server = //g' | sed 's/ftp:\/\///g' | sed 's/http:\/\///g' | sed 's/\/.*//g'`; do
M=$(ping $mirror -B -w 2 -n -c 4 2>/dev/null | grep rtt | awk -F '/' '{print $5}')
if [ ! -z "$M" ]; then
M=${M/.*};
if [ "$M" -lt "$BEST_TIME" ]; then
BEST_TIME=$M
BEST_MIRROR=$mirror
echo "[+] found a faster mirror [$BEST_MIRROR] => response time = $BEST_TIME ms"
fi
fi
done
if [ ! -z "$BEST_MIRROR" -a ! "$BEST_MIRROR" = "ftp.archlinux.org" -a ! -z "$BEST_TIME" ]; then
sed 's/^Server/#Server/g' $MIRROR_PATH > $TMP; cat $TMP > $MIRROR_PATH
cat $TMP > $MIRROR_PATH
line=$(egrep -in $BEST_MIRROR $MIRROR_PATH | uniq | sed 's/:.*//g' | head -1)
extension="ftp"
cat $MIRROR_PATH | head -$line | tail -1 | egrep -i "ftp:" 1>/dev/null
[ $? -eq 0 ] || extension="http"
sed -e "${line}s/^#Server = .*${BEST_MIRROR}/Server = ${extension}:\/\/${BEST_MIRROR}/g" $MIRROR_PATH > $TMP
cat $TMP > $MIRROR_PATH
fi
cleanup
pacman -Syy
Last edited by dimigon (2009-03-07 23:36:46)
Offline
nice script, but i think it will be more accurate if you made the ping line to
M=$(ping $mirror -B -w 2 -n -c 4 2>/dev/null | grep rtt | awk -F '/' '{print $5}')
Offline
Is this different from rankmirrors?
Bob
Offline
Is this different from rankmirrors?
Bob
Lol, I was just going to say: "Doesn't rank mirrors do this for you?"
Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.
Offline
Offline
Hrod beraht wrote:Is this different from rankmirrors?
Bob
Lol, I was just going to say: "Doesn't rank mirrors do this for you?"
exactly what I was thinking also! but rankmirrors needs python so i guess if you needed a stand alone script this would be perfect.
Offline
made a little update for it so it doesnt requir root acount
it also now adds last sync times to the results
#!/bin/bash
#
# mirrorize v0.1 - Fast mirror selector for pacman
# Copyright (C) 2009 sin
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
MIRRORLIST=$(mktemp)
cat /etc/pacman.d/mirrorlist > $MIRRORLIST
MIRROR_PATH="$MIRRORLIST"
BEST_MIRROR=""
BEST_TIME=300
TMP=$(mktemp)
LIST=$(mktemp)
wget -q "http://users.archlinux.de/~gerbra/mirrorcheck.html" -O /tmp/mirrorcheck.html
function cleanup() {
rm -f $TMP
rm -f $LIST
rm /tmp/mirrorcheck.html
}
trap cleanup SIGINT SIGTERM
echo "Pinging Servers..."
for mirror in `cat $MIRROR_PATH | sed 's/#//g' | grep ':' | sed 's/Server = //g' | sed 's/ftp:\/\///g' | sed 's/http:\/\///g' | sed 's/\/.*//g'`; do
M=$(ping $mirror -B -w 2 -n -c 4 2>/dev/null | grep rtt | awk -F '/' '{print $5}')
if [ ! -z "$M" ]; then
M=${M/.*};
if [ "$M" -lt "$BEST_TIME" ]; then
BEST_MIRROR=$mirror
LASTSYNC=$(cat /tmp/mirrorcheck.html | grep -A 13 "$BEST_MIRROR" | tail -n 1 | sed 's/<td>//g' | sed 's/()<\/td>//g' | cut -c 7-)
echo "$M $mirror Not synced since: $LASTSYNC" >> $LIST
fi
fi
done
cat $LIST | sort -n
cleanup
Offline
made a little update for it so it doesnt requir root acount
it also now adds last sync times to the results#!/bin/bash # # mirrorize v0.1 - Fast mirror selector for pacman # Copyright (C) 2009 sin # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. MIRRORLIST=$(mktemp) cat /etc/pacman.d/mirrorlist > $MIRRORLIST MIRROR_PATH="$MIRRORLIST" BEST_MIRROR="" BEST_TIME=300 TMP=$(mktemp) LIST=$(mktemp) wget -q "http://users.archlinux.de/~gerbra/mirrorcheck.html" -O /tmp/mirrorcheck.html function cleanup() { rm -f $TMP rm -f $LIST rm /tmp/mirrorcheck.html } trap cleanup SIGINT SIGTERM echo "Pinging Servers..." for mirror in `cat $MIRROR_PATH | sed 's/#//g' | grep ':' | sed 's/Server = //g' | sed 's/ftp:\/\///g' | sed 's/http:\/\///g' | sed 's/\/.*//g'`; do M=$(ping $mirror -B -w 2 -n -c 4 2>/dev/null | grep rtt | awk -F '/' '{print $5}') if [ ! -z "$M" ]; then M=${M/.*}; if [ "$M" -lt "$BEST_TIME" ]; then BEST_MIRROR=$mirror LASTSYNC=$(cat /tmp/mirrorcheck.html | grep -A 13 "$BEST_MIRROR" | tail -n 1 | sed 's/<td>//g' | sed 's/()<\/td>//g' | cut -c 7-) echo "$M $mirror Not synced since: $LASTSYNC" >> $LIST fi fi done cat $LIST | sort -n cleanup
Cheers! Nice one
Offline