Over the last few weeks I have been building a bunch of Debian packages (aka debs) for a new Ubuntu server roll out. Most of the packages are either updates to existing packages or meta packages. Building meta packages is pretty easy, once you know how.

I will outline how to build a simple package which pulls in a couple of useful packages.

First off we need to create the directory structures and files. I do all of my packaging work in /home/$USER/packaging, with my meta packages living in a directory called meta.

For your first package run the following command

$ mkdir -p /home/$USER/packaging/meta/my-meta/DEBIAN

The key to creating meta packages is the “control” file. I have a very generic package I use for all of my servers, called dhc-base . This pulls in what I consider to be the minimum dependencies needed for a basic server. My “~/packaging/meta/dhc-base/DEBIAN/control” file looks something like this:

Package: dhc-baseVersion: 0.1Section: mainPriority: standardArchitecture: allDepends: dhc-archive-keyring, fail2ban, iptables, openssh-server, screen, shorewall, ubuntu-minimalMaintainer: Dave Hall <EMAIL-ADDRESS>Description: Base install meta package for boxes administered by Dave Hall Consulting

The fields should all be pretty self explanatory. The key one is “Depends” which lists all of the packages which you want your package to pull in. I try to keep the list alphabetical so it is easier to manage.

In my example I pull in some basic things which I use all the time as well as the the gpg signing key for my packages, which I have also packaged – I may blog how to do that one day too.

Now we are ready to build the package. simply run

$ dpkg-deb -b /home/$USER/packaging/meta/my-meta

and wait for dpkg-deb to work its magic. Now you should have a shiny new deb called my-meta.deb sitting in /home/$USER/packaging/meta

If you have a bunch of meta packages to build, it can become tedious to have run the command over an over again, and each time the packages will overwrite the previous version. To save me some effort I wrote a little shell script which build a package, and gives it a nice version number too.

#!/bin/bash## build-meta - dpkg-deb wrapper script for building meta packages## Developed by Dave Hall Consulting## Copyright (c) 2009 Dave Hall Consulting - http://davehall.com.au## You may freely use and distribute this script as long as the copyright# notice is preserved#function usage {SCRIPT=`basename $0`echo Usage: $SCRIPT package-path output-path}if [ $# != 2 ]; thenusage $0exit 1fiDIR=$1OUT=$2DPKG_DEB=dpkg-debPKGNAME=`basename $DIR`BUILDREV=`date +%Y%m%d$H%I%S`VERSION=`cat $DIR/DEBIAN/control | awk '$1~/^Version:/{print $2}'`echo "Building $PKGNAME"$DPKG_DEB -b $DIR $OUT/${PKGNAME}_$VERSION-${BUILDREV}_all.deb

The script it pretty simple. It takes to arguments, the path for the package and directory to put the final package in, it will even read the version number from the control file.

To process all of the meta packages at once, simply run:

$for pkg in `find /home/$USER/packaging/meta -maxdepth 1 -type d | egrep -v '(.bzr|.svn|.git)'`; do /path/to/build-meta $pkg /home/$USER/packaging/built; done

Now you should have a nice collection of meta packages to deploy.

If you want to setup your own debian repository for your meta packages, I would recommend reading Ian Lawrence’s reprepro howto.

I have found meta packages really simplify the tedious task of setting up common package sets – especially for server roll outs.

from here