apt-fast icon indicating copy to clipboard operation
apt-fast copied to clipboard

Automatic mirror selection

Open A-Shahbazi opened this issue 9 years ago • 10 comments

I thought it would be a good idea to implement an automatic mirror selection command (apt-fast best-mirrors-select for example) to add best mirrors according to the location of user like what we have for best server selection in ubuntu.

A-Shahbazi avatar Apr 18 '15 08:04 A-Shahbazi

+1

peperunas avatar Feb 03 '16 22:02 peperunas

you can use netselect-apt for that. it gives you a list of the 10 best mirrors... you can then copy it into the MIRRORS variable.. shouldn't be too hard to automate that in a script.. ;)

sudo netselect-apt testing -n

here for Debian testing ;)

stfl avatar Nov 11 '16 13:11 stfl

I wrote a little python script that does that for me on Debian testing: https://github.com/stfl/apt-fast-mirrors

stfl avatar Nov 14 '16 12:11 stfl

I've got a Bash function to extract URLs of up-to-date Ubuntu mirrors below.

ubuntu_mirror() {
	local url="https://launchpad.net/ubuntu/+archivemirrors"
	local xpath1="//table/tbody/tr[td/span[@class='distromirrorstatusUP']]/td/a[starts-with(@href,'"
	local xpath2="${xpath1}$1"
	local xpath="${xpath2}')]/@href"
	wget -qO- $url | xmllint --html --xpath "$xpath" - 2>&0 | sed 's/.*href="\(.*\)"/\1/g'
}
MIRRORS1="(' "​
MIRRORS2=${MIRRORS1}$(ubuntu_mirror https | awk -vRS=' ' -vOFS=', ' '$1=$1')
MIRRORS="${MIRRORS2} ')"

The function can also find http or ftp URLs.

joshcangit avatar Aug 09 '20 15:08 joshcangit

I've got a Bash function to extract URLs of up-to-date Ubuntu mirrors below.

function ubuntu-mirror {
PROTOCOL="$1"
str='s/.*href="\('
str+=$PROTOCOL
str+=':\/\/.*\)"/\1/p'
wget -qO- https://launchpad.net/ubuntu/+archivemirrors | xmllint --html --xpath '//table/tbody/tr[td/span[@class="distromirrorstatusUP"]]/td/a[not(starts-with(@href, "/"))]/@href' - 2>&0 | sed -n $str
}
* Use either `http`, `https`, `ftp` or `rsync`.
MIRRORS="( '"
MIRRORS+="ubuntu-mirror https | awk -vRS='' -vOFS=', ' '$1=$1'"
MIRRORS+="' )"

How do you use this function after adding it to .profile?

bonelifer avatar Oct 08 '20 16:10 bonelifer

How do you use this function after adding it to .profile?

Sorry, forgot to fix it.

I'm still unsure to keep it as is or make it not as a function which I've tried and seems faster.

joshcangit avatar Oct 08 '20 17:10 joshcangit

MIRRORS="( '"
MIRRORS+=$(ubuntu-mirror https | awk -vRS='' -vOFS=', ' '$1=$1')
MIRRORS+="' )"

So this part also goes into .profile?

bonelifer avatar Oct 08 '20 17:10 bonelifer

So this part also goes into .profile?

Actually, both parts.

joshcangit avatar Oct 08 '20 18:10 joshcangit

So this part also goes into .profile?

Actually, both parts.

Then we export MIRRORS(?): export MIRRORS

bonelifer avatar Oct 09 '20 00:10 bonelifer

Then we export MIRRORS(?): export MIRRORS

I now don't think that's needed. You can use it if it works for you.

joshcangit avatar Oct 09 '20 00:10 joshcangit