Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic mirror selection #79

Open
A-Shahbazi opened this issue Apr 18, 2015 · 10 comments
Open

Automatic mirror selection #79

A-Shahbazi opened this issue Apr 18, 2015 · 10 comments

Comments

@A-Shahbazi
Copy link

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.

@peperunas
Copy link

+1

@stfl
Copy link

stfl commented Nov 11, 2016

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
Copy link

stfl commented Nov 14, 2016

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

@joshcangit
Copy link

joshcangit commented Aug 9, 2020

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.

@bonelifer
Copy link

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?

@joshcangit
Copy link

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.

@bonelifer
Copy link

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

So this part also goes into .profile?

@joshcangit
Copy link

joshcangit commented Oct 8, 2020

So this part also goes into .profile?

Actually, both parts.

@bonelifer
Copy link

So this part also goes into .profile?

Actually, both parts.

Then we export MIRRORS(?):
export MIRRORS

@joshcangit
Copy link

Then we export MIRRORS(?):
export MIRRORS

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

Repository owner deleted a comment Oct 29, 2022
Repository owner deleted a comment Nov 7, 2022
Repository owner deleted a comment Nov 16, 2022
Repository owner deleted a comment Dec 8, 2022
Repository owner locked as spam and limited conversation to collaborators Dec 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants