![]() | ![]() |
|
Debian Binary Package Building HOWTOChr. Clemens Lee2002-11-30, $Date: 2003/12/19 18:37:45 $
1. IntroductionThe intended use of such a newly created archive is to install it only on your own box, not to get them into the official Debian distribution. To follow the 'official' process, please study the Debian New Maintainers' Guide. Normal Debian packages get a proper source package, including a debian/rules file which automates the steps involved in creating the binary package. Here we just show how to package a simple shell script or binary executable into a small binary package. BTW, I assume you know how to use 'tar', 'man', and what a '.tar.gz' file and Debian is (and how to use an editor ;-), but I assume you have never touched programs like 'ar' or 'dpkg'. 1.1. Resources on the WebThe Debian Reference gives an excellent overview as well as detailed information for everything Debian specific. The official document for creating your own Debian packages is the Debian New Maintainers' Guide. 2. Getting StartedFrom the Debian Reference 2.2.2 2002-11-30: "The internals of this Debian binary package format are described in the deb(5) manual page. Because this internal format is subject to change (between major releases of Debian), always use dpkg-deb(8) for manipulating .deb files." From the dpkg-deb man page: "dpkg-deb packs, unpacks and provides information about Debian archives. .deb files can also be manipulated with ar and tar alone if necessary. Use dpkg to install and remove packages from your system." You might find lots of example .deb files in directory '/var/cache/apt/archives/'. With 'dpkg-deb -I somepackage.deb' you might get a general overview of what this package offers in particular. 'dpkg-deb -c somepackage.deb' lists all files which will be installed. List content of the .deb file with 'ar tv somepackage.deb'. Use the 'x' option to extract the files. 3. Package StructureLet's examine one example package a little bit closer. E.g. file 'parted_1.4.24-4_i386.deb' contains these three files:
Now we can start to extract all files including the content of the tar files. 3.1. debian-binaryThe content of this file is "2.0\n". This states the version of the deb file format. For 2.0 all other lines get ignored. 3.2. data.tar.gzThe 'data.tar.gz' file contains all the files that will be installed with their destination paths:
It must be the last file in the deb archive. 3.3. control.tar.gzIn our example this file has the following content:
'md5sums' contains for each file in data.tar.gz the md5sum. In our example the content looks like this:
Don't worry, the 'md5sum' file as well as the 'postinst' and 'prerm' files are not mandatory for your first package. But please take a note of their existence, every proper official Debian package has them for good reasons. 'prerm' and 'postinst' seem to take care of removing old documentation files and adding a link from doc to share/doc. And finally the most interesting file:
Further information about the control file can be obtained via 'man 5 deb-control'. 4. Hands OnNow it is time to get practical ourselves. I have a simple shell script named 'linuxstatus' which I want to install as '/usr/bin/linuxstatus'. So first let's create a directory named 'debian' next to the file 'linuxstatus'.
4.1. controlLet's start with the control file. The version number must have a dash with an additional Debian package version number, e.g. '1.1-1'. If your program consists e.g. only of portable shell scripts, use 'all' as its 'Architecture'. For 'Depends' you might need to find out to which package a certain file or program your new package relies onto belongs to. You can use 'dpkg -S <file>' for this to find this out, e.g.:
Then to find out more about package 'coreutils' you can use the command 'apt-cache showpkg coreutils', which will tell you among other things the current version number that is installed on the system. As a side note, there are two more ways to find the same information. There is a web page where you can search for Debian files: http://www.debian.org/distrib/packages. Go to the bottom of that page to fill out the web form. Last not least there is a nice GUI application named 'kpackage', which provides convenient package browsing options and also allows to search after packages given individual file names. 'Suggests', 'Conflicts', and 'Replaces' etc. can be left out if not needed. So here is the result of our first 'control' file:
The 'control' file gets copied into a directory called 'DEBIAN' inside the other 'debian' directory.
If you expect your package to have a bigger audience in the future it might help to read this Writing Debian package descriptions article. 4.2. dpkg-debNow it is almost done. Just type:
Uh, that was all easier than expected. Now we just have to install this package on our box and we are done:
Type 'linuxstatus' or 'ls -l /usr/bin/linuxstatus' to see if it worked. If you don't like your package any more, just type 'dpkg -r linuxstatus' and check again that the package is deinstalled. If you install a newer version you don't have to remove the old one first, thought. If you are curious about the version numbering scheme and naming conventions for a Debian package, have a read at this section in The Debian Reference. 5. Double CheckNow that you have gotten a first impression and build your own binary package, it is time to get a little bit more serious and have a look at the quality of the package that we have produced. 5.1. lintianLuckily for us the Debian project provides a 'lint' like tool for checking Debian packages. This tool is named 'lintian'. If you have not installed it yet on your system, this is a good moment (apt-get install lintian). Now we use this little treasure tool on our new package file:
Uh, doesn't look so perfect. We miss a man page, copyright file, and also those 'prerm' and 'postinst' scripts. 5.2. Minimal DocumentationThis is not the place to say much about writing and creating man pages, there are many books that have one or another chapter related to this topic and there is also The Linux MAN-PAGE-HOWTO online. So lets do a little time warp and assume you have now a perfect man page for your script at location ./man/man1/linuxstatus.1. The same for a 'copyright' file. You can find enough examples under the /usr/share/doc directory with this command: find /usr/share/doc -name "copyright" So here is our own example of a 'copyright' file:
For the 'prerm' and 'postinst' scripts we copy one to one the examples from the 'parted' package above into files with the same name in our own project directory. These files should work for us just as well. Now we create the debian package again. In the 'control' file we first increase the version number from 1.1-1 to 1.2-1 (since we have written a new man page we increase our internal release number). We also need to copy the new files to their appropriate places:
Gzip is necessary because lintian expects man page files to be compressed as small as possible. 5.3. fakerootNow lets see if our package has become a better Debian citizen:
Ups, new complains. OK, we will not give up. Actually most errors seem to be the same problem. Our files are all packaged for user and group 'clemens', while I assume most people would prefer having them installed as 'root/root'. But this is easily fixed using the tool 'fakeroot'. So lets fix and check this quickly (while ignoring the changelog issue):
Fine, but we have yet another file to add to the package. 5.4. More DocumentationLet me tell you already that next to a 'changelog' file in the 'doc/linuxstatus' directory a 'changelog.Debian' file is also required. Both should be gzipped as well. Here are two example files, 'changelog':
and 'changelog.Debian':
The Debian Policy file has more details regarding the format of the changelog file. Now hopefully our last step will be:
Ah, we get no more complains :-). As root you can install now this package over the old one, again with the standard 'dpkg -i' command.
6. SummaryNot to get confused, let us recapture all steps we have taken to build our binary Debian package. Prerequisite files:
Setup temporary 'debian' directories:
Copy files into temporary 'debian' tree:
Build and check binary Debian package:
7. What ElseThere are many details which have not been covered here, like how to distribute Unix daemons, configuration files and much more. But most important, I want to emphasize again that for Debian maintainers, packages are source packages, not binary packages. They never interact directly with the internals binary packages. In fact only 'dpkg-deb' and 'dpkg' developers need to know what they are. In fact it is not recommended to do so. If a developer were to explain someone how to build a Debian package, he will certainly explain how to make a source package and how to build it. On the other hand, not every developer wants to submit his software to Debian (yet), but still wants to profit from the advantages a packaging system like 'dpkg' offers without releasing package source code. Personally I will release my freeware projects still as tar.gz files with source code etc. for all kind of platforms, while I plan to offer more and more '.deb' packages for the convenience of Debian users who just want to install and use my software. If someone wants to do the next step to submit a software package to Debian, you have to move on to study the Debian New Maintainers' Guide as well as the Debian Policy Manual first. On your undertaking to create a Debian source package, also have a look at the debian-mentors mailing list to see experienced and beginning Debian developers interacting with each other and tackling similar problem you might encounter. 8. CreditsThanks to
9. Links
|