#!/usr/bin/perl

#
# The Wookee upgrade notification tool
#
# (C) 2006-2007 Julian Mehnle <julian@mehnle.net>
# $Id$
#
##############################################################################

=head1 NAME

wookee-upgrade - The Wookee upgrade notification tool.

=head1 VERSION

1.103

=head1 SYNOPSIS

B<wookee-upgrade>

=head1 DESCRIPTION

Should be called after a Wookee installation was upgraded (this happens
automatically on Debian systems).  Notifies registered Wookee-using programs
about the upgrade by calling their upgrade hooks installed in
C</etc/wookee/upgrade-hooks/>.

=head1 AUTHOR

Julian Mehnle <julian@mehnle.net>

=cut

use version; our $VERSION = qv('1.103');

use warnings;
use strict;

use IO::Handle;
use IO::Dir;

use constant TRUE   => (0 == 0);
use constant FALSE  => not TRUE;

use constant UPGRADE_HOOKS_DIR      => '/etc/wookee/upgrade-hooks';
use constant UPGRADE_HOOKS_IGNORE   => qr#^\.|\.(dpkg-.*|bak|new|old)$#;

STDOUT->autoflush(TRUE);

my $hook_dir = IO::Dir->new(UPGRADE_HOOKS_DIR);

foreach my $hook ($hook_dir->read) {
    my $hook_path = UPGRADE_HOOKS_DIR . '/' . $hook;
    next if $hook =~ UPGRADE_HOOKS_IGNORE or not -f $hook_path or not -x _;
    print("Notifying $hook about Wookee upgrade...\n");
    system($hook_path);
}

