Welcome to rc-linux.com

A personal blog about Linux and FOSS in general

How to recreate the « Arch Linux Updates Indicator » GNOME extension on XFCE

Introduction :

Hi everyone,

I left GNOME for XFCE a few month ago.

And the only thing I was missing is the « Arch Linux Updates Indicator » GNOME extension.

Indeed, I like to have a simple and easy way to track and apply available upgrades.

As I couldn’t find something similar to simply download and install somehow, I decided to create my own “Arch Linux Updates Indicator” using a generic monitor.

And… I’m pretty happy with what I came up with. So I decided to share it with you guys 🙂

Unfortunately, the way it is built makes it a bit hard to share as a single package or a simple “one command line installation process” (or maybe I just didn’t found a simple way to do so yet… Feel free to help me with that !).

Anyway, it is still very simple to reproduce and adapt to your needs/configuration.

Disclaimer :

Obviously, it is meant to be used with Arch Linux (or Arch based distros).

It also handle “AUR Packages” updates through “yay”.

But as I said earlier, it should be fairly easy to adapt it to another AUR helper (or no AUR helper at all if you don’t use AUR packages) but also to other distributions/package managers 🙂

How it works :

It works as a simple “available update counter” next to a clickable icon at its left in your top bar (the ones between the “>” and the clipboard manager) :

The “available update counter” shows the actual number of available updates for your system, only if it is not equal to 0 (Nobody cares being notified that you do not have any update to apply I guess…).

In the above screenshot, you can see that I have currently 3 available updates for my system.

The counter updates itself at each boot of your computer and then once per hour.

The icon at its left is a clickable icon that will open a terminal that shows you the actual list of packages that can be updated, classified separately between “regular packages” and “AUR packages” :

Clicking this icon will also automatically refresh the counter to make sure they both have a matching results.

You can then press “enter” to apply updates or “ctrl + c” to quit without applying them.

If you choose to apply updates, you will then be asked to provide your “sudo” password and the update process will automatically begin.

While the updates are processing, you’ll notice that the icon in your top bar will change like so :

Once the update process has finished, you will be prompted with the following message saying “Updates have been applied”. You just then need to press “enter” to quit :

If you aborted the update process or if it had an error, the message will be “Updates have been aborted” (preceded by the error message related to the problem it had) will display. You can then press “enter” to quit as well.

Once updates are done, you’ll notice that the icon will switch back to it’s initial “checking” image.

Also, the counter will disappear (until the next available update 😉 ) :

Remember that clicking the icon refresh the list of packages to update but also the counter (if you do not want to wait for its next auto-refresh).

If you do not have any package to update, you’ll see the following message :

And this is pretty much it, this is how it works (according to the way I built it). 🙂

Now, before seeing how you can reproduce it on your computer, you’ll first need a few dependencies.

Dependencies :

Arch Linux or an Arch Based distribution (obviously…).

– The XFCE Desktop Environment (obviously…).

– The “xfce4-genmon-plugin” package (which is included in the “xfce4-goodies” package group).

If you perform minimal XFCE installation by selecting the packages you install instead of installing the whole package group (like I do), make sure you have this one installed as we’ll use a generic monitor.

– The “pacman-contrib” package.

This package provides the “/usr/bin/checkupdates” script that we’ll be using in our generic monitor so it will not need “sudo” privileges to list available updates.

– The “yay” AUR Helper.

If you use a different AUR Helper or if you don’t use one at all, you’ll need to modify the scripts accordingly.

How to reproduce it :

This update indicator is based upon 3 simple scripts and a generic monitor.

The generic monitor’s script

The first thing we’ll do is to create the script used by the generic monitor to display information.

I called it “genmon_update.sh”, here’s its content :

#!/bin/bash

echo "<icon>mintupdate-checking</icon>"
echo "<iconclick>xfce4-terminal -x /home/rcandau/Documents/scripts/check_update.sh</iconclick>"
echo "<txt>$(/home/rcandau/Documents/scripts/update_notifier.sh)</txt>"

The third line is used to display the icon of the generic monitor. I chose the “mintupdate-checking” icon which is included in the “Tela Circle Theme” installed on my system.

If you prefer working with images instead of icons, you can use the following line instead :

echo "<img>Path to the image to display</img>"

The fourth line is used to determine the command to launch when you click on the icon. In my case, I asked to launch the “check_update.sh” script (that I will present you a bit later in this article) through the xfce4-terminal.

If you chose to work with an image rather than an icon in the third line of the script, you’ll need to change the “<iconclick>” and “</iconclick>” tags by “<click>” and “</click>”.

Finally, the fifth line is used to determine what text the generic monitor should display next to the icon/image.

It can be a command output by using this following pattern :

$(command)

In my case, I asked to display the output of the “update_notifier.sh” script that I will present right now.

There’s much more you can do with that type of script used by a generic monitor. Check this link for further information.

The « available update counter » script

Now we need to create the script that handle the “available update counter”.

I called it “update_notifier.sh”, here’s its content :

#!/bin/bash

UPDATE_NUMBER=$( (/usr/bin/checkupdates ; /usr/bin/yay -Qua) | wc -l)

if [ "$UPDATE_NUMBER" -ne 0 ]; then
        echo "$UPDATE_NUMBER"
else
        echo ""
fi

This is a pretty basic script.

What it does is that it gets how many updates are available by counting the number of lines returned by the “/usr/bin/checkupdates” script (for regular packages) and the “yay -Qua” command (for AUR packages), as each lines returned by those commands is equal to a package available to update.

Then, we just tell the script to print the number of available updates only if it is not equal to 0.

If it is equal to 0, I told it to print an empty character. The aim here, is to prevent the script to print a “0” when there’s no available update, as we do not care to be notified in that case.

Make sure to modify the “genmon_update.sh” script’s “<txt>” section according to the name and path you gave to this script.

The « check_update.sh » script

This script is used to give you the list of packages available to update classified separately between “regular packages” and “AUR packages” and apply available updates if you wish to.

This is actually the script that will be executed when you’ll click on the icon of the generic monitor.

I called it “check_update.sh”, here’s its content :

#!/bin/bash

PACKAGES=$(/usr/bin/checkupdates | awk '{print $1}')
AURPACKAGES=$(/usr/bin/yay -Qua | awk '{print $1}')

xfce4-panel --plugin-event=genmon-22:refresh:bool:true

if [ -n "$PACKAGES" ]; then
        echo -e "Packages :\n" && echo -e "$PACKAGES\n"
fi

if [ -n "$AURPACKAGES" ]; then
        echo -e "AUR Packages :\n" && echo -e "$AURPACKAGES\n"
fi

if [ -z "$PACKAGES" ] && [ -z "$AURPACKAGES" ]; then
        echo -e "No update available\n" && read -n 1 -r -s -p $'Press \"enter\" to quit\n'
        exit 0
else
        read -n 1 -r -s -p $'Press \"enter\" to apply updates or \"ctrl + c\" to quit\n'
        sed -i "s/mintupdate-checking/mintupdate-installing/" /home/rcandau/Documents/scripts/genmon_update.sh && xfce4-panel --plugin-event=genmon-22:refresh:bool:true
        sudo pacman -Syu && yay -Syu

        if [ "$?" -ne 0 ]; then
                sed -i "s/mintupdate-installing/mintupdate-checking/" /home/rcandau/Documents/scripts/genmon_update.sh && xfce4-panel --plugin-event=genmon-22:refresh:bool:true
                echo -e "\nUpdates have been aborted\n" && read -n 1 -r -s -p $'Press \"enter\" to quit\n'
                exit 1
        fi

        sed -i "s/mintupdate-installing/mintupdate-checking/" /home/rcandau/Documents/scripts/genmon_update.sh && xfce4-panel --plugin-event=genmon-22:refresh:bool:true
        echo -e "\nUpdates have been applied\n" && read -n 1 -r -s -p $'Press \"enter\" to quit\n'
        exit 0
fi

As you can see, this script is a bit more complex, but don’t worry I’ll explain it to you (without going in too much details tho, otherwise this article we’ll be too long. If your comfortable with bash, it is pretty easy to understand anyway).

At lines 3 and 4 we are getting the lists of package’s name available to update and we store them in 2 different variables (one for “regular packages” and one for “AUR packages”).

I told the script to only shows the first column of the list, the second one being the version changes from the current one installed on your system. I personally don’t care about this information. But if you want the version changes to be printed, just change the line 3 and 4 by the following ones respectively :

PACKAGES=$(/usr/bin/checkupdates)
AURPACKAGES=$(/usr/bin/yay -Qua)

Then, as I said earlier, clicking on the icon will update the counter to make sure they both have a matching results. Well this what line 6 is for. It told the generic monitor to refresh itself.

You’ll probably need to modify this line as well as lines 21, 25 and 30 in order to make them match to your generic monitor’s ID (as well as other things), which will probably be different then mine. But don’t worry, I’ll explain that to you in the next part.

Then I told the script to show the list of packages available to update (if there’s any) for both “regular packages” and “AUR packages”.

If the list is empty for both “regular packages” and “AUR packages” (meaning there’s no available update), then the script shows a message saying that there’s no update available and invite you to quit by pressing “enter”.

The script then asks you if you want to apply the updates (by pressing “enter”) or not (by pressing “ctrl + c”).

If you choose to apply the updates, then the script changes the icon of the generic monitor by modifying it in the “genmon_update.sh” script and refreshing it (in my case it changes the icon from “mintupdate-checking” to “mintupdate-installing”). Once done, it launches the update process.

Finally, if the update process went well, the icon of the generic monitor is switched back to its initial icon (in my case it goes back from “mintupdate-installing” to “mintupdate-checking”), refresh the counter and tells you that the updates have been applied before inviting you to quit by pressing “enter”.

Otherwise, it also changes back the icon of the generic monitor to its initial icon but tells you that the updates have been aborted (preceded by the error message related to the problem it had) before inviting you to quit by pressing “enter”.

Make sure to modify the “genmon_update.sh” script’s “<clickicon>” (or <click> if you work with an image rather than an icon) section according to the name and path you gave to this script.

Also, keep in mind that you’ll probably need to modify lines 6, 21, 25 and 30 of this script according to your generic monitor’s ID, icon used and path to the “genmon_update.sh” script (we’ll see that right in the following part of this article).

Create your generic monitor

Let’s move on to the final step, by creating the generic monitor in your top bar !

To do so, just reproduce the following steps :

My system is in french but I’m sure you’ll figure out 😉

Right click on your top bar and go into your panel properties :

Once in the panel properties, go to the Items section and add a new item :

Select “Generic Monitor” and click on “add”. Once added, you can move it anywhere you want on your top bar by selecting it in the “item tab” and using the up and down arrows (that you can see on the previous screenshot) :

Then, configure it by double clicking on it :

– In the “command” section, put the path to your “genmon_update.sh” script.

– In the label section, you can give it a name.

I personally named it “Arch Update” but I recommend you to uncheck the “label” checkbox otherwise the name of you generic monitor will be printed next to it in your top bar.

– In the “Period” section, select the period (in seconds) you want your generic monitor to update itself (this is mostly for the “available update counter” in our case).

I personally put 3600,00 seconds which is equal to an hour. Don’t forget that your generic monitor will also automatically update itself one time at each boot of your computer and each times you click on the icon.

Here’s my personal configuration :

Last, but not least, you’ll need to get the ID of your generic monitor to modify the “check_update.sh” script accordingly.

To do so, just hover your mouse over your generic monitor in the Items tab of the properties of your panel.

What we’re looking for is the Internal name “genmon-X” (for instance, mine is “genmon-22”) :

Once you have the internal name of your generic monitor, modify the following lines in your “check_update.sh” script accordingly (changes to make are in bold) :

X = number associated to your generic monitor (shown in its internal name).

icon_name_1 = Icon to show when checking for new updates.

icon_name_2 = Icon to show when applying updates.

Line 6

xfce4-panel –plugin-event=genmon-X:refresh:bool:true

Line 21

sed -i “s/icon_name_1/icon_name_2/” /path/to/your/genmon_update.sh/script && xfce4-panel –plugin-event=genmon-X:refresh:bool:true

Line 25

sed -i “s/icon_name_2/icon_name_1/” /path/to/your/genmon_update.sh/script && xfce4-panel –plugin-event=genmon-X:refresh:bool:true

Line 30

sed -i “s/icon_name_2/icon_name_1/” /path/to/your/genmon_update.sh/script && xfce4-panel –plugin-event=genmon-X:refresh:bool:true

Conclusion

And you’re finally done !

Now your “Update Indicator” generic monitor should work perfectly 🙂

As I already said, it is easy to adapt and new features can be easily added.

For instance, if you want to have real system notifications each time a new update is available/applied, you just have to add some “notify-send” commands to the different scripts.

Anyway, feel free to reproduce this “Update Indicator”, modify it, improve it, etc…

Also, feel free to post a comment under this article if you have any questions or problems with it 🙂

Bye !

Robin Candau

Leave a Reply

Your email address will not be published.

Back to top