Thursday, September 9, 2010

Steps for Creating a debian package installer for an application in Linux

Debian Package

Debian packages are standard Unix archives that include two gzipped, bzipped or lzmaed tar archives: one that holds the control information and another that contains the data.

The canonical program for handling these packages is dpkg, most commonly via apt/aptitude. [apt/aptitude are programs for application installers that come by default with Ubuntu]

A deb file contains two main files :

  • control.tar.gz
  • data.tar.gz
Certain things to be kept in mind for Linux

1) All executable binaries in Linux are usually to be installed under /usr/bin/ ; /usr/sbin/ ; /bin/

Why ? Coz these directories are added to the global PATH variable and all files are accessible from any folder.
To try this out : Open a terminal , type echo $PATH
You will see a number of directories , these are all having binaries / executables which can be accessed from any location . E.g the command 'cat' or 'ls' are all built-in executables that are present under /bin/ which is available in the PATH variable.

/home/rajesh/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

2) To find out the dependent shared libraries for an executable , try the ldd command

Why ? Coz this would give the libraries required by this executable , and can thus be listed in the control file of the .deb
Now we can see a step by step approach to creating a debian package with an example :

control file : This is the main “brain” of a debian file: it contains all of the informations reguarding this package, without this file the entire creation of a deb package has no meaning at all. A control file looks like this
__________________________________________________________________________________________________________
Package: ModBusTCPSim
Version: 1.01
Architecture: i386
Maintainer:
Installed-Size:
Depends:
Section: apps
Priority: optional
Description: ModBus TCP/IP Slave Simulator

ModBus TCP / IP Slave Simulator is a GUI implementation of the Slave Code of Modbus , built on the Sunlux Slave Stack Library.
This finds use as an slave simulator running on Linux / Ubuntu .
Original-Maintainer: Rajesh CB cb.rajesh.in@gmail.com>
________________________________________________________________________________________________________
  • Package: you have to put here the name of the package, never use spaces, never use a version number. It is case sensitive, be warned!
  • Version: of course, the version number / code. It can also be, for example, opengeu-3.0.2 or any other weird code, as long as the last part is a number. Always remember that chaning the version to a higher number triggers the system to consider that new file as an update of course!
  • Priority: optional, high, low, only system or security updated should have something like high in the priority.
  • Architecture: i386, amd64, all, you should specify here what platform this package is compiled for. If it is only an artowork or a metapackage, you can put all in the Architecture field.
  • Depends: a list of all the packages this package depends on. A metapackage, for example, can include almost nothing but depend on a lot of other packages so that installing this metapackage automatically installs a lot of other packages! That’s what happens with opengeu-desktop for example!
  • Conflicts: if you know that your package can’t work if another package is installed, well, you should then list that package here.
  • Description: put only a very short description in the first line, then enter a longer description on the second line, like it is shown in the example above.
Data
Every file that has to be installed into the system goes into the debian folder. Let’s say that this is like the heart of our deb package. Consider this folder as the “/” mount point of your system, the main system folder or whatever you call it. Basically, you have to recreate into the debian folder the structure of the folders and files you wish to be installed into the system. So, let’s say that our package has to install the ModBusTCPSim into the /usr/bin/ModBusTCPSim

then, you’ll have to create or edit the files and folders status to look like this:

Rajesh/debian/usr/bin/ModBusTCPSim

The final debian package creation :

Thus the final directory structure would look like this :

Rajesh/
`-- debian
`-- DEBIAN
|-- control
`-- usr
`-- bin
`-- ModBusTCPSim

Now cd to the folder Rajesh/ through a terminal and execute the command dpkg-deb –build debian
and you will have the debian.deb package created under the folder Rajesh/

We can rename or move the folder to a better name by :


mv debian.deb ModBusTCPSim.deb

'mv' - move command in Linux


Now through the GUI double click on
ModBusTCPSim.deb and the package gets installed.

Grey areas :

1) control can either be a file or a
control.tar.gz zipped archive of some more packages fro data integrity check.
2) This is a very basic set of files required to make a debian package , and does not contain all checks for data corruption et all , good debian packages contain manuals for the application too.

No comments: