How to create debian (deb) package

How to create debian (deb) package

Introduction –
Packages generally contain all of the files necessary to implement a set of related commands or features. There are two types of Debian packages:
1) Binary packages, which contain executables, configuration files, man/info pages, copyright information, and other documentation.
These packages are distributed in a Debian-specific archive format they are usually distinguished by having a ‘.deb’ file extension.
Binary packages can be unpacked using the Debian utility dpkg (possibly via a frontend like aptitude).

2) Source packages, which consist of a .dsc file describing the source package (including the names of the following files), a .orig.tar.gz file that contains the original unmodified source in gzip-compressed tar format and usually a .diff.gz file that contains the Debian-specific changes to the original source. The utility dpkg-source packs and unpacks Debian source archives.
Installation of software by the package system uses “dependencies” which are carefully designed by the package maintainers.  These dependencies are documented in the control file associated with each package.

Step 1) Please install few deb packages as pre-requirement –

arunb@laptop:~# apt-get install fakeroot build-essential

Step 2) Create directory where you will be putting your build data –

arunb@laptop:~# mkdir /var/create-deb-pkg/
arunb@laptop:~# chown arunb:arunb /var/create-deb-pkg/

Step 3) extract source and manually compile your software –

I compiled my software ie openlsm as shown below…

# cd /var/src/
tar xvfz openlsm-0.99-r51.tar.gz
cd openlsm-0.99-r51/
./configure –prefix=/usr/local/openlsm –with-mysql=/usr/bin/mysql_config –enable-internal-pcre –with-geoip=/usr –with-ldap=/usr
make
make install

Step 4) Create directory structure for creating deb package and copy build code/data –

arunb@laptop:~$ cd  /var/create-deb-pkg/

arunb@laptop:/var/create-deb-pkg$ mkdir openlsm-0.99-r51
arunb@laptop:/var/create-deb-pkg$ mkdir -p openlsm-0.99-r51/usr/local/
arunb@laptop:/var/create-deb-pkg$ mkdir openlsm-0.99-r51/DEBIAN/

** copying my build code here

arunb@laptop:/var/create-deb-pkg$ cp -fr /usr/local/openlsm/  openlsm-0.99-r51/usr/local/

arunb@laptop:/var/create-deb-pkg$ ll openlsm-0.99-r51/
drwxr-xr-x 2 arunb arunb 4096 2012-01-19 16:34 DEBIAN/
drwxr-xr-x 3 arunb arunb 4096 2012-01-19 16:31 usr/

Step 5) Define/Create deb package control files in DEBIAN directory –

arunb@laptop:/var/create-deb-pkg$ ll openlsm-0.99-r51/DEBIAN/
-rw-r–r– 1 arunb arunb   179 2012-01-19 16:34 changelog
-rw-r–r– 1 arunb arunb   139 2012-01-19 16:34 conffiles
-rw-r–r– 1 arunb arunb   419 2012-01-19 16:34 control
-rw-r–r– 1 arunb arunb 17696 2012-01-19 16:34 md5sums
-rwxr-xr-x 1 arunb arunb   535 2012-01-19 16:34 postinst
-rwxr-xr-x 1 arunb arunb   227 2012-01-19 16:34 postrm
-rwxr-xr-x 1 arunb arunb   303 2012-01-19 16:34 preinst
-rw-r–r– 1 arunb arunb     0 2012-01-19 16:34 rules

* DEBIAN/rules – file is empty

* DEBIAN/changelog file –

arunb@laptop:/var/create-deb-pkg$ cat openlsm-0.99-r51/DEBIAN/changelog
openlsm (0.99) stable; urgency=low

* openlsm web server for admin panel
+ 0.99 released – Jun 2009

— Arun Bagul <arunbagul@indiangnu.org>  Tue, 01 Jun 2009 01:31:52 -0530
arunb@laptop:/var/create-deb-pkg$

* DEBIAN/control file –

arunb@laptop:/var/create-deb-pkg$ cat openlsm-0.99-r51/DEBIAN/control
Package: openlsm
Version: 0.99-r51
Architecture: i386
Maintainer: Arun Bagul <arunbagul@indiangnu.org>
Provides: httpd, httpd-cgi
Section: httpd
Priority: optional
Homepage: http://openlsm.sourceforge.net/
Description: openlsm is web-based control panel for Unix/Linux systems
openlsm is web-based control panel for Unix/Linux systems
and Web Hosting! openlsm handles all aspects of administration in its interface.

* DEBIAN/postinst file (perform after installing package) –

arunb@laptop:/var/create-deb-pkg$
arunb@laptop:/var/create-deb-pkg$ cat openlsm-0.99-r51/DEBIAN/postinst
#!/bin/sh

set -e
SOFT=”openlsm”
echo “Copying pam.d/openlsm and init.d/openlsm file”
cp -fv /usr/local/${SOFT}/etc/pam.d/openlsm   /etc/pam.d/openlsm
cp -fv /usr/local/${SOFT}/etc/init.d/openlsm  /etc/init.d/openlsm
test -f /etc/init.d/openlsm && chmod 755 /etc/init.d/openlsm

update-rc.d openlsm defaults

echo “Changing permission of ‘/usr/local/openlsm/'”
chown openlsm:openlsm -R /usr/local/openlsm/
echo “Please run this cmd to generate Certificate for openlsm ~ ‘/usr/local/openlsm/bin/openlsm-create-certificate'”
exit 0

* DEBIAN/postrm file (take action before removing package) –

arunb@laptop:/var/create-deb-pkg$ cat openlsm-0.99-r51/DEBIAN/postrm
#! /bin/sh

set -e

echo “postrm step -”

update-rc.d -f openlsm remove
rm -vf /etc/init.d/openlsm /etc/pam.d/openlsm
echo “Deleting user & group – ‘openlsm’…”
userdel openlsm
getent group openlsm && groupdel openlsm

exit 0
arunb@laptop:/var/create-deb-pkg$

* DEBIAN/md5sums –

arunb@laptop:/var/create-deb-pkg$ head openlsm-0.99-r51/DEBIAN/md5sums
2129ba0e98dd77e8879e0912abe432a3  /usr/local/openlsm/sbin/openlsm-worker
a1dbdafadefd74bac29c8fd229dd1c01  /usr/local/openlsm/bin/openlsm-panic
e57e75853b52caf9569c922b7c404129  /usr/local/openlsm/bin/openlsm-tweak
..

arunb@laptop:/var/create-deb-pkg$

* DEBIAN/conffiles file –

arunb@laptop:/var/create-deb-pkg$ cat openlsm-0.99-r51/DEBIAN/conffiles
/usr/local/openlsm/etc/openlsm/openlsm.conf
/usr/local/openlsm/etc/openlsm/openlsm.conf.perf_sample
arunb@laptop:/var/create-deb-pkg$

Step 6) Create deb package now –

arunb@techops-i-arunb:/var/create-deb-pkg$ ls -l
drwxr-xr-x 4 arunb arunb 4096 2012-01-19 16:43 openlsm-0.99-r51

* creating deb package now…

arunb@techops-i-arunb:/var/create-deb-pkg$ fakeroot dpkg-deb –build openlsm-0.99-r51/
dpkg-deb: building package `openlsm’ in `openlsm-0.99-r51.deb’.

arunb@techops-i-arunb:/var/create-deb-pkg$ ls -l
drwxr-xr-x 4 arunb arunb    4096 2012-01-19 16:43 openlsm-0.99-r51
-rw-r–r– 1 arunb arunb 3491738 2012-01-19 16:52 openlsm-0.99-r51.deb

* rename your package if required like arch etc

arunb@techops-i-arunb:/var/create-deb-pkg$ mv openlsm-0.99-r51.deb openlsm-0.99-r51_i386.deb

arunb@techops-i-arunb:/var/create-deb-pkg$ ls -l
drwxr-xr-x  4 arunb arunb    4096 2012-01-19 16:43 openlsm-0.99-r51/
-rw-r–r–  1 arunb arunb 3491738 2012-01-19 16:52 openlsm-0.99-r51_i386.deb
arunb@techops-i-arunb:/var/create-deb-pkg$

* That’s it, enjoy Debian/Ubuntu!

Thank you,
Arun Bagul

Similar Posts:

Be Sociable, Share!

1 Reply to “How to create debian (deb) package”

Leave a Reply

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