Build your own Debian Packages
Until now when I wrote some scripts I always copied them directly to the Servers .I always thought: “It would be really cool if this were a Debian Package”. I played with the thougth of creating my own packages but it seemed to be very complicated (reading the Debian Standard Howto). Lately I discovered, that the Debian Howto covers a lot more than I actually needed and to create a simple binary package you actually need almost only your scripts. So let’s start.
Package-Folder-Structure
Every Debian Package has to contain at least a directory named “DEBIAN” and this has to contain the files “control”, “postinst” and “prerm”.
“postinst” and “prerm” are scripts which are executed “post installation” or “pre removal”. So you can figure out what they’re for
. The control-file contains information about the package e.g. the name, version, etc.
Folder-Structure
mypackage/ |-- DEBIAN | |-- control | |-- postinst | `-- prerm
Basic control file
A basic control-file could look like this:
Package: mydebianpackage Version: 0.1 Priority: optional Architecture: all Essential: no Depends: perl Maintainer: Jonas Garcia Koehel Provides: mydebianpackage Description: Some scripts used to do something
detailed description of the fields: http://www.debian.org/doc/debian-policy/ch-controlfields.html
Basic postinst and prerm scripts
They do nothing but have to exist to build the package
#!/bin/sh exit 0
Create the folder structure including own scripts
Lets say you want your scripts “script1.pl”, “script2.pl”, and “script3.pl” in the folder /usr/bin and you want “myscripts.conf” in /etc, so you create the following structure inside a build-directory (which can be named freely).
mydebianpackage/
|-- DEBIAN
| |-- control
| |-- postinst
| `-- prerm
|-- etc
| |-- myscripts.conf
|
`-- usr
|-- bin
|-- script1.pl
|-- script2.pl
`-- script3.pl
That’s all
Speaking the magic spell
And Abrakadabra:
dpkg -b ./mydebianpackage/ mydebianpackage_0.1.deb
Ready is your own debian package
Install it on a system
To install it just copy it to a server and type:
dpkg -i mydebianpackage_0.1.deb
to remove it again
apt-get remove mydebianpackage

Who can i get an in addres asked by the DEBIAN/config to the DEBIAN/postinst????????