Creating Packages For Ubuntu

/!\ This article is incomplete and may be incorrect. If you can correct or add to it, please do!

At some point you'll probably want to build your own packages for easy deployment. We do this for Xen, God and a number of other pieces of software.

In this example we'll repackage God. We'll end up with a package called xeriom-god which will include an init script and will look in /etc/god/watches.d/*.god for watch configuration, automatically reloading configuration files that have been changed.

Preparing your build environment

Before we start, we'll setup a little area to perform our packaging tasks in so that our homedir doesn't get messy.

mkdir -p ~/packages/{build,debs}

We'll use the build directory to assemble packages and the debs directory will hold our completed packages.

Packaging God

Setup the necessary directory structure under ~/packages/build

mkdir -p ~/packages/build/xeriom-god/DEBIAN
mkdir -p ~/packages/build/xeriom-god/var/lib/gems/1.8
mkdir -p ~/packages/build/xeriom-god/etc/init.d
mkdir -p ~/packages/build/xeriom-god/etc/god/watches.d
mkdir -p ~/packages/build/xeriom-god/etc/default
mkdir -p ~/packages/build/xeriom-god/usr/share/{bug,doc}/xeriom-god

touch ~/packages/build/xeriom-god/etc/god/watches.d/.keep

Install the necessary software into the build root.

gem install rake --install-dir ~/packages/build/xeriom-god/var/lib/gems/1.8/
gem install rubyforge --install-dir ~/packages/build/xeriom-god/var/lib/gems/1.8/
gem install hoe --install-dir ~/packages/build/xeriom-god/var/lib/gems/1.8/
gem install god --install-dir ~/packages/build/xeriom-god/var/lib/gems/1.8/

Add some customisations

cp ~/.../god-watch_watcher.rb ~/packages/build/xeriom-god/var/lib/gems/1.8/bin/watch_watcher
cp ~/.../god-master.conf ~/packages/build/xeriom-god/etc/god/master.conf
cp ~/.../god-init.d.sh ~/packages/build/xeriom-god/etc/init.d/god

You can look at these files at:

Add a default configuration.

echo 'MASTER_CONFIG=/etc/god/master.conf' > ~/packages/build/xeriom-god/etc/default/god

Make sure that bug reports will be sent to the correct place.

echo 'Send-To: support@xeriom.net' > ~/packages/build/xeriom-god/usr/share/bug/xeriom-god/control

Create the package control file.

nano -w ~/packages/build/xeriom-god/DEBIAN/control

Package: xeriom-god
Version: 0.0-1
Section: base
Priority: optional
Architecture: amd64
Depends: ruby (>= 1.6.8), libc6, lsb-base (>= 3.0-6)
Maintainer: Craig Webster <craig@xeriom.net>
Description: God packaged for use at Xeriom Networks
 Watches /etc/god/watch.d/**/*.god for watch configuration. 

Declare all the configuration files.

nano -w ~/packages/build/xeriom-god/DEBIAN/conffiles

/etc/init.d/god
/etc/default/god
/etc/god/master.conf
/etc/god/watches.d/.keep

Register (and delete when appropriate) the init script using the postinst and postrm scripts.

touch ~/packages/build/xeriom-god/DEBIAN/postinst
chmod u+x ~/packages/build/xeriom-god/DEBIAN/postinst
nano -w ~/packages/build/xeriom-god/DEBIAN/postinst

#! /bin/sh

set -e

case "$1" in
    configure)
        update-rc.d god defaults
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

exit 0

touch ~/packages/build/xeriom-god/DEBIAN/postrm
chmod u+x ~/packages/build/xeriom-god/DEBIAN/postrm
nano -w ~/packages/build/xeriom-god/DEBIAN/postrm

#! /bin/sh

set -e

case "$1" in
    upgrade|remove|failed-upgrade|abort-install|abort-upgrade|disappear)
    ;;
    purge)
        if [ "$1" = purge ]; then
            update-rc.d god remove
        fi
    ;;
    *)
        echo "postrm called with unknown argument \`$1'" >&2
        exit 1
esac

exit 0

Create the copyright file.

nano -w ~/packages/build/xeriom-god/usr/share/doc/xeriom-god/copyright

This package was debianized by Craig Webster <craig@xeriom.net> on
[whenever].

It was downloaded from http://somewhere.com/

Author(s): Author Name <email@address.com>
           Another Author Name

Copyright: (c) YYYY Author Name

    [ text of licence goes here ]

The Debian packaging is (C) 2008, Craig Webster <craig@xeriom.net> and
is licensed under the ... licence, see `...'.

Create the changelog and changelog.Debian file.

nano -w ~/packages/build/xeriom-god/usr/share/doc/xeriom-god/changes


xeriom-god (0.1-0.0) hardy; urgency=low

  * Initial release.

 -- Craig Webster <craig@xeriom.net>  Sat, 31 May 2008 16:37:19 +0100

cp ~/packages/build/xeriom-god/usr/share/doc/xeriom-god/changes ~/packages/build/xeriom-god/usr/share/doc/xeriom-god/changes.Debian
gzip --best ~/packages/build/xeriom-god/usr/share/doc/xeriom-god/changes*

Build the package.

cd ~/pacakges
fakeroot dpkg-deb --build xeriom-god ~/packages/debs

You should now have a xeriom-god_0.0-1_amd64.deb file in ~/packages/debs. Let's check and make sure it meets the communities quality standards.

lintian ~/packages/debs/xeriom-god_0.0-1_amd64.deb

After fixing any errors (mostly by running chmod 0755 on any scripts it complains about not being executable) try installing it. Make sure you install the dependency - in this case Ruby - first.

sudo apt-get install ruby
sudo dpkg -i ~/packages/debs/xeriom-god_0.0-1_amd64.deb

If it installs, you now have a working package. Play with the installed version and see what you did wrong, building new versions as appropriate. I made lots of typos when setting up the configuration files and forgot a lot of Gem dependencies.

Once you're happy you can either copy it to whichever server you want to install it on and install it using dpkg as above or you could add this package to your own package repository.

XeriomWiki: CreatingPackagesForUbuntu (last edited 2008-05-31 21:15:09 by CraigWebster)