Arch Update Notifications Using Cron

Arch Linux LogoOne of the great things about Arch is its hands-off approach and KISS approach. Unfortunately, that can also be one of its greatest killjoys.

Update notifications fall victim to this approach. If you’re left to build an Arch system to your own accord, how can the Arch devs know what will work on your system and what won’t? Therefore, instead of worrying about GNOME vs KDE vs Any Other Desktop Environment (that is, if you’re running a GUI at all) and possibly forcing dependencies you don’t want, no package management system will ever be officially supported by Arch outside of pacman.

I realize that there are quite a few solutions to this problem available in the AUR. My personal favorite is Yapan. But after watching the Linux Action Show’s put-down of David Gerwitz’s ZD-Net article, I got to thinking. Yapan et al where solutions derived from previous experiences from elsewhere, most likely Windows and/or Ubuntu. Was there another way available that was more in-line with Arch’s KISS? Yes, actually. And it can scale across multiple computers.

If you are using multiple computers, you can set up all the computers to use a shared cache. If you’re not, skip to the xinitrc stuff as the movements that are about to be mentioned aren’t necessary.

Start with the computer that will act as an update server and then go around and do the same thing on the clients. You can safely ignore any warnings on the clients pertaining to not being able to move files. This just means that the file already existed and was put there by another user.

mkdir -p /home/all/pacman/pkg
mkdir /home/all/pacman/sync
chmod 1777 /home/all/pacman/*
mv /var/cache/pacman/pkg/* /home/all/pacman/pkg
mv /var/lib/pacman/sync/* /home/all/pacman/sync
rm -r /var/cache/pacman/pkg
rm -r /var/lib/pacman/sync
ln -s /home/all/pacman/pkg /var/cache/pacman/pkg
ln -s /home/all/pacman/sync /var/lib/pacman/sync

If the clients are running X sessions with console-kit and dbus, add this line to .xinitrc for each user who can update.

for UU in "user1 user2 etc"; do
 echo 'echo $DBUS_SESSION_BUS_ADDRESS > ~/.dbsbaddr'|cat - /home/$UU/.xinitrc > /tmp/out
 mv /tmp/out /home/$UU/.xinitrc
 chown $UU /home/$UU/.xinitrc
done

Once this is done, only one computer needs to run a cron job to retrieve updates.

For the stand-alone computer (as root):

59 * * * * /usr/bin/pacman -Syuw --noconfirm && /usr/bin/pacman -Qu > /home/[user]/.updates

For the computer acting as an update server to other computers (as root):

59 * * * * /usr/bin/pacman -Syuw --noconfirm && pacman -Qu > /home/all/update-server-updates.list

For other headless servers (as root):

59 * * * * /usr/bin/pacman -Qu > /home/all/other-server-updates.list

For desktop clients querying for updates to themselves (as user):

*/5 * * * * /usr/bin/pacman -Qu > ~/.updates && [ -s ~/.updates ] && DISPLAY=:0.0 XAUTHORITY=~/.Xauthority DBUS_SESSION_BUS_ADDRESS=`cat ~/.dbsbaddr` /usr/bin/notify-send -t 10000 -u normal "Updates Available" "`cat ~/.updates`"

For desktop clients querying for updates to servers:

*/5 * * * * [ -s /home/all/other-server-updates.list ] && DISPLAY=:0.0 XAUTHORITY=~/.Xauthority DBUS_SESSION_BUS_ADDRESS=`cat ~/.dbsbaddr` /usr/bin/notify-send -t 10000 -u normal "File Server Updates" "`cat /home/all/other-server-updates.list`"

If you’re not using dbus for whatever reason, you can also check out alternatives to notify-send like zenity, kdialog, gmessage, xmessage, xosd-bin.

UPDATE 2011-12-23: Forgot one major aspect, and that’s package maintenance. If you don’t run /usr/bin/pacman -Sc every once and a while, you’ll end up with multiple versions of the same package. However, that command will clear out all packages from the cache that are not currently installed on the local machine. You can edit /etc/pacman.conf and change CleanMethod to KeepCurrent, but that will only keep the latest version of all packages. There is a script in the AUR called cacheclean that will allow you to specify how many previous versions to keep.