Rebuilding Debian Packages - Debian Delvings
Ever wanted a Debian package to be just a -little- bit different? Here’s how.
While most of the software we’re pulling in from Debian is fine for our uses there are a couple of applications that we’d like to be a little different than the stock versions. Rather than go away and package them ourselves (which would require a lot more packing skills and time than I currently have - improving those skills is one of the reasons I’m doing this series) it’s possible to download a source version of a Debian package, make a small amendment and then repackage it for personal use. In this example we’ll have a look at how to do this with NginX, a very fast and stripped down webserver I’m evaluating for a couple of services.
Firstly let’s be nosey and have a look at the Nginx source package.
Assuming you have a deb-src line in your
/etc/apt/sources.list file getting a copy of the source
package is as simple as
apt-get source nginx; it’s worth
noting that this command doesn’t need you to be root to run. While we’re
here let’s pull down the dependencies required to rebuild nginx once
we’ve made our modifications -
sudo apt-get build-dep nginx
- note the build-dep argument - and then pull down the other packages
required but are not specific to this package.
sudo apt-get install
build-essential devscripts fakeroot (sudo or as root).
It’s a bit of a tangent (and an annoyance) but the package of Nginx in Debian stable (nginx 0.4.13-2) has a Nginx package removal bug that stops you from removing the package without hacking the init script. I only point this out as when I was trying to learn how to repackage I couldn’t remove it and so assumed I’d broken something.
Before we make any amendments to the package let’s try and rebuild
it. cd in to the versioned source directory (nginx-0.4.13 in our
example) and run
debuild -us -uc. A few screens of text
later and we’ve got a package - ../nginx_0.4.13-2_i386.deb.
Now we know we can round trip let’s be intrusive and make some amendments to the package. We’ll add an optional module (http_realip_module) to the nginx package (you should be able to do something like this to add SSL support for example. In this case it’s a small, one line, change -
$ cd nginx-0.4.13 # this is the etch version when I wrote this $ vi debian/rules # add '--with-http_realip_module' to the ./configure line. $ dch --nmu "Rebuild of package and addition of the http_realip_module module" $ vi debian/changelog # change the name and email as required. # build the new package with the extra module $ DEBFULLNAME="Dean Wilson" DEBEMAILemail@example.com debuild -us -uc $ ls -alh ../nginx_0.4.13-2.1_i386.deb # if you have a repo drop it in now and regenerate the index for clients to see it.
dch simplifies adding changelog entries to
debian/changelog. The two variables before the command tell it who’s
made the change. In our case we’re logging that we added the new
module and that this package is a “Non maintainer upload” (NMU). This
is important for future users of the package - in essence we’re
taking responsibility for the repack away from the oringinal
maintainer, who knows nothing of the changes you’ve made, and making
ourselves the correct contact point. And if you don’t do this lintian
will complain when you build the package.
Closing notes - you may need to pin or hold the package to stop it getting overwritten when future (maintainer) upgrades become available - but that’s outside the scope of this post.
Bonus Debian Nginx package Evil. Bad idea but useful for some testing I was doing.