You are not logged in.

#1 2006-05-15 14:27:47

fredp
Member
From: Italy
Registered: 2005-08-11
Posts: 30

System update notifier

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

#2 2006-05-16 12:07:47

fredp
Member
From: Italy
Registered: 2005-08-11
Posts: 30

Re: System update notifier

Nobody? :?

However I forgot to say that it requires python (of course), dbus, notification-daemon and libnotify

Offline

#3 2006-05-16 12:10:50

FUBAR
Member
From: Belgium
Registered: 2004-12-08
Posts: 1,029
Website

Re: System update notifier

I'm afraid I don't use dbus. Thanks for the effort though. smile


A bus station is where a bus stops.
A train station is where a train stops.
On my desk I have a workstation.

Offline

#4 2006-05-16 15:04:39

lessthanjake
Member
From: Norway
Registered: 2005-11-09
Posts: 319
Website

Re: System update notifier

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

#5 2007-09-01 21:40:10

ruscook
Member
From: Sydney Australia
Registered: 2007-08-27
Posts: 105
Website

Re: System update notifier

Thanks Fred, I'm gonna give it a try. Getting notification is a great idea.
Russ

Offline

#6 2008-05-26 00:15:52

poor_kenny
Member
Registered: 2008-05-14
Posts: 13

Re: System update notifier

FUBAR wrote:

I'm afraid I don't use dbus. Thanks for the effort though. smile

Is there a reason/benefit for this?

Offline

Board footer

Powered by FluxBB