Skip to content

FUSE coolness with mhddfs

Let’s say you have three disks but you wish to share with Samba or NFS clients.

Of course you could just mount the disks on three separate mount points and export those. Or you could mount the three disks on three mount points inside the same directory and export the parent directory. The problem with both solutions is you have to “balance” the data among the disks – and it will make navigating your TViX, WDTV or Popcorn more annoying.

You could use RAID or LVM to handle all this for you. But. What if you already have data on the disks? What happens if one of the disks dies? With RAID0 or LVM your data is gone.

Luckily you can have the best of both worlds: mhddfs

mhddfs is a FUSE plugin that combines data from several directories and present it in one directory. The only downside is that you do not know (or control) where a file is created. Let’s say you combine /dir1, /dir2 and /dir3 under /virtual. Previously you had /dir1/my_content. This is now /virtual/my_content. If you write a file to /virtual/my_content it will not necessarily end up in /dir1/my_content. This also mean you can not predict what data is lost if you lose a disk.

The plugin is available in Ubuntu

$ sudo apt-get install mhddfs

Using it is pretty simple

$ sudo mkdir /export/hest
$ sudo mhddfs /dir1,dir2,dir3 /export/hest
[sudo] password for alj:
mhddfs: directory '/dir1' added to list
mhddfs: directory '/dir2' added to list
mhddfs: directory '/dir3' added to list
mhddfs: mount to: /export/hest
mhddfs: move size limit 4294967296 bytes

The “move size limit” deserves an explanation:

if free space size threshold if a drive has the free space less than the threshold specifed then another drive will be choosen while creating a new file. If all the drives have free space less than the threshold specified then a drive containing most free space will be choosen.

Default value is 4G, minimum value is 100M.

Now you have the combined space of all three disks

/dir1;/dir2;/dir3
                      589G  329G  260G  56% /export/hest

To mount the combined directory during boot, at this to /etc/fstab:

mhddfs#/dir1,/dir2,/dir3 /export/hest fuse defaults,allow_other 0 0

You can export the combined directory using NFS or Samba. If you export the combined directory using NFS you need to add the fsid option in /etc/exports

/export/hest 192.168.1.0/24(fsid=2,ro,sync,crossmnt,no_subtree_check,insecure)

MoreAdorned MSG template – now compatible with ThumbGen

I’ve stumbled upon yet another tool for generating movie sheets compatible with the WDTV: ThumbGen.

ThumbGen uses Movie Sheet Generator/TViXie compatible templates, but some of them needs to be tweaked a bit.

A user on the WDTV Forum requested an update of the MoreAdorned template – And luckily the author of ThumbGen delivered.

I have repackaged my copy of MoreAdorned with the updated template XML here

Tip: Fixing character encoding in Terminator 0.14 (Ubuntu 10.04)

I’ve been using the excellent terminal emulator Terminator for a long time. Terminator sports (among other things) split screen hand “cluster support” (grouping of screens, making it possible to type the same thing in all terminals).

Example

In previous versions of Ubuntu (Terminator versions prior to 0.14) Terminator would pick all settings from GNOME Terminal, including character encoding (ISO-8859-15 in my case). Apparently this is no longer the case in Ubuntu 10.04, which has Terminator 0.14.

To use another encoding than UTF-8, add the following to ~/.config/terminator/config:

encoding = ISO-8859-15

Substitute ISO-8859-15 with whatever encoding you want.

Some other nice configuration options

scrollback_lines = 10000 # Scroll back size
focus = sloppy # sloppy focus, ie. the focus follows the mouse when moving the pointer to another split-screen

for more options, run man terminator_config.

Tip: Moving the titlebar buttons back where they belong in Ubuntu 10.04

I’m not going to dwell on the subject – The Ubuntu Design team (and in the end Mark Shuttleworth) decided to change the titlebar button layout as part of the new Light GNOME theme (which is a really nice theme); for more information read this article

Being the good Ubuntu fanboy that I am, I have really tried to embrace this new layout – But every time I move the mouse pointer to the right side of the window only to find the close button missing, I grew increasingly frustrated.

Luckily the fix is easy.

From a terminal (or from the run prompt, ALT-F2), run

gconftool-2 --set /apps/metacity/general/button_layout --type string menu:minimize,maximize,close

Tip: How to fix the ATI driver when upgrading Ubuntu 9.10 to 10.04

I decided to upgrade my laptop to 10.04 beta 1.

When the update was done (something I had to do at home because the damn Update Manager does not work with proxies, at least not when running it manually) I was left without a working Xorg configuration, apparently because the fglrx (non-free) ATI driver did not support the x-server used in Lucid. According to the release notes, the fix is the use the open source driver (ati) instead.

After fiddling a bit, I discovered that removing xorg-driver-fglrx and installing the package fglrx did in fact work and I have accelerated OpenGL again.

www.nowhere.dk is now IPv6 enabled

IPv6 readyJust a quick note to let you know that www.nowhere.dk is now accessible through IPv6

$ host -t AAAA www.nowhere.dk
www.nowhere.dk          CNAME   coredump.nowhere.dk
coredump.nowhere.dk     AAAA    2001:2010:0:2:0:0:0:DEAD

The only thing I had to do was to enable IPv6 in Lighttpd, enable IPv6 in ufw (done in /etc/default/ufw) and then re-add any rules to ufw that affect IPv6 (like web and ssh). The last part is crucial and not very well documented.

Irssi notifications in Windows using Growl and Minivan

After completing my script to deliver Irssi notifications to the Linux desktop using Perl (IPC::Message::Minivan and Desktop::Notify), I wondered if this framework could be extended to Windows (since I have a Windows desktop at work).

I have previously looked at Growl (on Linux) and think it is cumbersome to get the notifications across the network – but ended up using it anyway since it’s an easy way to display notifications in Windows (and probably in MacOS as well). There is a another Growl script for Irssi but I wanted to make my own that plugs into Minivan because I wanted the pop ups to look the same on all computers (at least the wording).

On Windows

  1. Download Grow for Windows and install it.
  2. Download MyEnTunnel and install it.
  3. If you haven’t already (which I am guessing you have) then download Putty SSH client and install it
  4. Configure MyEnTunnel to match your configuration, create a remote tunnel: <random port number>:localhost:23053 – The random port is important and will be used later

On the server running Irssi

  1. Install the Minivan – See this article
  2. Install Growl::GNTP
    $ sudo apt-get install libcrypt-cbc-perl libdata-uuid-perl
    $ sudo perl -MCPAN -e 'Growl::GNTP'
  3. Install the script
    #!/usr/bin/perl

    # The IRC icon is from here: http://aurls.info/4o

    use strict;
    use warnings;
    use IPC::Message::Minivan;
    use Encode;
    use Growl::GNTP;
    use Data::Dumper;


    if ($#ARGV != 0) {
        print "Usage: irssi-notify-growl.pl <port number>\n";
        exit;
    }

    my $port = $ARGV[0];

    my $van = IPC::Message::Minivan->new(host => 'localhost');
    $van->subscribe("#irssi");

    my $growl = Growl::GNTP->new(
            AppName => "Irssi",
            PeerHost => "localhost",
            PeerPort => $port,
            Password => "",
            AppIcon => "http://dl.dropbox.com/u/262048/www.nowhere.dk/files/irc.png"
    );

    $growl->register([
            { Name => "irssi", },
    ]);

    $growl->notify(
                    Event => "irssi",
                    Title => "Minivan",
                    Message => "Connection established"
    );

           
    while (1) {
            if (my $cmd = $van->get(5,[])) {
                    if ($cmd->[0] eq '#irssi') {
                            my $c=$cmd->[1];

                            my $message = $c->{msg};
                            my $summary = $c->{summary};
                           
                            $growl->notify(
                                            Event => "irssi",
                                            Title => $summary,
                                            Message => $message,
                            );

                    }
            }
    }

    Copy the script to ~/bin/irssi-notify-growl.pl.

  4. Make the script executable and run it as
    irssi-notify-growl.pl <port number>

    The port number is the one you chose on the Windows machine for your remote tunnel – You need to run an instance of the script for each Growl-client.

Irssi notifications using Desktop Notifications and Minivan

I was pretty happy with solution to get notifications from Irssi though it had some shortcomings.

A couple of days ago a colleague made me aware of a Perl modules written by another colleague (Anton Berezin) called IPC::Message::Minivan which, it turns out, is perfect for my notification script. Basing the notifications on Minivan combine the speed of using something like Dbus locally (instant notifications) with the convenience of my previous script (notifications over the network, able to handle multiple clients).

This setup consists of three parts: The Minivan daemon, the Irssi script and the notification script.

As always my instructions are based on Ubuntu but should work on most Linux and Unix systems.

Installing the Minivan

IPC::Message::Minivan is not yet available directly through CPAN so we need to install it manually

  1. Download IPC::Messaging and IPC::Message::Minivan (and unpack them).
  2. Install dependencies: sudo apt-get install libjson-xs-perl libregexp-common-perl
  3. One could use dh-make-perl but I chose to install the two modules manually
    Basically run “perl Makefile.pl && sudo make install
    :~/devel/IPC-Messaging-0.01_12$ perl Makefile.PL
    Cannot determine license info from lib/IPC/Messaging.pm
    *** Module::AutoInstall version 1.03
    *** Checking for Perl dependencies...
    [Core Features]
    - Test::More                ...loaded. (0.72)
    - B::Generate               ...missing.
    - IO::Socket::UNIX          ...loaded. (1.23)
    - IO::Socket::INET          ...loaded. (1.31)
    - Storable                  ...loaded. (2.18)
    - Time::HiRes               ...loaded. (1.9711)
    - IO::Select                ...loaded. (1.17)
    - Module::Load::Conditional ...loaded. (0.22)
    ==> Auto-install the 1 mandatory module(s) from CPAN? [y] y
    *** Dependencies will be installed the next time you type 'make'.
        (You may need to do that as the 'root' user.)
    *** Module::AutoInstall configuration finished.
    Checking if your kit is complete...
    Looks good
    Warning: prerequisite B::Generate 0 not found.
    Writing Makefile for IPC::Messaging
    :~/devel/IPC-Messaging-0.01_12$ sudo make install
    [sudo] password for alj:
    /usr/bin/perl "-Iinc" Makefile.PL --config= --installdeps=B::Generate,0
    Cannot determine license info from lib/IPC/Messaging.pm
    *** Installing dependencies...
    [MSG] No '/home/alj/.cpanplus/custom-sources' dir, skipping custom sources
    [MSG] No '/home/alj/.cpanplus/custom-sources' dir, skipping custom sources
    [MSG] No '/home/alj/.cpanplus/custom-sources' dir, skipping custom sources
    *** Installing B::Generate...
    Running [/usr/bin/perl /usr/bin/cpanp-run-perl /home/alj/.cpanplus/5.10.0/build/B-Generate-1.26/Makefile.PL INSTALLDIRS=site]...
    # running Build.PL installdirs=site
    /usr/bin/perl Build.PL installdirs=site
    Creating custom builder _build/lib/My/Builder.pm in _build/lib/My
    Checking whether your kit is complete...
    Looks good

    Checking prerequisites...
    Looks good

    Creating new 'Build' script for 'B-Generate' version '1.26'
    Unknown 'build_class', defaulting to 'Module::Build'
    Running [/usr/bin/make test UNINST=1]...
    make[1]: Entering directory `/home/alj/.cpanplus/5.10.0/build/B-Generate-1.26'
    /usr/bin/perl Build --makefile_env_macros 1 test
    t/basic............ok
            2/10 skipped: various reasons
    t/inspect-btest....ok
    t/inspect-this.....ok
    t/new_cv...........ok
    t/op_list..........ok
    t/op_list_bgen.....ok
    All tests successful, 2 subtests skipped.
    Files=6, Tests=721,  0 wallclock secs ( 0.24 cusr +  0.21 csys =  0.45 CPU)
    make[1]: Leaving directory `/home/alj/.cpanplus/5.10.0/build/B-Generate-1.26'

    *** B::Generate successfully installed.
    *** Module::AutoInstall installation finished.
    cp lib/IPC/Messaging.pm blib/lib/IPC/Messaging.pm
    Manifying blib/man3/IPC::Messaging.3pm
    Installing /usr/local/share/perl/5.10.0/IPC/Messaging.pm
    Installing /usr/local/man/man3/IPC::Messaging.3pm
    Writing /usr/local/lib/perl/5.10.0/auto/IPC/Messaging/.packlist
    Appending installation info to /usr/local/lib/perl/5.10.0/perllocal.pod
    :~/devel/IPC-Message-Minivan-0.01_08$ perl Makefile.PL
    Cannot determine license info from lib/IPC/Message/Minivan.pm
    Writing Makefile for IPC::Message::Minivan
    :~/devel/IPC-Message-Minivan-0.01_08$ sudo make install
    cp lib/IPC/Message/Minivan.pm blib/lib/IPC/Message/Minivan.pm
    cp minivan blib/script/minivan
    /usr/bin/perl "-Iinc" "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/minivan
    Manifying blib/man1/minivan.1p
    Manifying blib/man3/IPC::Message::Minivan.3pm
    Installing /usr/local/share/perl/5.10.0/IPC/Message/Minivan.pm
    Installing /usr/local/man/man1/minivan.1p
    Installing /usr/local/man/man3/IPC::Message::Minivan.3pm
    Installing /usr/local/bin/minivan
    Writing /usr/local/lib/perl/5.10.0/auto/IPC/Message/Minivan/.packlist
    Appending installation info to /usr/local/lib/perl/5.10.0/perllocal.pod
  4. Create an Upstart script for the Minivan daemon
    $ cat /etc/init/minivan.conf
    # minivan - minimalistic message bus
    #

    description     "minimalistic message bus"

    start on runlevel [2345]
    stop on runlevel [!2345]

    expect fork
    respawn

    exec /usr/local/bin/minivan -l /var/log/minivan -d
  5. Start the Minivan daemon
    $ sudo start minivan

Install the Irssi script

  1. Copy the script to ~/.irssi/scripts/notifier-minivan.pl (the script below is just for reference, it might not be up to date)
    ## Put me in ~/.irssi/scripts, and then execute the following in irssi:
    ##
    ##       /load perl
    ##       /script load notifier-minivan
    ##

    use strict;
    use Irssi;
    use vars qw($VERSION %IRSSI);
    use HTML::Entities;
    use IPC::Message::Minivan;

    $VERSION = "0.01";
    %IRSSI = (
        authors     => 'Allan Willems Joergensen',
        origauthors => 'Luke Macken, Paul W. Frields, Jared Quinn, Anton Berezin, Kristoffer Larsen',
        contact     => 'allan@nowhere,dk',
        name        => 'notifier-minivan.pl',
        description => 'Alert the user of new messages or hilights through IPC::Message::Minivan',
        license     => 'Beerware',
        url         => 'http://www.nowhere.dk/articles/irssi-notifications-minivan',
    );

    # Default settings in Irssi
    Irssi::settings_add_str('notifier','minivan_host', 'localhost');
    Irssi::settings_add_str('notifier','minivan_port', 6826);
    Irssi::settings_add_str('notifier','minivan_channel','#irssi');

    # Fetch settings from Irssi
    my $minivan_host = Irssi::settings_get_str('minivan_host');
    my $minivan_port = Irssi::settings_get_str('minivan_port');
    my $minivan_channel = Irssi::settings_get_str('minivan_channel');

    # Connect to the Minivan
    our $van = IPC::Message::Minivan->new(host => $minivan_host, port => $minivan_port);

    sub notify {
        my ($server, $summary, $message) = @_;

        # Encode certain characters using HTML
        my $safemsg = HTML::Entities::encode($message, '<>&"');

        # Load everyone into the minivan
        $van->msg($minivan_channel, {summary => $summary, msg => $safemsg});
    }

    sub print_text_notify {
        my ($dest, $text, $stripped) = @_;
        my $server = $dest->{server};
        return if (!$server || !($dest->{level} & MSGLEVEL_HILIGHT));
        my $sender = $stripped;
        $sender =~ s/^\<.([^\>]+)\>.+/\1/ ;
        $stripped =~ s/^\<.[^\>]+\>.// ;
        my $summary = "Hilite in " . $dest->{target};
        notify($server, $summary, $stripped);
    }


    sub message_private_notify {
        my ($server, $msg, $nick, $address) = @_;
        return if (!$server);
        notify($server, "Private message from ".$nick, $msg);
    }

    sub dcc_request_notify {
        my ($dcc, $sendaddr) = @_;
        my $server = $dcc->{server};

        return if (!$dcc);
        notify($server, "DCC ".$dcc->{type}." request", $dcc->{nick});
    }

    Irssi::signal_add('print text', 'print_text_notify');
    Irssi::signal_add('message private', 'message_private_notify');
    Irssi::signal_add('dcc request', 'dcc_request_notify');
  2. Load the script inside Irssi: /script load notifier-minivan.pl
  3. If your Minivan is not running on the same machine as Irssi, change the configuration inside Irssi:
    /set minivan_host your_hostname – IPC::Message::Minivan is tunnel-able through ssh, see client configuration
  4. Auto-load the script:
    ln -sf ~/.irssi/scripts/notifier-minivan.pl ~/.irssi/scripts/autoload/notifier-minivan.pl

The stuff running on your local machine

It is possible to use autossh to automatically setup the tunnel but since I am always connected to my server (at least when I am in front of a computer) I chose to use normal ssh port forwarding.

In ~/.ssh/config I have

Host my.server.bogus
        LocalForward 6826 localhost:6826

The stuff that actually shows the notifications

I did not want to bother trying to make the script error proof so I simply call the Perl script from a shell script like so

#!/bin/bash

wait=0
while true
 do
    $HOME/bin/irssi-notify-client.pl

    let wait=$wait+5
    if [ $wait -ge 30 ]
     then
        sleep 30
    else
        sleep $wait
    fi
done

Save the script as ~/bin/start-irssi-notify-client.sh

The notification script requires Desktop::Notify – It is available in the Ubuntu repositories but it is an old version, so let’s use a newer:

$ sudo apt-get install dh-make-perl libnet-dbus-perl
$ cpan2deb Desktop::Notify
$ sudo dpkg -i ~/.cpan/libdesktop-notify-perl*.deb

The script

#!/usr/bin/perl

use strict;
use warnings;
use Desktop::Notify;
use IPC::Message::Minivan;
use Encode;

my $notify_timeout = 500;
my $icon = "/usr/share/pixmaps/pidgin/protocols/scalable/irc.svg";
#my $icon = "gnome-irc.png";

my $van = IPC::Message::Minivan->new(host => 'localhost');
$van->subscribe("#irssi");
our $notify = Desktop::Notify->new();
my $notification = $notify->create(summary => 'Minivan', body => 'Connection established', timeout => $notify_timeout, app_icon => $icon);
$notification->show();

while (1) {
    if (my $cmd = $van->get(5,[])) {
        if ($cmd->[0] eq '#irssi') {
            my $c=$cmd->[1];
           
            my $message = Encode::encode("utf-8",$c->{msg});
            my $summary = $c->{summary};
           
            $notification->summary($summary);
            $notification->body($message);
            $notification->show();
        }
    }
}

$notification->close();

Copy the script to ~/bin/irssi-notify-client.pl.

Remember to make both scripts executable.

The final thing to do is to add the notify client to your desktop environment’s autostart

In GNOME: System -> Preferences -> Startup Applications

Add Startup Program

Add Startup Program

Facebook Chat in bitlbee

Facebook now supports XMPP. Yay.

Using Facebook Chat in bitlbee is pretty straight forward (I am running 1.2.4, older versions of bitlbee require a bit more tweaking, consult the manual).

For Facebook Chat through XMPP to work you need to set a Facebook username.

In the &bitlbee channel

account add jabber <username>@chat.facebook.com> <Facebook password>
account on

that’s it.

Facebook users are listed by their Facebook user id (uXXXXXXX) so you have to rename them manually, unless you are using irssi.

Download this script to ~/.irssi/scripts and load it

/script load bitlbee_rename

(Note: This script only renames your Facebook contacts – The original version which renames all contact but does not handle international characters really well is available here)

Now each of your contacts will be renamed based on their real name in their vCard.

Remember to symlink to script to ~/.irssi/scripts/autorun if you wish to auto-load it.

Yet another way to get Irssi notifications on your Linux desktop

For a better solution, see this article – I am keeping this post online because it makes it possible to implement distributed notifications with Perl modules included in the Ubuntu repositories.

One of the things lacking (in my opinion at least) when using Irssi and GNU Screen is the lack of a way for Irssi to alert you when you are not looking at the terminal.

I have looked at many implementations for libnotify (default in Ubuntu), Mumbles (Growl for Linux) and Dzen.

Some of the things I have looked at

  • thl’s irssi notification script aka fnotify
    Most of this is actually quite good and has formed the basis for my implemenation. Uses libnotify.
  • Using irssi with libnotify over Secure Shell
    A different implementation of the above, using xterm’s print facility to send data to libnotify.
  • irssi-libnotify
    Uses notify-send on the same machine as irssi, requires X-forwarding (which is a bitch with screen). I liked this but as it uses X-Windows on the remote server the notifications might not match those of your desktop
  • Dzen notifications
    This is where I got the idea for using a named pipe
  • Mumbles
    I used this before libnotify became standard in Ubuntu. It was hard to make it work and required several (Python) daemon running to forward the notifications.

Since I have several machines I use to access my server where Irssi is running none of the other implementations I looked at really worked since I need to be sure that all machines get the notifications. In the end I decided to use MySQL as a “proxy” for the notifications.

Prepare the MySQL database

It’s a good idea to set up a separate database – just in case one of the scripts f*ck up and deletes everything.

$ sudo mysqladmin -u root -p create irssi
mysql> use irssi
Database changed
mysql> CREATE TABLE `notify` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `summary` varchar(64) CHARACTER SET utf8 NOT NULL,
  `message` varchar(255) CHARACTER SET utf8 NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM;
mysql> GRANT ALL ON irssi.* TO 'irssi'@'localhost' IDENTIFIED BY 'Password';

Installing the Irssi script

It is also possible to simply create a table inside an existing database; just adjust the configuration values in Irssi.

The Irssi script is based on Jared Quins work (which in turn is based on irssi-libnotify). The basic idea is the same as with fnotify but instead of writing to a temporary file I write to a MySQL database.

## Put me in ~/.irssi/scripts, and then execute the following in irssi:
##
##       /load perl
##       /script load notify
##

use strict;
use Irssi;
use vars qw($VERSION %IRSSI);
use HTML::Entities;
use DBI;
use utf8;

$VERSION = "0.01";
%IRSSI = (
    authors     => 'Allan Willems Joergensen',
    origauthors => 'Luke Macken, Paul W. Frields, Jared Quinn',
    contact     => 'allan@nowhere,dk',
    name        => 'notifier.pl',
    description => 'Use libnotify to alert the user of new messages or hilights (Using MySQL as "proxy")',
    license     => 'GNU General Public License',
    url         => 'http://www.nowhere.dk/articles/irssi-notification',
);

Irssi::settings_add_str('notifier','notifier_mysql_user', 'irssi');
Irssi::settings_add_str('notifier','notifier_mysql_password', 'changeme');
Irssi::settings_add_str('notifier','notifier_mysql_host', 'localhost');
Irssi::settings_add_str('notifier','notifier_mysql_db', 'irssi');

sub write2db {
        my $db_user = Irssi::settings_get_str('notifier_mysql_user');
        my $db_pass = Irssi::settings_get_str('notifier_mysql_password');
        my $db_host= Irssi::settings_get_str('notifier_mysql_host');
        my $db_name = Irssi::settings_get_str('notifier_mysql_db');
        my ($summary, $message) = @_;
        my $dsn = "dbi:mysql:dbname=$db_name;host=$db_host";
        my $dbh = DBI->connect($dsn, $db_user, $db_pass) || die "DB connect failed";

        my $sth = $dbh->prepare("INSERT INTO notify (summary, message) VALUES (?, ?)")
            or die "Can't prepare statement: $?";
        $sth->execute($summary, $message) or die "Couldn't execute INSERT: $?";

        $dbh->disconnect;
}


sub notify {
    my ($server, $summary, $message) = @_;
    my $safemsg = HTML::Entities::encode($message, '<>&"');
    my $utf8msg = utf8::encode($safemsg);

    write2db($summary, $safemsg);
}

sub print_text_notify {
    my ($dest, $text, $stripped) = @_;
    my $server = $dest->{server};
    return if (!$server || !($dest->{level} & MSGLEVEL_HILIGHT));
    my $sender = $stripped;
    $sender =~ s/^\<.([^\>]+)\>.+/\1/ ;
    $stripped =~ s/^\<.[^\>]+\>.// ;
    my $summary = "Hilite in " . $dest->{target};
    notify($server, $summary, $stripped);
}


sub message_private_notify {
    my ($server, $msg, $nick, $address) = @_;
    return if (!$server);
    notify($server, "Private message from ".$nick, $msg);
}

sub dcc_request_notify {
    my ($dcc, $sendaddr) = @_;
    my $server = $dcc->{server};

    return if (!$dcc);
    notify($server, "DCC ".$dcc->{type}." request", $dcc->{nick});
}

Irssi::signal_add('print text', 'print_text_notify');
Irssi::signal_add('message private', 'message_private_notify');
Irssi::signal_add('dcc request', 'dcc_request_notify');

Download the script to ~/.irssi/scripts and rename it to notifier.pl.

If you want it to load automatically, symlink it to ~/.irssi/scripts/autorun
$ ln -sf ~/.irssi/scripts/notifier.pl ~/.irssi/scripts/autorun/notifier.pl

Load the script inside irssi
/script load notifier.

Once you have loaded the script, set these variables inside Irssi (adjust according to your setup)

/set notifier_mysql_db irssi
/set notifier_mysql_host localhost
/set notifier_mysql_user irssi
/set notifier_mysql_password Password

Setup MySQL port forwarding

It is possible to use autossh to automatically setup the tunnel but since I am always connected to my server (at least when I am in front of a computer) I chose to use normal ssh port forwarding.

In ~/.ssh/config I have

Host my.server.bogus
        LocalForward 13306 localhost:3306

The stuff running on your local machine

That is, the stuff that actually shows the notifications

I did not want to bother trying to make the MySQL-stuff error proof so I simply call the Perl script from a shell script like so

#!/bin/bash

wait=0
while true
 do
    $HOME/bin/irssi-notify-client.pl

    let wait=$wait+5
    if [ $wait -ge 30 ]
     then
        sleep 30
    else
        sleep $wait
    fi
done

Save the script as ~/bin/start-irssi-notify-client.sh

The Perl script requires DBI and Desktop::Notify – Both are available in Ubuntu

$ sudo install libdesktop-notify-perl libdbd-mysql-perl
#!/usr/bin/perl

use strict;
use warnings;
use DBI;
use Desktop::Notify;

my $last = 0;
my $loops = 0;
my $notify_timeout = 2000;
my $icon = "gnome-irc.png";

sub mysql_connect {
    my $db_user = "irssi";
    my $db_pass = "Password";
    my $db_host = "127.0.0.1:13306";
    my $db_name = "irssi";
    my $dsn = "dbi:mysql:dbname=$db_name;host=$db_host";
    my $dbh = DBI->connect($dsn, $db_user, $db_pass) or die "DB connect failed";

    return($dbh);
}

while (1) {
    my $dbh = mysql_connect();

    if ($last == 0) {
        my $sth_state = $dbh->prepare("SELECT MAX(id) FROM notify");
        $sth_state->execute() or die "Unable execute query: $dbh->err, $dbh->errstr\n";
        $last = ($sth_state->fetchrow_array)[0];
        $sth_state->finish();
    }

    my $sth = $dbh->prepare("SELECT id,time,summary,message FROM notify WHERE id > ? ORDER BY id ASC LIMIT 0,10");
    $sth->execute($last) or die "Unable execute query:$dbh->err, $dbh->errstr\n";

    if ($sth->rows > 0) {
        my $notify = Desktop::Notify->new();
        my $notification = $notify->create(timeout => $notify_timeout, app_icon => $icon);
        while (my $ref = $sth->fetchrow_hashref()) {
       
            my $id = $ref->{'id'};
            my $summary = $ref->{'summary'};
            my $message = $ref->{'message'};
           
            $notification->summary($summary);
            $notification->body($message);
            $notification->show();

            $last = $id;
            sleep 1;

        }
        $notification->close();
    }

    $sth->finish();
   
    # Clean up once in a while. This is not really essential so we simply
    # do it once every 1000 iterations
    $loops++;
    if ($loops > 1000) {
        my $sth_cleanup = $dbh->prepare("DELETE FROM notify WHERE id < ?");
        $sth_cleanup->execute($last);
        $sth_cleanup->finish();
    }

    $dbh->disconnect;

    sleep 5;
}

Save the script to ~/bin/irssi-notify-client.pl.

Remember to make both scripts executable.

The final thing to do is to add the notify client to your desktop environment’s autostart

In GNOME: System -> Preferences -> Startup Applications

Add Startup Program

Add Startup Program