Skip to content

Instantly share code, notes, and snippets.

@yavorski
Created November 23, 2024 11:50
Show Gist options
  • Save yavorski/ea720e2c728e7faa67f0cb34cf96b70a to your computer and use it in GitHub Desktop.
Save yavorski/ea720e2c728e7faa67f0cb34cf96b70a to your computer and use it in GitHub Desktop.
Auto update arch linux pacman mirrors list

Auto update mirror list

pacman -S reflector
pacman -S pacman-contrib

Edit the reflector configuration file at /etc/xdg/reflector/reflector.conf

# setup reflector options
REFLECTOR_CONF="/etc/xdg/reflector/reflector.conf"
mv $REFLECTOR_CONF "$REFLECTOR_CONF.BAK"
touch $REFLECTOR_CONF
cat >> $REFLECTOR_CONF << EOL
# $REFLECTOR_CONF
# ------------------------------------------
--age 24
--latest 32
--protocol https
--sort rate
--sort score
--sort country
--country 'BG,RO,PL,SI,HU,CZ,FR,NL,DE,UA,CH,IT,DK,LT,LV,GB'
--save /etc/pacman.d/mirrorlist
EOL

Start and Enable reflector.service and reflector.timer

systemctl start reflector.service
systemctl enable reflector.service

systemctl start reflector.timer
systemctl enable reflector.timer

Create a pacman hook that will start reflector.service and remove the .pacnew file created every time pacman-mirrorlist gets an upgrade

# create hooks dir
mkdir /etc/pacman.d/hooks

# create mirror-update.hook file
touch /etc/pacman.d/hooks/mirror-update.hook

Enter the following content to mirror-update.hook

# /etc/pacman.d/hooks/mirror-update.hook
# --------------------------------------
[Trigger]
Operation = Upgrade
Type = Package
Target = pacman-mirrorlist

[Action]
Description = Updating pacman-mirrorlist with reflector and removing pacnew...
When = PostTransaction
Depends = reflector
Exec = /bin/sh -c 'systemctl start reflector.service; if [ -f /etc/pacman.d/mirrorlist.pacnew ]; then rm /etc/pacman.d/mirrorlist.pacnew; fi'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment