Ubuntu – The correct way to create your own packages for local installation

aptpackage-managementpackaging

I am running an Ubuntu 12.04 LTS server. I currently have an issue where one of my used packages has an annoying bug. Instead of removing it and just building it from source, I want to integrate it into Ubuntus/Debians package management.

Coming from ArchLinux we did this by copying the original PKGBUILD and changing it in such a way that it compiles the new package. This is a very simple process but it informs the package manager about this package even though it is in no local repositories.

Is there a similar way for Ubuntu/Debian? Can I easily base my package on the outdated Ubuntu version and install this package instead of the original repository one?

Note: The concerning software is libvirt (I need 0.9.13 at least, 12.04 runs 0.9.8) and while I would appreciate a solution for this particular package in the comments, I am looking for a more general solution for such problems should they arise in the future.

Contrary to questions How can I manually assemble my own package “the hard way”? and What is the simplest Debian Packaging Guide? I am not interested in creating a new package but instead using existing resources and update them to a newer version.

Best Answer

I would download the source and the build dependencies for the Ubuntu version first:

apt-get install dpkg-dev
apt-get build-dep <package>
apt-get source <package>

The unmodified, upstream source the Ubuntu version is based on will be in a file called <pkg>_<ver>.orig.tar.gz (compression scheme may vary) - I would decompress this to one directory (let's call it "dir A"), then download the source to the bug-fixed version into another directory ("dir B"), and then generate a patch for what's changed:

diff -Nur <dirA> <dirB> >/tmp/upgrade.patch

Then change to the directory where apt-get source decompressed the modified Ubuntu version, and apply the patch

patch -p1 </tmp/upgrade.patch

Assuming there weren't many changes between the two upstream versions, and they didn't conflict with any of the Ubuntu packager's changes, this should work. Then edit debian/changelog in the Ubuntu package to give it a new version number, and dpkg-buildpackage should build you a custom version..