Reflector

Reflector is a script that allows you to get a list of mirrors from the MirrorStatus page, filter them based on their update, sort them by speed and overwrite the file /etc/pacman.d/mirrorlist.

Warning: It is prudent to make a backup copy of /etc/pacman.d/mirrorlist before proceeding: cp -vf /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup

Installation

Install the reflector package.

pacman -S reflector

 The following command gets five mirrors chosen based on speed and overwrites:

# reflector --verbose -l 5 --sort rate --save /etc/pacman.d/mirrorlist

The following command generates a list of 200 HTTP servers among the most updated, sorts them by download speed and overwrites them /etc/pacman.d/mirrorlist

# reflector --verbose -l 200 -p http --sort rate --save /etc/pacman.d/mirrorlist

The following command generates a list of up to 200 HTTP servers among the most up to date in Italy, France and Germany, sorts them by download speed and overwrites /etc/pacman.d/mirrorlist:

# reflector --verbose -c Germany -c France -c Italy -l 200 -p http --sort rate --save /etc/pacman.d/mirrorlist

Automation

Pacman hook

You can create a pacman hook that will run reflector and remove the .pacnew file created every time pacman-mirrorlist gets an upgrade.

/etc/pacman.d/hooks/mirrorupgrade.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 "reflector --country 'United States' --latest 200 --age 24 --sort rate --save /etc/pacman.d/mirrorlist; rm -f /etc/pacman.d/mirrorlist.pacnew"

Make sure to substitute in your desired arguments for reflector.

Systemd service

This is an example of a service unit that waits for the network to be up and online before running reflector:

/etc/systemd/system/reflector.service
[Unit]
Description=Pacman mirrorlist update
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/reflector --protocol https --latest 30 --number 20 --sort rate --save /etc/pacman.d/mirrorlist

[Install]
RequiredBy=multi-user.target

starting reflector.service will update the mirrorlist. To update the mirrorlist every time the computer boots, enable the service.

Systemd timer

If you want to run reflector.service on a weekly basis, create an associated .timer. For example:

/etc/systemd/system/reflector.timer
[Unit]
Description=Run reflector weekly

[Timer]
OnCalendar=Mon *-*-* 7:00:00
RandomizedDelaySec=15h
Persistent=true

[Install]
WantedBy=timers.target

And then just start the reflector.timer.

Reflector-timer package

Install reflector-timerAUR to run reflector weekly.

The default configuration, which can be edited to fit one’s needs, is:

/usr/share/reflector-timer/reflector.conf
AGE=6
COUNTRY=Germany
LATEST=30
NUMBER=20
SORT=rate
### remove an entry if you don't want it as available protocol
PROTOCOL1='-p http'
PROTOCOL2='-p https'
PROTOCOL3='-p ftp'

Be sure to enable reflector.timer.

Cron task

To update the mirrorlist daily, consider the following:

/etc/cron.daily/mirrorlist
#!/bin/bash

# Get the country thing
/usr/bin/reflector -c "India" -p http --sort rate > /etc/pacman.d/mirrorlist

# Work through the alternatives
/usr/bin/reflector -p http  --latest 20 -p https -p ftp --sort rate >> /etc/pac
man.d/mirrorlist

 

Calogero Scarnà
Calogero Scarnà
Articoli: 299

Newsletter

Inserisci il tuo nome e il tuo indirizzo email qui sotto e iscriviti alla nostra newsletter