Sunday, April 29, 2012

How to package a .deb

          On Debian-based systems, the package manager uses .deb containers to handle the installation of packages. Many people make a connection between .deb and .exe since both are easy formats that usually lead to the installation of a program, but this is not the case. Deb files are more like an advanced .tar, and they don't even need to be used for installing programs. In this tutorial I will show you how to make and build a debian package. Make a new directory, let's say for instance, mydeb. Then, in the mydeb directory make a folder named DEBIAN. Now we can begin.

There are a few essential things to put into DEBIAN. You need to have a control file called control, a pre-installation script called preinst, and a pre-removal file called prerm. The control file uses a special syntax to define dependencies, make a description, and note the authors. Here is a sample control file:

Package: mydeb
Version: 1.0.0-0ubuntu1
Architecture: amd64
Maintainer: You <You@email>
Installed-Size: 154
Depends:
Section: accessories
Priority: optional
Description: A sample debian package.

Package is the name of the package, in this case it's mydeb. The version is the version of the file with any special revision names included. Architecture is what type of CPU it can run on. Depends is the most important, which lists dependencies. The operations > < and >= <= can be used to specify higher or lower version numbers for dependencies. The section is what type of application it is. Priority is whether or not the package is a necessity. In this case it's not. Description is a long description of what the package can do. This can be multiple lines.

Now that the control file is out of the way, make two scripts called preinst and postinst. These are bash scripts (text files with #!/bin/bash at the top) that list the commands to install and remove the parts of the program that were included on install. ldconfig should be called in either file.

The fun part
The fun and arguably the most important step is specifying the directories where files will be installed. Leave the DEBIAN folder and make one called home. Then, make one that is exactly equal to your home folder. Make a sample text file here. When the .deb is installed that text file will be placed in your home folder. This is used to spread resources across the files system, for instance the icon goes in /usr/share/pixmaps. You actually have to create those directories inside of the parent directory.

Now you should have two directories in the parent directory, DEBIAN and home. Now we can package these with the dpkg command. Enter the terminal and use the command
dpkg -b 'PATH_TO_PARENT_FOLDER' myDeb.deb


This should create a file in your home folder called myDeb.deb. Now you can install the package with gdebi, the software center, or dpkg.

A note for application developers: ldd lists the dependencies of an executable file for the Depends: part of a command file.

External: http://www.linuxfordevices.com/c/a/Linux-For-Devices-Articles/How-to-make-deb-packages/

No comments:

Post a Comment