Chapter 1. Quick summary of dpkg's external interface

Table of Contents

1.1. Control files
1.2. The dpkg status area
1.3. The dpkg library files
1.4. The "dpkg" command-line utility

The basic dpkg package control file supports the following major features:-

  • 5 types of dependencies:-

    • Pre-Depends, which must be satisfied before a package may be unpacked

    • Depends, which must be satisfied before a package may be configured

    • Recommends, to specify a package which if not installed may severely limit the usefulness of the package

    • Suggests, to specify a package which may increase the productivity of the package

    • Conflicts, to specify a package which must NOT be installed in order for the package to be configured

    • Breaks, to specify a package which is broken by the package and which should therefore not be configured while broken

    Each of these dependencies can specify a version and a dependency on that version, for example "<= 0.5-1", "== 2.7.2-1", etc. The comparators available are:-

    • "<<" - less than

    • "<=" - less than or equal to

    • ">>" - greater than

    • ">=" - greater than or equal to

    • "==" - equal to

  • The concept of "virtual packages", which many other packages may provide, using the Provides mechanism. An example of this is the "httpd" virtual package, which all web servers should provide. Virtual package names may be used in dependency headers. However, current policy is that virtual packages do not support version numbers, so dependencies on virtual packages with versions will always fail.

  • Several other control fields, such as Package, Version, Description, Section, Priority, etc., which are mainly for classification purposes. The package name must consist entirely of lowercase characters, plus the characters '+', '-', and '.'. Fields can extend across multiple lines - on the second and subsequent lines, there is a space at the beginning instead of a field name and a ':'. Empty lines must consist of the text " .", which will be ignored, as will the initial space for other continuation lines. This feature is usually only used in the Description field.

The "dpkg status area" is the term used to refer to the directory where dpkg keeps its various status files (GNU would have you call it the dpkg shared state directory). This is always, on Debian systems, /var/lib/dpkg. However, the default directory name should not be hard-coded, but #define'd, so that alteration is possible (it is available via configure in dpkg 1.4.0.9 and above). Of course, in a library, code should be allowed to override the default directory, but the default should be part of the library (so that the user may change the dpkg admin dir simply by replacing the library).

Dpkg keeps a variety of files in its status area. These are discussed later on in this document, but a quick summary of the files is here:-

These files are installed under /usr/lib/dpkg (usually), but /usr/local/lib/dpkg is also a possibility (as Debian policy dictates). Under this directory, there is a "methods" subdirectory. The methods subdirectory in turn contains any number of subdirectories for each general method processor (note that one set of method scripts can, and is, used for more than one of the methods listed under dselect).

The following files may be found in each of these subdirectories:-

  • names - One line per method, two-digit priority to appear on menu at beginning, followed by a space, the name, and then another space and the short description.

  • desc.<name> - Contains the long description displayed by dselect when the cursor is put over the <name> method.

  • setup - Script or program which sets up the initial values to be used by this method. Called with first argument as the status area directory (/var/lib/dpkg), second argument as the name of the method (as in the directory name), and the third argument as the option (as in the names file).

  • install - Script/program called when the "install" option of dselect is run with this method. Same arguments as for setup.

  • update - Script/program called when the "update" option of dselect is run. Same arguments as for setup/install.

This strange option is described as follows in the source code:

/* Print a single package which:
 *  (a) is the target of one or more relevant predependencies.
 *  (b) has itself no unsatisfied pre-dependencies.
 * If such a package is present output is the Packages file entry,
 *  which can be massaged as appropriate.
 * Exit status:
 *  0 = a package printed, OK
 *  1 = no suitable package available
 *  2 = error
 */

On further inspection of the source code, it appears that what is does is this:-

  • Looks at the packages in the database which are selected as "install", and are installed.

  • It then looks at the Pre-Depends information for each of these packages from the available file. When it find a package for which any of the pre-dependencies are not satisfied, it breaks from the loop through the packages.

  • It then looks through the unsatisfied pre-dependencies, and looks for packages which would satisfy this pre-dependency, stopping on the first it finds. If it finds none, it bombs out with an error.

  • It then continues this for every dependency of the initial package.

Eventually, it writes out the record of all the packages to satisfy the pre-dependencies. This is used by the disk method to make sure that its dependency ordering is correct. What happens is that all pre-depending packages are first installed, then it runs dpkg -iGROEB on the directory, which installs in the order package files are found. Since pre-dependencies mean that a package may not even be unpacked unless they are satisfied, it is necessary to do this (usually, since all the package files are unpacked in one phase, the configured in another, this is not needed).