Last active
May 10, 2016 13:45
-
-
Save demosdemon/be43d883bfe74a5ca389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Find the fastest apt mirror | |
# Adapted from http://askubuntu.com/questions/39922/how-do-you-select-the-fastest-mirror-from-the-command-line/141536#141536 | |
IFS=$'\n' read -d '' -r -a HOSTS < <( | |
wget -q -O- https://launchpad.net/ubuntu/+archivemirrors | | |
grep -P -B8 'statusUP|statusSIX' | | |
grep -o -P '(f|ht)tp[^"]*"' | sed 's/"$//' | |
) | |
sudo netselect -v -s10 -t30 "${HOSTS[@]}" | tee -i mirrors.txt | |
echo | |
TOP_HOST=$( | |
head -n1 mirrors.txt | | |
tr -s ' ' ' ' | | |
cut -d' ' -f3 | |
) | |
OLD_HOST=$( | |
grep '^deb' /etc/apt/sources.list | | |
cut -d' ' -f2 | | |
sort | uniq -c | sort -d | | |
head -n1 | | |
tr -s ' ' ' ' | | |
cut -d' ' -f3 | |
) | |
echo "sudo sed -i'~' 's!${OLD_HOST/./\\.}!${TOP_HOST}!' /etc/apt/sources.list" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment