Skip to main content
Welcome guest. | Register | Login | Post

Howto Select Fastest Mirror in Debian

If you want to select Fastest Mirror in Debian follow this tutorial and this is very helpful if you want to download and install your debian packages,Updates .netselect-apt automatically creates a sources.list file for using with apt for the specified distribution by downloading the list of Debian mirrors using wget and choosing the fastest servers (both US and non-US) using netselect. The output file is written to OUTFILE.

Full Story

Comments

Save this in a file somewhere in $PATH (I call it getmirror) and make it executable (chmod +x getmirror). Then run "getmirror [ OF MIRRORS]".

#!/bin/bash
#getmirror — Print on stdout the fastest mirror of the ones given. Mirrors can be URLs, IP addresses, or FQDNs.
#
#Copyright © "a thing" <athing {at} ippimail.com> 18 May 2008
#
#Free Script License:
#
#Permission to use, copy, modify, and distribute this software provided that the above copyright notice is not removed and the used, copied, modified, or distributed software is under the terms of this license, or (at your option), the GNU General Public License as published by the Free Software Foundation (GGPL); either version 3 of the License, or (at your option) any later version.
#
#It is recommended to use the GGPL only when the software is longer than the GGPL or included in something under the GGPL, for the GGPL requires that the license is included with the software, not just linked to.
#
#THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

i=1 # No need to do it for 0.
for mirror; do
	mirrors[i]=${mirror#*/} #Strip protocol, except for last /
	if [ "${mirrors[i]:0:1}" == '/' ]; then #Strip / from above
		mirrors[i]=${mirrors[i]:1}
	fi
	mirrors[i]=${mirrors[i]%%/*} #Strip anything after FQDN
	: $((i++));
done

i=1
for mirror in ${mirrors
  • }; do if host $mirror>/dev/null; then averages[i]="$(printf "%.0f" $(ping -c 2 $mirror|tail -n1|cut -d/ -f6))" else averages[i]="error" fi : $((i++)); done IFS=" " #So sort will count each element of $averages as a different value for number in $(echo "${averages
  • }"|sort -n); do if [ $number != "error" ]; then bestaverage=$number break fi; done for ((i=1; "${averages[i]}" != "$bestaverage"; i++));do :;done #Get $i to equal the element of $averages that's the fastest. echo $(eval "echo $"'{'"$i"'}') #$$i doesn't work because $$ expands to the process ID of the shell.
  • [/]

    Comment viewing options

    Select your preferred way to display the comments and click "Save settings" to activate your changes.