You are not logged in.

#1 2012-01-10 21:18:24

Tribal
Member
Registered: 2012-01-10
Posts: 1

Pacman mirrorlist update script

Hey all, I thought I would share this script I made awhile ago to automatically update my pacman mirrorlist. It requires reflector and currently grabs the 8 most recently updated servers and sorts them by speed. It there is no internet connection, pacman is currently running, or reflector fails for some reason it will wait 60 seconds and retry until RETRY_TIMEOUT reaches 0.

#!/bin/sh

[ -e /usr/bin/reflector ] || exit

RETRY_TIMEOUT=10
PACMAN_ISRUNN=1

retry() {
   if [ "$RETRY_TIMEOUT" != 0 ]; then
      RETRY_TIMEOUT=$(( RETRY_TIMEOUT-1 ))
      sleep 60
      main
   fi

   [ -e /etc/pacman.d/mirrorlist.new ] && rm /etc/pacman.d/mirrorlist.new

   exit
}

main() {
   [ ping -w5 -c3 google.com > /dev/null 2>&1 ] && retry

   if [ -e /var/lib/pacman/db.lck ]; then
      PACMAN_ISRUNN=1
      retry
   fi

   PACMAN_ISRUNN=0
   touch /var/lib/pacman/db.lck

   reflector -l 8 --sort rate -p http --save /etc/pacman.d/mirrorlist.new

   if ! grep -q ^S /etc/pacman.d/mirrorlist.new; then
      rm /var/lib/pacman/db.lck
      retry
   fi

   mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
   mv /etc/pacman.d/mirrorlist.new /etc/pacman.d/mirrorlist
   rm /var/lib/pacman/db.lck
   pacman -Syy > /dev/null 2>&1
}

main

Pretty simple, not much really, but if you have any suggestions or comments I'll be here wink

Offline

#2 2012-01-10 22:12:01

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Pacman mirrorlist update script

The wiki has https://wiki.archlinux.org/index.php/Mi … _Generator Maybe you can enhance that script?
If you're not sure if the outcome is correct, post it on the wiki talk page first.

Offline

#3 2012-01-11 00:20:10

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: Pacman mirrorlist update script

mod action: Moving from Programming & Scripting to Community Contributions.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#4 2012-01-11 04:13:26

anonymous_user
Member
Registered: 2009-08-28
Posts: 3,059

Re: Pacman mirrorlist update script

@karol - The script in the wiki does not rely on reflector. Though this script would be nice for users of reflector.

Offline

Board footer

Powered by FluxBB