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 /usr/lib

But then what if you need to update 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/

changelog  compat  control*  copyright  install  rules*  source/




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 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/



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 

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 
achiang@aspen:~/Projects/example/debian$ cat copyright 
This package was debianized by Alex Chiang  on
Mon Jul 11 14:30:17 MDT 2011


    Copyright (C) 2011 Alex Chiang


    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
    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.

5 thoughts on “trivial .deb packaging

  1. Olivier says:

    Nicely summarized, this can indeed come in very handy, and having a skeleton package in a branch will make it painless.

    I had to do exactly that last week as part of a project for which I don’t have access to the source code, I only get a compiled .so and a bunch of headers. Note that if you’re going to build a source package (if for example you want to push to a PPA) using debuild -S, you will need to override the -I parameter, as it excludes *.so files from the source tarball by default. It took me a while to figure out, so I thought I’d share the info.

    • Thanks Olivier.

      For future google visitors, the man page that Olivier is talking about is dpkg-source.

      Note: While they have similar purposes, -i and -I have very different
      syntax and semantics. [...]

      The default regexp and patterns for both options can be seen in the
      output of the –help command.

      So, from dpkg-source –help, we see:

      -I[] filter out files when building tarballs
      (defaults to: -I*.a -I*.la -I*.o -I*.so -I.*.sw? -I*/*~ -I,,* -I.[#~]* -I.arch-ids -I.arch-inventory -I.bzr -I.bzr.backup -I.bzr.tags -I.bzrignore -I.cvsignore -I.deps -I.git -I.gitattributes -I.gitignore -I.hg -I.hgignore -I.hgtags -I.shelf -I.svn -ICVS -IDEADJOE -IRCS -I_MTN -I_darcs -I{arch}).

      To do the override that Olivier mentions, I invoke debuild as such:

      $ debuild -S -sa -I.bzr -i

      if your package is more complex, you’ll have to extend the example. Note that simply dropping the -I option completely does not work. Finally, you’ll want your package to be a 3.0 (native) package.

  2. rob says:

    Thanks for this post. I have always wanted to make my own .deb files but the lack of tutorials on the interwebs has always scared me out of ever doing it.

    I just downloaded a .deb file ( cowsay_3.03+dfsg1-3_all.deb )
    I ran
    dpkg -x cowsay_3.03+dfsg1-3_all.deb /my_tmp_dir/

    and all I see are the usr/ directory. No debian/

    Is the debian/ junk needed.

    • You cannot recreate a debian source package from the binary package alone, because not all the files from the debian/ directory in the source package end up in the binary package.

      How did you get that .deb file? Did you just download it? Ideally, you could just do “apt-get source cowsay” which should grab the debian *source* package, which you can then inspect.

      That said, there are some things you can inspect if you only have the binary package. dpkg -x will get you the contents; dpkg -I will give you info; dpkg -e will give you the control file and the maintainer scripts.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>