Sometimes you just want a quick way of installing a piece of software on multiple Debian (or Debian-based, e.g. Ubuntu) systems. Maybe a set of maintenance scripts you wrote (don’t we all?), or a binary you found somewhere. In those cases, it feels like quite a burden to use dpkg-buildpackage: the only thing you need is for a directory structure to go into a .deb archive, with some additional metadata. Here’s how you do that.
The tool to use: dpkg-deb
The easiest way to construct a .deb file based on a directory structure and some metadata, is to use the dpkg-deb tool. It comes with dpkg, so you won’t have to install any additional software. To get it completely right, you will need root permissions, though. Otherwise, the files in the .deb file will be owned by the user (or rather, his/her uid) on the remote system.
The directory structure
Let’s assume we’re building version 0.5 of a package called “backup-script”, which has two files: /usr/bin/backup-script and /etc/backup-script.conf. We will need the following files and directories under /home/[yourname]/ (or any other location you like better):
backup-script/backup-script_0.5/DEBIAN/control backup-script/backup-script_0.5/DEBIAN/conffiles backup-script/backup-script_0.5/usr/bin/backup-script backup-script/backup-script_0.5/etc/backup-script.conf
The contents of the DEBIAN directory
In this simple example, we need two files in the DEBIAN subdirectory (note that DEBIAN is spelled with upper case characters): control and conffiles. The first file will contain the metadata for our package and should contain the following information:
Package: backup-script Architecture: all Maintainer: Bas van Schaik Depends: debconf (>= 0.5.00), rsync Priority: optional Version: 0.5 Description: My Simple backup script This script provides an easy way of creating backups . Creating backups is now more fun than ever!
The description in control can consists of multiple lines (like in the example), but the lines need to be indented and empty lines need to contain a full stop (empty lines are not allowed in control). The conffiles file needs to contain a list of configuration files. These are installed in a different way (see [1] for a detailed description), so changes to the configuration files (/etc/backup-script.conf) by the system administrator don’t get overwritten. In our case, conffiles contains just one line with:
etc/backup-script.conf
Building the .deb file
Now the directory structure is in place, we can construct the .deb package. First, change the ownership of all files to root (see Debian Bug 291320 [2]) – otherwise the deployed files will be owned by you (or the user with your uid). Run the following commands as root (or use sudo if you’re on Ubuntu):
chown -R root:root backup-script/backup-script_0.5/
Then, build the package using dpkg-deb:
dpkg-deb --build backup-script/backup-script_0.5
Bonus step: add it to an existing APT repository
If you’re hosting your own APT repository, you can use the following command to add your new .deb package to the repository (to a distribution called production):
reprepro -b /path/to/repo includedeb production backup-script_0.5.deb
For more information on how to set up your own APT repository, you might be interested in reading [3]
References
[1] http://www.debian.org/doc/manuals/maint-guide/dother.en.html#conffiles
Pingback: moov.de » Install puppet on ARM devices (Raspberry Pi)