Arch Linux – Automating Single Package Updates

By | December 7, 2017

I have been a long time user of Arch and recently, I wanted to update a single package on a set schedule.  Here is how you can do it from a simple bash script:

#!/bin/bash
# the next line updates the package database only
pacman -Sy
# the next line updates only a single package if it needs to be.
pacman -S –needed –noconfirm [package]
# if the package is a daemon, we will need to refresh and restart
systemctl daemon-reload
systemctl restart [package]

Unfortunately, pacman does not support useful exit codes, so you can not only reload/restart the daemon if it’s been upgraded (at least, not yet).  Pacman will always return 0 if the package is upgraded or not and will return a 1 if a true error occurs.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.