Backporting new code to Debian packages

I like Linux distros packaging systems, especially Debian’s. It makes it trivial to install, remove and change to different versions of programs. The only problem is that sometimes there is a delay in packaging the latest version of an app.

Never fear though, if you are willing to do a little bit of work you can shoehorn the latest code into a package yourself without needing any special knowledge of how to create packages. Note this will only work with programs that already have been packaged since it re-uses the old packaging info with the new code.

I refer to Debian, but the exact same procedure will work on any deb based distro, such as Ubuntu.

Before starting make sure you have the devscripts and build-essential packages installed. These will install all the tools needed to build debian packages.

First download the source package of the old version.

apt-get source $NAME

Then, as a sanity check cd into the created directory and run

debuild -i -us -uc

This will probably complain about missing packages needed for building, so go ahead and install them with apt-get or aptitude or whatever. Then re-run the build command. Assuming that works you should end up with some .deb files in the parent dir.

Now grab the code for the latest version from its website. If it is not already in a tarball you’ll want to make one from it with

tar czf application_version-1.orig.tar.gz applicationdir

If it is a tarball already then just rename it to match the formatting application_version-1.orig.tar.gz. For example when backporting mesa I name the tarball mesa_7.7.0-1.orig.tar.gz.

Next copy the debian dir from the old application directory to the new one.

cp -a application-debianversion/debian application-newversion/

Then cd into the new directory and run

debchange -v version-1 "Updated code to latest version"

It is vital that the version number used in this command matches the naming of the .orig.tar.gz file you created earlier. For example for mesa I use 7.7.0-1. This is the magic that will make everything work.

The final step is to build the new package.

debuild -i -us -uc

and tada! With a bit of luck your shiny new version should be packaged up and ready to be installed.