I'm afraid I don't use dbus. Thanks for the effort though.
Is there a reason/benefit for this?
]]>However I forgot to say that it requires python (of course), dbus, notification-daemon and libnotify
]]>check_updates.sh:
#!/bin/sh
pacman -Sy
PACKAGES=$(pacman -Sup | wc -l)
let PACKAGES-=1
if [ "$PACKAGES" -gt 0 ]; then
dbus-send --system /org/archlinux/resources/system/updates org.archlinux.resources.system.updates.UpdateAvailable int32:"$PACKAGES"
fi
notify_updates.py
#!/usr/bin/env python
import dbus, dbus.glib
import gtk
systembus = dbus.SystemBus()
sessionbus = dbus.SessionBus()
notifications = dbus.Interface(sessionbus.get_object('org.freedesktop.Notifications',
'/org/freedesktop/Notifications'), 'org.freedesktop.Notifications')
icon = gtk.icon_theme_get_default().lookup_icon("update-notifier", 48,
gtk.ICON_LOOKUP_USE_BUILTIN).get_filename()
def notify_updates(num):
if num < 1:
return
elif num == 1:
verb = "is"
s = ""
else:
verb = "are"
s = "s"
notifications.Notify("Update manager", 0, icon, "Updates available",
"There %s %d package%s that can be updated" % (verb, num, s), "", {}, -1)
systembus.add_signal_receiver(notify_updates, 'UpdateAvailable',
'org.archlinux.resources.system.updates')
gtk.main()
The first one (check_updates.sh) is to be executed when you want to refresh the database (and so must be executed as root): then, if new packages are found, it emits a "UpdateAvailable" signal on DBus system bus.
The second script is instead run in background by the user who wants to be notified of new packages: when the UpdateAvailable signal is emitted, it shows a popup notification telling you how many packages can be upgraded.
For example, I run notify_updates.py as a normal user (I put it among the programs Gnome loads at startup), and I added /path/to/check_updates.sh to /etc/ppp/ip-up , so that it is called when I connect to the internet (unlucky me I can't have DSL), but perhaps you may want to set up a proper cron job to call it periodically.
]]>