Building deb files with fpm and vagrant

At $WORK I need to package stuff up. Most of the time, I've worked with RPMs. Those are easy; it took, I dunno, an hour? to come up with my first spec file, and it's been pretty simple after that -- even with oddball software that uses "make configure" to mean "make build" and "make" to actually install it. But deb files...man, these are hard. There is a lot more policy built into making a deb file than there ever was in an RPM, and you overlook/override/ignore it at your peril. I want to do the right thing -- which means, since I'm stubborn and have thought idly about becoming a Debian developer someday, I bang my head against the deb files until it works. Except, that as Jordan Sissel has so rightly pointed out, sometimes I just don't have time.

So Jordan Sissel, being Jordan Sissel, has put together fpm, the Effing Package Management. And it's awesome: take your source files, point fpm at them, and you get rpms AND debs. But I want more: the pbuilder system is truly awesome in its you're-gonna-compile-on-an-empty-chroot-or-you're-borked brutish stubbornness, and I want that for fpm. So I'm using vagrant for this. My approach is not as nice as debuild or pbuilder, but it is so far working for me.

It's actually pretty trivial; I'm mainly putting it up here so that I remember it. Hopefully it's useful to someone else, too.

The heart is a dirt-simple shell script; here's what I've got for vmd:

#!/bin/bash

# Bail on error; want this to be as hands-off as possible
set -e

# Add build-essential
sudo apt-get update
sudo apt-get install -y build-essential
# Install fpm.  FIXME: That check is borken; not sure about using vagrant_ruby to install it.
which fpm || sudo /opt/vagrant_ruby/bin/gem install fpm

# Where to look for stuff
ORIGIN=/vagrant
INSTALLROOT=/opt
BUILDDIR=/tmp/vmd
TARBALL=vmd-1.9.1.bin.LINUXAMD64.opengl.tar.gz
BUILDDEPS=
# FIXME: gotta put in all the "--depends" by hand.
DEPS="--depends libgl1-mesa-dev --depends libglu1-mesa --depends libxinerama1 --depends libxi6"

[ -d $BUILDDIR ] || mkdir $BUILDDIR
cd $BUILDDIR
tar xvzf ${ORIGIN}/$TARBALL
cd vmd-1.9.1
export VMDINSTALLBINDIR=${INSTALLROOT}/bin
export VMDINSTALLLIBRARYDIR=${INSTALLROOT}/vmd
./configure
sudo make -C src install

# And here's the fpm magic.  FIXME: Note the stupid assumptions about opt.
/opt/vagrant_ruby/bin/fpm -s dir -t deb -n vmd -v 1.9.1 -f $DEPS -p ${ORIGIN}/vmd-VERSION_ARCH.deb -x opt/vagrant_ruby -x opt/VBoxGuestAdditions* -C / opt

Drop this in a directory along with the vmd tarball:

-rwxr-xr-x 1 hugh hugh     1153 Sep 12 14:40 build_vmd.sh
-rw-r--r-- 1 hugh hugh 22916955 Sep 12 10:05 vmd-1.9.1.bin.LINUXAMD64.opengl.tar.gz

Vagrant up, then build:

$ vagrant init precise64    # That's Ubuntu 12.04, yo.
$ vagrant up
$ vagrant ssh -- /vagrant/build_vmd.sh

If all goes well, you now have a deb in that directory:

$ ls -l *deb
-rw-rw-r-- 1 hugh hugh 22396738 Sep 12 14:41 vmd-1.9.1_amd64.deb

Like I say, it's dirt-simple -- but it does make stuff a lot easier. Thanks, Mitchell and Jordan!