Author Archives: Rcart

Packaging apport hooks


Apport is the software that handles bug crashes in Ubuntu. Whenever you want to report a bug in Ubuntu, apport collects data about that package, attach it to the bug report and send it to Launchpad.

Hooks are scripts written in python that help apport to collect specific data about a package. In this post, I’ll show how to write one, specifically an apport hook for the MPD package which includes the user configuration file. There are some links that you have to read to get a better understanding of what hooks are, and how to write them, those links will be at the end of this post.

If you want to write a hook for a package that doesn’t have a hook but need it, then you can report a bug similar to this one:

First off, we need to get the source of the package:

bzr branch ubuntu:mpd ; bzr branch mpd fix-missing-hook ; cd fix-missing-hook

And we’re ready to start. In this example, th eMPD user configuration file is stored at ~/.mpdconf. Everytime we write a hook, we *must* ensure that we keep the user data safe. That means that if the configuration file contains passwords, they *must* kept away from the public. Fortunately for this example I found a snippet that replaces passwords strings in files (link at the end). I just had to modified it to fit my needs and add some little things to it. Here’s the apport hook to include MPD user configuration file:

apport package hook for Music Player Deamon

Author: Ronny Cardona

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version. See for
the full text of the license.

from apport.hookutils import *
import os

# Reference for this function:
def _my_files(report, filename, keyname):
if not (os.path.exists(filename)):
key = keyname
report[key] = “”
for line in read_file(filename).split(‘\n’):
if ‘password’ in line.split(‘”‘)[0]:
line = “%s \”@@APPORTREPLACED@@\” ” % (line.split(‘”‘)[0])
report[key] += line + ‘\n’
except IndexError:

def add_info(report):
_my_files(report, os.path.expanduser(‘~/.mpdconf’), ‘UserMpdConf’)

As you can see, the script was initially released under GPL3+, BUT! MPD uses GPL2+ which means that it’s incompatible with the software license. The best solution is to always release the hooks under the same licence as the software the hook was written for, in this example GPL2+.

After the script is ready and copied to /usr/share/apport/package-hooks it *must* be tested to check that it works like expected:

ubuntu-bug mpd

This will call apport which will call then the hooks for the specific package, if you can see in attached files the user configuration file (or whatever file you wanted to include), then the script works like it should do.

So, the script is ready and working, just left to package it. Here comes the interesting part. Apport hooks *must* be included in the debian/ directory, named That means that MPD hook must be named as and then put it inside the debian/ directory.

Now, we can edit mpd.install file to point out where our script will be allocated after installation. That destination is at /usr/share/apport/package-hooks/. So, we append a line like this one:

debian/ usr/share/apport/package-hooks

That is all we need to do when writing a simple apport hook. We haven’t change code outside debian/ dir, so we’re ready to write the changelog entry:

dch -i

And here we can specify our changes:

mpd (0.16.5-1ubuntu4) precise; urgency=low

* debian/
– Added apport hook to include user configuration file. (LP: #947551)

– Ronny Cardona Wed, 07 Mar 2012 18:03:12 -0600

Then, commit the change:

bzr commit

And build the package:

bzr builddeb -S
pbuilder-dist precise build ../*.dsc

We install the package and test it. And check the hook destination directory to verify that it was installed in it’s respective directory. We also verify (one more time) if the hook is called when apport is launched =)

Push the branch to LP:

bzr push lp:~rcart/ubuntu/precise/mpd/fix-947551
bzr lp-open

Then propose for merge

That’s all.


pbuilder: Building i386 packages on x64 hosts


A wonderful thing when creating packages with pbuilder would be to have the freedom to build packages for i386 archs on x64 hosts. Well, thats easy using recent versions of pbuilder (I don’t know since when this is possible). The first step is to have those architectures created with pbuilder previously. let’s do it:

pbuilder-dist precise i386 create

When it’s done, create the x64 sistem base (since I’ve a x64 machine, isn’t necessary to specify the architecture to pbuilder, ’cause this creates a system base according to the host arch):

pbuilder-dist precise create

So, when we want to build a package for i386, just do:

pbuilder-dist precise i386 *.dsc

For x64 packages we do it as for any package:

pbuilder-dist precise *.dsc

This is because we have a x64 host, and pbuilder with no arch specified, will build packages for the host’s arch. A really nice tip.

[Pdf] An introduction to Debian packaging


This is really good text that focus in the basics of packaging for Debian (also applies to Ubuntu). I really would recommend it to get an overview of the process.

Like the author says:

About this tutorial
Goal: tell you what you really need to know about Debian packaging
Tries to keep a reasonable size
No attempt to be complete
You might need to read more documentation

Download at: