cheatsheet.zwischenspeicher.info

Some tech documentation and snippets, finally organized.

Hotfixing a Debian package

How to patch and compile a Debian package from its source and avoid future re-installation of the unpatched version by creating a local version number. Example: claws-mail.

Note: Source repositories need to be enabled in the sources.list.

Become root and install the needed software:

$ sudo su
$ apt-get install build-essential apt-src devscripts patch

Create a working directory, here /usr/src/claws-mail and enter it:

$ mkdir /usr/src/claws-mail
$ cd /usr/src/claws-mail

apt-src will download and install the Debian source package itsself as well as all needed development files and tools:

$ apt-src install claws-mail

Enter the source tree, apply the patch (or edit source manually) and use debchange from the "devscripts" package to create a local version number with suffix "local". It is possible to append a short decripive text directly to the debchange command, which will be added to the packages changelog:

$ cd claws-mail-VERSION
$ patch SOURCEFILE DIFF
$ debchange --local local PATCH_DESCRIPTION...

If no changelog text is given, an editor will open the changelog. (Edit, save and) close the file to continue. Now leave the source tree and compile the package:

$ cd ..
$ apt-src -p build claws-mail

This will take a while. When back at the command prompt, the newly built Debian package(s) can be found in the "top level" working directory, ready to install.

$ cd ..
$ dpkg -i ALLTHEDEBS

Finally clean the leftovers of the build process from the source tree:

$ apt-src clean claws-mail

Note: The next official update of the package will automatically overwrite this local version. In case the update does not contain the locally applied patch, update the apt package index and run apt-src again. It will try to bring the patch forward:

$ apt-get update
$ cd /usr/src/claws-mail
$ apt-src -b upgrade claws-mail
$ cd .. && dpkg -i ALLTHEDEBS

If you want to install all of the built packages (or there is only one package going to be built), it is sufficient to run

$ apt-src -i install claws-mail

This will update, patch and compile the sources and finally install the newly built package(s) in one go.