#!/bin/bash # # Purpose : Keep pacman's mirrorlist on mirrors that are up to date with Arch. # A mirror that stops syncing doesn't cause an error: update and # version just stop seeing new packages, such as a new kernel. # # reflector.timer picks fresh mirrors once a week, and update picks new ones # straight away when the first mirror falls a day behind (updates.d/10-pacman.sh). # To choose mirrors yourself, edit /etc/xdg/reflector/reflector.conf: once it # doesn't start with the CoreDesktop line below, this leaves it alone. To stop # CoreDesktop changing the mirrorlist at all, add reflector to # ~/.config/coredesktop/skip-packages. COREDESKTOP="$HOME/.local/share/coredesktop" source "$COREDESKTOP/utils.sh" CONF=/etc/xdg/reflector/reflector.conf MARKER="# CoreDesktop: choose up-to-date mirrors (system/mirrors.sh)" install_packages reflector || exit 1 # Skipped in skip-packages is_installed reflector || exit 0 # Ours, or reflector's own that no one has edited, is ours to replace (pacman # translates UNMODIFIED, hence LC_ALL=C) if head -n 1 "$CONF" 2> /dev/null | grep -qxF "$MARKER" \ || LC_ALL=C pacman -Qii reflector 2> /dev/null | grep -qE "^UNMODIFIED[[:space:]]+$CONF$"; then # Mirrors that synced in the last 12 hours, fastest first. --latest rates only # the 20 most recently synced, as rating every mirror takes minutes. sudo tee "$CONF" > /dev/null << EOF $MARKER # Delete the line above to choose your own; CoreDesktop then leaves this alone. --save /etc/pacman.d/mirrorlist --protocol https --age 12 --completion-percent 100 --latest 20 --sort rate EOF else echo "Keeping your own mirror choices in $CONF." fi enable_services reflector.timer # A failed refresh leaves the mirrorlist as it was echo "Choosing up-to-date mirrors..." if ! sudo systemctl start reflector.service; then echo "Couldn't choose new mirrors; keeping the ones in /etc/pacman.d/mirrorlist." fi exit 0