Skip to content

Instantly share code, notes, and snippets.

@gntlmnoffice
Forked from helixw/sort-mirrors
Created November 29, 2020 15:06
Show Gist options
  • Select an option

  • Save gntlmnoffice/4ed4ef7c5e2105ca9840e5dbc877854f to your computer and use it in GitHub Desktop.

Select an option

Save gntlmnoffice/4ed4ef7c5e2105ca9840e5dbc877854f to your computer and use it in GitHub Desktop.
Script sorts pacman mirrors for Arch Linux/Arch based distros as per ping received.
#!/bin/sh
# Description: Script sorts pacman mirrors for Arch Linux as per ping received.
# Author: HelixW <shreyas.2000@hotmail.com>
# Check for sudo
if ! [ $(id -u) = 0 ]; then
echo "$(tput setaf 1)Root priviledge required; use sudo."
exit 1
fi
# Check if reflector is installed
if ! command -v reflector &>/dev/null; then
echo "$(tput setaf 1)Reflector package could not be resolved."
echo "$(tput setaf 3)Reflector is available in the community repository, run sudo packman -Sy reflector to install."
echo "More information on reflector @ https://wiki.archlinux.org/index.php/reflector.$(tput sgr 0)"
exit 1
fi
# Initialization statement
TIME=$(date +"%r")
DATE=$(date +"%D")
echo -ne "$(tput setaf 2)Initiating pacman mirror sort as per rate @ [$TIME | $DATE] "
for _ in $(seq 1 3); do
echo -ne ". \033[0K"
sleep 1.2
done
# Command info
echo && echo "$(tput setaf 3)RUNNING: reflector --verbose --sort rate --save /etc/pacman.d/mirrorlist$(tput setaf 6)"
# Sort mirrors
time reflector --verbose --sort rate --save /etc/pacman.d/mirrorlist
# Ending quotes
echo -e "\n$(tput setaf 2)Sorting completed successfully, check /etc/pacman.d/mirrorlist$(tput sgr0)"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment