You are not logged in.
Pages: 1
Hi
I wrote a couple of simple scripts to automatically refresh pacman database and popup a notification when new packages are available.
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.
Offline
Nobody? :?
However I forgot to say that it requires python (of course), dbus, notification-daemon and libnotify
Offline
I'm afraid I don't use dbus. Thanks for the effort though.
A bus station is where a bus stops.
A train station is where a train stops.
On my desk I have a workstation.
Offline
Nice one, could save me some -Syu's. Line 12 fails using Tango icon theme, I just hardcoded a icon, then it worked ok. I would like it better if it placed a icon in the system tray, easy to miss the message only lasting a short time.
Offline
Thanks Fred, I'm gonna give it a try. Getting notification is a great idea.
Russ
Offline
I'm afraid I don't use dbus. Thanks for the effort though.
Is there a reason/benefit for this?
Offline
Pages: 1