I want to update my sources.list
file with the fastest server from the command line in a fresh Ubuntu Server install. I know this is trivially easy with the GUI, but there doesn’t seem to be a simple way to do it from from the command line?
1 |
sudo netselect -v -s10 -t20 `wget -q -O- https://launchpad.net/ubuntu/+archivemirrors | grep -P -B8 "statusUP|statusSIX" | grep -o -P "(f|ht)tp://[^\"]*"` |
Automated Process
1 2 |
sudo apt install netselect-apt netselect-apt -n |
If you want a utility to do this you could implement such a utility as a simple bash script like the following.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#!/bin/bash if [ -z "$1" ] then echo Usage: sudo $0 http://mirrors.ubuntu.com/mirrors.txt echo OR consider one of... for mirror in `wget http://mirrors.ubuntu.com/mirrors.txt -O - 2> /dev/null` do ( host=`echo $mirror |sed s,.*//,,|sed s,/.*,,` echo -e `ping $host -c1 | grep time=|sed s,.*time=,,`:' \t\t'$mirror ) & done wait exit 1 fi OLD_SOURCE=`cat /etc/apt/sources.list | grep ^deb\ | head -n1 | cut -d\ -f2` [ -e /etc/apt/sources.list.orig ] || cp /etc/apt/sources.list /etc/apt/sources.list.orig cp /etc/apt/sources.list /etc/apt/sources.list.tmp sed "s,$OLD_SOURCE,$1," < /etc/apt/sources.list.tmp > /etc/apt/sources.list |