Xfce Software Update Notifications

Simple Software Update for XFCE Notification Plugin
1. Install octopkg and xfce4-notifyd
$ pkg install octopkg xfce4-notifyd

2. Create /usr/local/lib/pkg-update.sh (updated)
Bash:
#!/usr/local/bin/bash

notified=false
while true; do
  ifconfig | grep -q 'broadcast'
  if [ $? == 0 ]; then
    sudo pkg upgrade -n | grep -q 'Number of packages to be'
    if [ $? == 0 ]; then
      if [ $notified == false ]; then
        notified=true
        $(notify-send "Software Update" "There are new available package updates." --icon software-update-available --action octopkg=Update)
      fi
    else
      notified=false
    fi
    sleep 3600
  else
   sleep 300
  fi
done

3600 = 1 hour, update check frequency
300 = 5 minutes, network check frequency

3. Create a /usr/local/libexec/pkg-update symbolic link
$ cd /usr/local/libexec
$ ln -s /usr/local/lib/pkg-update.sh pkg-update

4. Add a /usr/local/etc/sudoers.d/pkg-update file with (users must belong to wheel group)
%wheel ALL=(ALL) NOPASSWD: /usr/sbin/pkg upgrade -n

5. Add a ~/.config/autostart/Software\ Update.desktop file with
Code:
[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=Software Update
Comment=Check for software updates
Exec=/usr/local/libexec/pkg-update
OnlyShowIn=XFCE;
RunHook=0
StartupNotify=false
Terminal=false
Hidden=false

And that's it!
We got update notifications.
 
Last edited:
Improved bash script.
The previous detected updates when network was down
You may add an warning notification for when pkg update fails but I decided not to.

Bash:
#!/usr/local/bin/bash

while true; do
  ifconfig | grep -q 'broadcast'
  if [ $? == 0 ]; then
    sudo pkg update | grep -q 'All repositories are up to date.'
    if [ $? == 0 ]; then
      sudo pkg upgrade -n | grep -q 'Your packages are up to date.'
      if [ $? == 1 ]; then 
        $(notify-send "Software Update" "There are new available package updates." --icon software-update-available --action octopkg=Update)
      fi
    fi
    sleep 3600
  else
   sleep 350
  fi
done
 
Latest version. (I'm updating the original post with this new version)
Don't need to execute pkg update before upgrade as the upgrade does both.
Also changed the condition logic to make sure it only notifies when there are packages and not for any other reason, ie: error executing the command.

Bash:
#!/usr/local/bin/bash

while true; do
  ifconfig | grep -q 'broadcast'
  if [ $? == 0 ]; then
    sudo pkg upgrade -n | grep -q 'Number of packages to be'
    if [ $? == 0 ]; then
      $(notify-send "Software Update" "There are new available package updates." --icon software-update-available --action octopkg=Update)
    fi
    sleep 3600
  else
   sleep 350
  fi
done
 
Fix to avoid repeated notifications

Bash:
#!/usr/local/bin/bash

notified=false
while true; do
  ifconfig | grep -q 'broadcast'
  if [ $? == 0 ]; then
    sudo pkg upgrade -n | grep -q 'Number of packages to be'
    if [ $? == 0 ]; then
      if [ $notified == false ]; then
        notified=true
        $(notify-send "Software Update" "There are new available package updates." --icon software-update-available --action octopkg=Update)
      fi
    else
      notified=false
    fi
    sleep 3600
  else
   sleep 350
  fi
done
 
Back
Top