XFCE update notifier for pacman

I have not found a simple tool to alert on available packages update with XFCE4 on Archlinux. So I've tried to write a code snippet using the XFCE generic monitor plugin. It can be easily added in the dashboard bar.

Update pacman database

First, it is necessary to update regularly the pacman database. Only root can do that. So I've installed crontab to schedule pacman update and append a task for that.

# install and enable cronie, a crontab service
sudo pacman -S cronie
systemctl enable cronie
systemctl start cronie

# append the task "pacman -Sy" every two hours
(sudo crontab -l ; echo "* */2 * * * /usr/bin/pacman -Sy >/dev/null 2>&1") | sort - | uniq - | sudo crontab -

Then I write small script compatible with xfce genmon plugin.

For example, call it ~/mon_updates.sh with this content :

#!/bin/bash
# 
# This script has to be used in an XFCE4 generic monitor plugin
# https://docs.xfce.org/panel-plugins/xfce4-genmon-plugin
#
# it is necessary to schedule a regular check of update with root account
# add this line in root crontab (without first #) executed each 2 hours
# */2 * * * * /usr/bin/pacman -Sy >/dev/null 2>&1
#

# count lines of updates
NB_PACKAGES=$(pacman -Qu | wc -l)

# display OK icon or number of updates
if [ $NB_PACKAGES -eq 0 ];then
    echo "<img>/usr/share/icons/Adwaita/24x24/legacy/emblem-default.png</img>"
else
    echo "<txt>$NB_PACKAGES upd </txt>"
    echo "<img>/usr/share/icons/Adwaita/24x24/legacy/system-software-update.png</img>"
fi

# generate tooltip with list of packages to update
echo "<tool>$(pacman -Qu)</tool>"

# on click, lauch "pacman -Syu" in a terminal
echo "<txtclick>xfce4-terminal -H -e 'bash -c \"sudo pacman -Syu\"'</txtclick>"

# end

then make it executable

chmod +x ~/mon_updates.sh

Add monitor

Now add a "Generic monitor" plugin in your dashboard bar (right click on the bar, dashboard, add new item) and associate it with your script ~/mon_updates.sh and run it every 600 seconds.

You will see an icon with packages number and list of them in tooltip (mouse hold over generic monitor)

screenshot of available updates

🖼️
screenshot of available updates

Clicking on the number of packages would launch a terminal with the command to update : "pacman -Syu"

Or a green check if your system is up to date !

screenshot with system ok

🖼️
screenshot with system ok

[..]

🐘 gemini://adele.pollux.casa/gemlog/2021-03-04_Xfce_update_notifier_for_pacman.gmi