trivial .deb packaging

There are certain situations where one might want to generate a quick .deb package that just installs things onto the target system without doing anything fancy, like compiling source files.

The classic example is if you are in charge of delivering software to a group of machines, but do not have source code to the software. Maybe you just have a pre-compiled library you want installed somewhere.

You could ask your users to:

$ sudo cp mylib.so /usr/lib

But then what if you need to update mylib.so somehow? I can see the nightmare a-comin’ from all the way over here.

So then you think to yourself, gee, I have a very nice package management system; why don’t I use it? Which means, you’re going to try and teach yourself the bare minimum debian packaging skills needed to do such a thing, to which I say, good luck.

Perhaps there are easy examples out there [and if so, let me know and I'll update this post]; in the meantime, this is the bare minimum that I could come up with.

Hope it helps.

The directory layout follows:

achiang@aspen:~/Projects/example$ ls -RF
.:
debian/  usr/

./debian:
changelog  compat  control*  copyright  install  rules*  source/

./debian/source:
format

./usr:
lib/

./usr/lib:
mylib.so

Of course, we have the debian/ directory, which is where the magic happens. But the other top-level directory, usr/ in our case, is what we want to install on the target system.

The easiest thing to do is to re-create your target system’s filesystem layout as a top-level directory, and then put your files in the appropriate spot. Here, we want to install mylib.so into /usr/lib on the target system, so you can see that I’ve recreated it above.

If you also wanted to install, an upstart script, say, you’d also create:

$ ls -RF
.:
debian/  etc/  usr/

./etc:
init/

./etc/init:
myjob.conf

Ok, next let’s look at the stuff in debian/:

achiang@aspen:~/Projects/example/debian$ cat rules 
#!/usr/bin/make -f
%:
	dh $@

That’s pretty easy. How about the control file?


achiang@aspen:~/Projects/example/debian$ cat control 
Source: example
Section: libs
Priority: extra
Maintainer: Alex Chiang 
Build-Depends: debhelper (>= 7)
Standards-Version: 3.9.1

Package: example
Architecture: any
Depends: ${misc:Depends}
Description: A skeleton installation deb
 An example, minimal package that installs files into the filesystem, without
 any processing from the packaging system.

Ok, one more interesting file, the ‘install’ file:

achiang@aspen:~/Projects/example/debian$ cat install 
usr/

The usr/ entry in ‘install’ maps to the usr/ directory you created above. Again, if you also wanted to install something into etc/, you’d add the corresponding line into ‘install’. Extend this concept to any other directories/files you’ve created.

The rest of the files are more or less boilerplate. I’ll display them for completeness’ sake:

achiang@aspen:~/Projects/example/debian$ cat compat 
7
achiang@aspen:~/Projects/example/debian$ cat copyright 
This package was debianized by Alex Chiang  on
Mon Jul 11 14:30:17 MDT 2011

Copyright:

    Copyright (C) 2011 Alex Chiang

License:

    This program is free software: you can redistribute it and/or modify it
    under the terms of the the GNU General Public License version 3, as
    published by the Free Software Foundation.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranties of
    MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
    PURPOSE.  See the applicable version of the GNU Lesser General Public
    License for more details.
 
On Debian systems, the complete text of the GNU General Public License
can be found in `/usr/share/common-licenses/GPL-3'
achiang@aspen:~/Projects/example/debian$ cat source/format 
3.0 (native)

So, there you have it. A pretty trivial example on how to package a binary inside of a debian source package. Of course, you could do this with text files, PDFs, whatever.

Feedback appreciated.