Friday, August 19, 2011

Patching and rebuilding debian packages

So i've been doing some bug fixes for packages in the linux mint debian edition and its been alot of fun. However, since they have kind of a small team and it takes awhile for patches to hit the distro, i thought it might be fun and helpful to roll my own .deb packages for people to "try at your own risk" until official packages are released.

So, for my own point of reference and as a quick reference to anyone who cares, here's a simple tutorial. You'll need normal debian buildtools and something called quilt that helps manage patches. Lets assume you've fixed your bug and made a diff against the original file and all that good stuff. I keep directories like so to keep track of what i'm working on, so you'll see them referenced:

~/bin (for binaries or ready-to-use scripts)
~/src (for debian source packages and in progress scripts)
~/diffs (for patches)

normally to get a debian source package, you would run something like:

voytek@voytek ~/src $ apt-get source package-name

in whatever directory you want to have the new source directory created. I'm working on the mintBackup tool which they don't have a debian source package for in the repos, so I'm pulling it directly from git:

voytek@voytek ~/src $ git clone git://github.com/linuxmint/mintbackup.git


Simple procedures for working with quilt come from this tutorial, however before you start using quilt for debian packages, you'll want to make sure you have a ~/.quiltrc file that at least has this line:

QUILT_PATCHES=debian/patches

This makes sure you're putting the patches where debian expects them. The tutorial tells us:

"quilt works in the source tree. There's no copying large trees around. There's also no need to always keep the source tree clean of unapplied changes just to be able to extract a diff with SVN.

To achieve this, however, quilt needs to know which files are contained in each patch. The workflow is as follows:

  1. you tell quilt that you start working on a given patch
  2. you work on that patch
  3. you tell quilt that you're done"
So I move into the mintbackup src directory and I run:

voytek@voytek ~/src/mintbackup $ quilt new python-apt-api-changes.patch

You can name the patch anything you want, but I'm choosing to name mine descriptively. Next you would want to edit and/or patch the file, but first you have to tell quilt what file you're editing. To do this, you just run:

voytek@voytek ~/src/mintbackup $ quilt edit usr/lib/linuxmint/mintBackup/mintBackup.py

Now, this will open the file you've specified in whatever you have set as your $EDITOR. You could make your changes here, but I like to be organized and I tend to make mistakes when I don't have a way to test things nicely, so I'm going to use the patch I already made. So, I close my editor and quilt responds with:

File usr/lib/linuxmint/mintBackup/mintBackup.py added to patch python-apt-api-changes.patch

Good times!

The patch I'm using was originally created from my copy of the modified script in ~/bin applied to the unmodified version on my system, like so:

voytek@voytek ~ $ diff /usr/lib/linuxmint/mintBackup/mintBackup.py bin/mintBackup.py > diffs/mintBackup.py.diff

And to apply it, I will simply run:

voytek@voytek ~/src/mintbackup $ patch usr/lib/linuxmint/mintBackup/mintBackup.py ~/diffs/mintBackup.py.diff

Now we have to tell quilt that we're finished, which will output the following (cmd included):

voytek@voytek ~/src/mintbackup $ quilt refresh python-apt-api-changes.patch
Refreshed patch python-apt-api-changes.patch

Great, so our modified source is ready to be built into a package! This can be done from the root of the source tree by running:

voytek@voytek ~/src/mintbackup $ debuild -us -uc

Assuming we did everything correctly, this should create .deb packages for our modified sources in the parent directory. Thankfully, since the package I'm working on today doesn't have any compiled binaries, I also get a mintbackup_2.0.8_all.deb package which can install on any architecture.

No comments:

Post a Comment