2 min read, 400 words

Once again fucked by the intricacies of Debian packaging

Every couple of weeks I find myself having to modify a deb package, but can never remember the exact incantations required to correctly do everything. This post is mostly for my own information, since I have to spend a couple hours looking through the Debian documentation every time.

  1. Create some directories to hold your working files
$ mkdir gunicorn
$ cd gunicorn
  1. Download the package you want to modify.
$ apt-get download gunicorn=15.7
Get:1 Downloading gunicorn 17.5 [142 kB]
Fetched 1 B in 0s (5 B/s) 
$ ls
  1. Extract the entire package in your new working directory to a sub-directory raw:
$ dpkg-deb -R gunicorn_17.5-2build1_all.deb raw
  1. Make any changes you need, the control files will be in raw/DEBIAN and the rest of the package contents in raw. In this case, I was modifying the init.d script, so I made my changes to raw/etc/init.d/gunicorn and saved the file. Make sure to increment the build number of the version in DEBIAN/control, in this case I changed 17.5-2build1 to 17.5-2build2, to ensure that the new package will be installed over the original.

  2. For completeness, next we re-generate the md5sums for the package, in-case anyone verifies them in the future (apt/apt-get/dpkg do not by default)

$ cd raw
$ md5sum $(find . -type f | grep -v '^[.]/DEBIAN/') >DEBIAN/md5sums

This command will find any files in raw that are not within the DEBIAN directory (We only care about files that will be installed) and outputs their md5 hash to the md5sum control file.

  1. Finally, rebuild the package:
$ dpkg-deb -b raw gunicorn_17.5-2build2_all.deb

I have appended a custom Debian version to the package, to differentiate the new package from the old, without iterating the semver version of the upstream package.

Last steps will be to either install the package by hand using dpkg -i gunicorn_17.5-2build2_all.deb or upload it to your local apt repository. This package is not signed, so apt may complain when installing it, depending on your configuration.

First real adventures with Terraform Packaging Nightmares

comments powered by Disqus