Posted by Steve on Sun 27 Mar 2005 at 18:11
The Debian distribution is one which is based upon binary packages, which are built from by developers from source, and then uploaded into the archive and mirrors. Obtaining the source code which is used to build packages is very simple - but sometimes you might want to work with the binary packages.
The Debian binary format is very simple, it is nothing more complex than an archive produced using the ar tool containing two files:
If you have the binary .deb file for a given package you can unpack it's contents in two ways, using ar or using the dpkg command.
The second method is simplest:
skx@mystery:~$ dpkg -x komi_1.03-1_i386.deb tmp skx@mystery:~$ ls tmp/ usr var
As you can see we've extracted the contents of the komi package into the directory tmp, which now contains the package.
If you were sufficiently motivated you could "install" binary packages beneath your home directory by unpacking them and setting up your PATH appropriately.
Using ar to unpack the contents is almost as easy, first of all you need to unpack the two .tar.gz files:
skx@mystery:~$ ar -x komi_1.03-1_i386.deb control.tar.gz skx@mystery:~$ ar -x komi_1.03-1_i386.deb data.tar.gz
Once this has been done you can list the contents of the data file, by running:
skx@mystery:~$ tar -tzvf data.tar.gz drwxr-xr-x root/root 0 2004-07-12 15:47:05 ./ drwxr-xr-x root/root 0 2004-07-12 15:47:04 ./usr/ drwxr-xr-x root/root 0 2004-07-12 15:47:05 ./usr/games/ -rwxr-xr-x root/root 69464 2004-07-12 15:47:05 ./usr/games/komi drwxr-xr-x root/root 0 2004-07-12 15:47:04 ./usr/share/ drwxr-xr-x root/root 0 2004-07-12 15:47:03 ./usr/share/games/ .... snip ....
The contents of the control archive are interesting too:
skx@mystery:~$ tar -tzvf control.tar.gz drwxr-xr-x root/root 0 2004-07-12 15:47:06 ./ -rwxr-xr-x root/root 173 2004-07-12 15:47:05 ./postinst -rwxr-xr-x root/root 160 2004-07-12 15:47:05 ./postrm -rw-r--r-- root/root 5472 2004-07-12 15:47:06 ./md5sums -rw-r--r-- root/root 626 2004-07-12 15:47:06 ./control
Here you can see the some files, postinst is a script which runs post install. postrm is another script which runs post-remove. The control contains information about the package, dependencies etc, and the md5sums contains checksums of all the files in the data.tar.gz file.
If you wished you could make changes to the control file and repack the whole thing - this might be useful if you wish to force the installation of a package by removing a dependency, or performing similar magic.
ar is a pretty simple tool to work with, and is fully described in the fine manpage: