Last active
March 31, 2022 19:13
-
-
Save TyIsI/aa94acf80e41263ea728456435d09b5b to your computer and use it in GitHub Desktop.
A script to generate an APT mirrors.list file from the official ubuntu mirrors list.
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
#!/bin/bash | |
NETSELECT_VERSION="0.3.ds1-29" | |
echo -n "Checking netselect installation status..." >/dev/stderr | |
INSTALLED=$(dpkg --list | egrep -iw netselect | egrep '^ii') | |
if [ "${INSTALLED}" != "" ]; then | |
echo "INSTALLED!" >/dev/stderr | |
else | |
echo "MISSING" >/dev/stderr | |
DOWNLOAD_URL="https://ftp.debian.org/debian/pool/main/n/netselect/netselect_${NETSELECT_VERSION}_amd64.deb" | |
TMPFILE="/tmp/${NETSELECT_VERSION}" | |
echo -n "Downloading netselect..." >/dev/stderr | |
wget -qO ${TMPFILE} ${DOWNLOAD_URL} | |
RES=$? | |
if [ ! -f ${TMPFILE} ]; then | |
echo "ERROR!" >/dev/stderr | |
echo "Got [${RES}] while downloading netselect. Bailing." >/dev/stderr | |
exit 1 | |
else | |
echo "DONE" >/dev/stderr | |
fi | |
echo -n "Installing netselect..." >/dev/stderr | |
sudo dpkg -i ${TMPFILE} >/dev/null | |
RES=$? | |
if [ ! -f ${TMPFILE} ]; then | |
echo "ERROR!" >/dev/stderr | |
echo "Got [${RES}] while installing netselect. Bailing." >/dev/stderr | |
exit 2 | |
else | |
echo "DONE" >/dev/stderr | |
fi | |
fi | |
TEMPLATE=$(cat /etc/apt/sources.list | egrep -v '^(#|$)|security' | egrep '^deb\ .*\ (main|restricted|universe|multiverse)' | perl -pe 's|deb\ http.*/\ (.*)|deb REPO $1|g') | |
EXCLUDE_HOSTS=$(cat /etc/apt/sources.list | egrep ^deb | awk -F'/' '{ print $3 }' | sort -u | xargs | sed 's/ /|/g') | |
echo "Finding mirrors..." >/dev/stderr | |
MIRRORS_DATA=$(wget -qO - mirrors.ubuntu.com/mirrors.txt | egrep -v ${EXCLUDE_HOSTS} | egrep https | xargs) | |
sudo netselect -s 5 -t 40 ${MIRRORS_DATA} | awk '{print $2 }' | head -5 | while read MIRROR_URL; do | |
echo "${TEMPLATE}" | sed "s|REPO|${MIRROR_URL}|g" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment