星期六, 2月 05, 2022

ArchLinux 的 Reflector

 

Reflector 是一個用來更新 mirrorlist 的程式,前幾年看到的時候就用了,挺不錯的。最近想起來,但怎麼樣也找不到筆記,我想應該是沒有紀錄到吧,特別寫這篇來記著。

ArchLinux 維基的 Reflector 頁面寫的蠻清楚的,就不再贅述,下面主要紀錄我做的設定。

安裝

yay -S reflector

新增檔案:$HOME/bin/renew_mirrorlist ,這主要是方便手動更新用的。

#!/bin/bash
sudo /bin/sh -c "reflector @/etc/xdg/reflector/reflector.conf && rm -f /etc/pacman.d/mirrorlist.pacnew"

編輯檔案:/etc/xdg/reflector/reflector.conf ,這個檔案會被 reflector.service 跟 reflector.timer 使用到。

# 存到 /etc/pacman.d/mirrorlist
--save /etc/pacman.d/mirrorlist
# 只用 http 跟 https 的來源
--protocol http,https
# 從台灣、日本的伺服器來挑
--country Taiwan,Japan
# 挑最近更新的 10 個伺服器
--latest 10
# 用分數來排序
--sort score
# 最近 24 小時內同步完的伺服器
--age 24

新增檔案:/etc/pacman.d/hooks/mirrorupgrade.hook,這會在 pacman 更新 mirrorlist 時去執行。這同時也要修改 /etc/pacman.conf,把裏面 HookDir 那行的註解拿掉。

[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 "/usr/bin/reflector @/etc/xdg/reflector/reflector.conf && rm -f /etc/pacman.d/mirrorlist.pacnew"

最後再啟用定時更新

systemctl enable reflector.timer
systemctl start reflector.timer

沒有留言: