#!/bin/bash # # Generates to stdout a ranked Antergos mirror list that can be directly used as # file /etc/pacman.d/antergos-mirrorlist. # # For optimizing performance # - while searching the mirrors with this tool # AND # - while updating your system using the ranked mirrors # you may exclude mirror countries (option --exclude-countries) # or exclude groups of countries (--exclude-countrygroups), or individual mirrors (--exclude-mirrors). # # You can specify which protocols (https, http) are used (option --protocols). # # For more details, see below. # # Installation: # - Copy this script into a file (e.g. /usr/bin/reflector-antergos or /usr/local/bin/reflector-antergos) # and make it executable (e.g. chmod +x /usr/bin/reflector-antergos). # # NOTE1: for option --exclude-countries, in addition to country names you can # give "reserved" word 'Automated'. The Automated excludes all # automated mirrors (usually one or two). # Single mirrors (URLs) can be excluded with option --exclude-mirrors. # # NOTE2: it is possible to manually edit and re-order mirrors # in /etc/pacman.d/antergos-mirrorlist. # # Usage example: # reflector-antergos --exclude-countrygroup=Asia2,Europe > ~/antergos-mirrorlist # sudo mv -f /etc/pacman.d/antergos-mirrorlist /etc/pacman.d/antergos-mirrorlist.bak # optional: backup old file # sudo mv -f ~/antergos-mirrorlist /etc/pacman.d/antergos-mirrorlist # # TODO: # - Only http and https protocols are currently supported. # # Caveats: # - This script assumes $INPUTFILE (antergos-mirrorlist, see function GetLatestInputFile below) # is written using a certain format. # If the format changes, this script must be modified accordingly # (which may or may not be trivial). # OUTPUTFILE=/etc/pacman.d/antergos-mirrorlist INPUTFILE="" # the latest available antergos-mirrorlist, downloaded! EXCLUDEDCOUNTRYGROUPS="" EXCLUDEDCOUNTRIES="" EXCLUDEDMIRRORS="" PROTOCOLS="http" # default protocol INCLUDEDCOUNTRIES="" REPO=antergos ARCH=$(uname -m) TMPDIR="$HOME/.rankingstuff.tmp.$$" #TMPDIR="/tmp/.rankingstuff.tmp.$$" RANKEDMIRRORS="$TMPDIR/rankedmirrors" INSTALLER="$TMPDIR/installer.bash" REFLECTOR_ANTERGOS_CONF=/etc/reflector-antergos.conf # may contain e.g. REFERENCEURL if [ -f $REFLECTOR_ANTERGOS_CONF ] ; then source $REFLECTOR_ANTERGOS_CONF fi if [ "$REFERENCEURL" = "" ] ; then REFERENCEURL=http://mirrors.antergos.com/$REPO/$ARCH/main.files.tar.gz fi REFERENCEFILE="$TMPDIR/referencefile" REFERENCESTAMP=0 # timestamp FOUND_MIRRORS=0 SAVE_TO_FILE=false # false=output to standard output, true=to /etc/pacman.d/antergos-mirrorlist HIDE_ORIGINAL_MIRRORS=yes # Controls how the original mirror list is appended after ranked mirrors. # yes=hides original mirrors, no=don't hide original mirrors. VERSION_STUB="$Id: reflector-antergos,v 1.34 2018/06/20 14:38:01 manuel Exp $" VERSION=0.$(echo "$VERSION_STUB" | awk '{print $3}') VERBOSE=1 DEBUG=0 TIME_CMD=/usr/bin/time WGET_CMD=/usr/bin/wget WGET_TIMEOUT=30 # seconds to wait for the mirror to respond echo2() { echo "$@" >&2 ; } verbose2() { test $VERBOSE -ne 0 && echo2 "$@" ; } verbose2more() { test $VERBOSE -eq 2 && echo2 "$@" ; } debug2() { test $DEBUG -eq 1 && echo2 "$@" ; } printf2() { local fmt="$1" shift printf "$fmt" "$@" >&2 } _runcheck() { "$@" if [ $? -ne 0 ] ; then echo2 "ERROR: command '$*' failed." exit 1 fi } Usage() { case $VERBOSE in 1|2) cat <