dpkg-tech.dbk 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
  4. <!ENTITY % aptent SYSTEM "apt.ent"> %aptent;
  5. <!ENTITY % aptverbatiment SYSTEM "apt-verbatim.ent"> %aptverbatiment;
  6. <!ENTITY % aptvendor SYSTEM "apt-vendor.ent"> %aptvendor;
  7. ]>
  8. <book lang="en">
  9. <title>dpkg technical manual</title>
  10. <bookinfo>
  11. <authorgroup>
  12. <author>
  13. <personname>Tom Lees</personname><email>tom@lpsg.demon.co.uk</email>
  14. </author>
  15. </authorgroup>
  16. <releaseinfo>Version &apt-product-version;</releaseinfo>
  17. <abstract>
  18. <para>
  19. This document describes the minimum necessary workings for the APT dselect
  20. replacement. It gives an overall specification of what its external interface
  21. must look like for compatibility, and also gives details of some internal
  22. quirks.
  23. </para>
  24. </abstract>
  25. <copyright><year>1997</year><holder>Tom Lees</holder></copyright>
  26. <legalnotice>
  27. <title>License Notice</title>
  28. <para>
  29. APT and this document are free software; you can redistribute them and/or
  30. modify them under the terms of the GNU General Public License as published by
  31. the Free Software Foundation; either version 2 of the License, or (at your
  32. option) any later version.
  33. </para>
  34. <para>
  35. For more details, on Debian systems, see the file
  36. /usr/share/common-licenses/GPL for the full license.
  37. </para>
  38. </legalnotice>
  39. </bookinfo>
  40. <chapter id="ch1"><title>Quick summary of dpkg's external interface</title>
  41. <section id="control"><title>Control files</title>
  42. <para>
  43. The basic dpkg package control file supports the following major features:-
  44. </para>
  45. <itemizedlist>
  46. <listitem>
  47. <para>
  48. 5 types of dependencies:-
  49. </para>
  50. <itemizedlist>
  51. <listitem>
  52. <para>
  53. Pre-Depends, which must be satisfied before a package may be unpacked
  54. </para>
  55. </listitem>
  56. <listitem>
  57. <para>
  58. Depends, which must be satisfied before a package may be configured
  59. </para>
  60. </listitem>
  61. <listitem>
  62. <para>
  63. Recommends, to specify a package which if not installed may severely limit the
  64. usefulness of the package
  65. </para>
  66. </listitem>
  67. <listitem>
  68. <para>
  69. Suggests, to specify a package which may increase the productivity of the
  70. package
  71. </para>
  72. </listitem>
  73. <listitem>
  74. <para>
  75. Conflicts, to specify a package which must NOT be installed in order for the
  76. package to be configured
  77. </para>
  78. </listitem>
  79. <listitem>
  80. <para>
  81. Breaks, to specify a package which is broken by the package and which should
  82. therefore not be configured while broken
  83. </para>
  84. </listitem>
  85. </itemizedlist>
  86. <para>
  87. Each of these dependencies can specify a version and a depedency on that
  88. version, for example "&lt;= 0.5-1", "== 2.7.2-1", etc. The comparators
  89. available are:-
  90. </para>
  91. <itemizedlist>
  92. <listitem>
  93. <para>
  94. "&lt;&lt;" - less than
  95. </para>
  96. </listitem>
  97. <listitem>
  98. <para>
  99. "&lt;=" - less than or equal to
  100. </para>
  101. </listitem>
  102. <listitem>
  103. <para>
  104. "&gt;&gt;" - greater than
  105. </para>
  106. </listitem>
  107. <listitem>
  108. <para>
  109. "&gt;=" - greater than or equal to
  110. </para>
  111. </listitem>
  112. <listitem>
  113. <para>
  114. "==" - equal to
  115. </para>
  116. </listitem>
  117. </itemizedlist>
  118. </listitem>
  119. <listitem>
  120. <para>
  121. The concept of "virtual packages", which many other packages may provide,
  122. using the Provides mechanism. An example of this is the "httpd" virtual
  123. package, which all web servers should provide. Virtual package names may be
  124. used in dependency headers. However, current policy is that virtual packages
  125. do not support version numbers, so dependencies on virtual packages with
  126. versions will always fail.
  127. </para>
  128. </listitem>
  129. <listitem>
  130. <para>
  131. Several other control fields, such as Package, Version, Description, Section,
  132. Priority, etc., which are mainly for classification purposes. The package
  133. name must consist entirely of lowercase characters, plus the characters '+',
  134. '-', and '.'. Fields can extend across multiple lines - on the second and
  135. subsequent lines, there is a space at the beginning instead of a field name
  136. and a ':'. Empty lines must consist of the text " .", which will be ignored,
  137. as will the initial space for other continuation lines. This feature is
  138. usually only used in the Description field.
  139. </para>
  140. </listitem>
  141. </itemizedlist>
  142. </section>
  143. <section id="s1.2"><title>The dpkg status area</title>
  144. <para>
  145. The "dpkg status area" is the term used to refer to the directory where dpkg
  146. keeps its various status files (GNU would have you call it the dpkg shared
  147. state directory). This is always, on Debian systems, /var/lib/dpkg. However,
  148. the default directory name should not be hard-coded, but #define'd, so that
  149. alteration is possible (it is available via configure in dpkg 1.4.0.9 and
  150. above). Of course, in a library, code should be allowed to override the
  151. default directory, but the default should be part of the library (so that
  152. the user may change the dpkg admin dir simply by replacing the library).
  153. </para>
  154. <para>
  155. Dpkg keeps a variety of files in its status area. These are discussed later
  156. on in this document, but a quick summary of the files is here:-
  157. </para>
  158. <itemizedlist>
  159. <listitem>
  160. <para>
  161. available - this file contains a concatenation of control information from all
  162. the packages which dpkg knows about. This is updated using the dpkg commands
  163. "--update-avail &lt;file&gt;", "--merge-avail &lt;file&gt;", and
  164. "--clear-avail".
  165. </para>
  166. </listitem>
  167. <listitem>
  168. <para>
  169. status - this file contains information on the following things for every
  170. package:-
  171. </para>
  172. <itemizedlist>
  173. <listitem>
  174. <para>
  175. Whether it is installed, not installed, unpacked, removed, failed
  176. configuration, or half-installed (deconfigured in favour of another package).
  177. </para>
  178. </listitem>
  179. <listitem>
  180. <para>
  181. Whether it is selected as install, hold, remove, or purge.
  182. </para>
  183. </listitem>
  184. <listitem>
  185. <para>
  186. If it is "ok" (no installation problems), or "not-ok".
  187. </para>
  188. </listitem>
  189. <listitem>
  190. <para>
  191. It usually also contains the section and priority (so that dselect may classify
  192. packages not in available)
  193. </para>
  194. </listitem>
  195. <listitem>
  196. <para>
  197. For packages which did not initially appear in the "available" file when they
  198. were installed, the other control information for them.
  199. </para>
  200. </listitem>
  201. </itemizedlist>
  202. <para>
  203. The exact format for the "Status:" field is:
  204. </para>
  205. <screen>
  206. Status: Want Flag Status
  207. </screen>
  208. <para>
  209. Where <replaceable>Want</replaceable> may be one of
  210. <emphasis>unknown</emphasis>, <emphasis>install</emphasis>,
  211. <emphasis>hold</emphasis>, <emphasis>deinstall</emphasis>,
  212. <emphasis>purge</emphasis>. <replaceable>Flag</replaceable> may
  213. be one of <emphasis>ok</emphasis>, <emphasis>reinstreq</emphasis>,
  214. <emphasis>hold</emphasis>,
  215. <emphasis>hold-reinstreq</emphasis>. <replaceable>Status</replaceable> may
  216. be one of <emphasis>not-installed</emphasis>, <emphasis>unpacked</emphasis>,
  217. <emphasis>half-configured</emphasis>, <emphasis>installed</emphasis>,
  218. <emphasis>half-installed</emphasis> <emphasis>config-files</emphasis>,
  219. <emphasis>post-inst-failed</emphasis>, <emphasis>removal-failed</emphasis>.
  220. The states are as follows:-
  221. </para>
  222. <variablelist>
  223. <varlistentry>
  224. <term>not-installed</term>
  225. <listitem>
  226. <para>
  227. No files are installed from the package, it has no config files left, it
  228. uninstalled cleanly if it ever was installed.
  229. </para>
  230. </listitem>
  231. </varlistentry>
  232. <varlistentry>
  233. <term>unpacked</term>
  234. <listitem>
  235. <para>
  236. The basic files have been unpacked (and are listed in
  237. /var/lib/dpkg/info/[package].list. There are config files present, but the
  238. postinst script has _NOT_ been run.
  239. </para>
  240. </listitem>
  241. </varlistentry>
  242. <varlistentry>
  243. <term>half-configured</term>
  244. <listitem>
  245. <para>
  246. The package was installed and unpacked, but the postinst script failed in some
  247. way.
  248. </para>
  249. </listitem>
  250. </varlistentry>
  251. <varlistentry>
  252. <term>installed</term>
  253. <listitem>
  254. <para>
  255. All files for the package are installed, and the configuration was also
  256. successful.
  257. </para>
  258. </listitem>
  259. </varlistentry>
  260. <varlistentry>
  261. <term>half-installed</term>
  262. <listitem>
  263. <para>
  264. An attempt was made to remove the packagem but there was a failure in the
  265. prerm script.
  266. </para>
  267. </listitem>
  268. </varlistentry>
  269. <varlistentry>
  270. <term>config-files</term>
  271. <listitem>
  272. <para>
  273. The package was "removed", not "purged". The config files are left, but
  274. nothing else.
  275. </para>
  276. </listitem>
  277. </varlistentry>
  278. <varlistentry>
  279. <term>post-inst-failed</term>
  280. <listitem>
  281. <para>
  282. Old name for half-configured. Do not use.
  283. </para>
  284. </listitem>
  285. </varlistentry>
  286. <varlistentry>
  287. <term>removal-failed</term>
  288. <listitem>
  289. <para>
  290. Old name for half-installed. Do not use.
  291. </para>
  292. </listitem>
  293. </varlistentry>
  294. </variablelist>
  295. <para>
  296. The two last items are only left in dpkg for compatibility - they are
  297. understood by it, but never written out in this form.
  298. </para>
  299. <para>
  300. Please see the dpkg source code, <literal>lib/parshelp.c</literal>,
  301. <emphasis>statusinfos</emphasis>, <emphasis>eflaginfos</emphasis> and
  302. <emphasis>wantinfos</emphasis> for more details.
  303. </para>
  304. </listitem>
  305. <listitem>
  306. <para>
  307. info - this directory contains files from the control archive of every
  308. package currently installed. They are installed with a prefix of
  309. "&lt;packagename&gt;.". In addition to this, it also contains a file
  310. called &lt;package&gt;.list for every package, which contains a list
  311. of files. Note also that the control file is not copied into here; it
  312. is instead found as part of status or available.
  313. </para>
  314. </listitem>
  315. <listitem>
  316. <para>
  317. methods - this directory is reserved for "method"-specific files - each
  318. "method" has a subdirectory underneath this directory (or at least,
  319. it can have). In addition, there is another subdirectory "mnt", where
  320. misc. filesystems (floppies, CD-ROMs, etc.) are mounted.
  321. </para>
  322. </listitem>
  323. <listitem>
  324. <para>
  325. alternatives - directory used by the "update-alternatives" program. It
  326. contains one file for each "alternatives" interface, which contains
  327. information about all the needed symlinked files for each alternative.
  328. </para>
  329. </listitem>
  330. <listitem>
  331. <para>
  332. diversions - file used by the "dpkg-divert" program. Each diversion takes
  333. three lines. The first is the package name (or ":" for user diversion), the
  334. second the original filename, and the third the diverted filename.
  335. </para>
  336. </listitem>
  337. <listitem>
  338. <para>
  339. updates - directory used internally by dpkg. This is discussed later, in the
  340. section <xref linkend="updates"/>.
  341. </para>
  342. </listitem>
  343. <listitem>
  344. <para>
  345. parts - temporary directory used by dpkg-split
  346. </para>
  347. </listitem>
  348. </itemizedlist>
  349. </section>
  350. <section id="s1.3"><title>The dpkg library files</title>
  351. <para>
  352. These files are installed under /usr/lib/dpkg (usually), but
  353. /usr/local/lib/dpkg is also a possibility (as Debian policy dictates). Under
  354. this directory, there is a "methods" subdirectory. The methods subdirectory in
  355. turn contains any number of subdirectories for each general method processor
  356. (note that one set of method scripts can, and is, used for more than one of
  357. the methods listed under dselect).
  358. </para>
  359. <para>
  360. The following files may be found in each of these subdirectories:-
  361. </para>
  362. <itemizedlist>
  363. <listitem>
  364. <para>
  365. names - One line per method, two-digit priority to appear on menu at
  366. beginning, followed by a space, the name, and then another space and
  367. the short description.
  368. </para>
  369. </listitem>
  370. <listitem>
  371. <para>
  372. desc.&lt;name&gt; - Contains the long description displayed by dselect
  373. when the cursor is put over the &lt;name&gt; method.
  374. </para>
  375. </listitem>
  376. <listitem>
  377. <para>
  378. setup - Script or program which sets up the initial values to be used
  379. by this method. Called with first argument as the status area directory
  380. (/var/lib/dpkg), second argument as the name of the method (as in the
  381. directory name), and the third argument as the option (as in the names file).
  382. </para>
  383. </listitem>
  384. <listitem>
  385. <para>
  386. install - Script/program called when the "install" option of dselect is run
  387. with this method. Same arguments as for setup.
  388. </para>
  389. </listitem>
  390. <listitem>
  391. <para>
  392. update - Script/program called when the "update" option of dselect is
  393. run. Same arguments as for setup/install.
  394. </para>
  395. </listitem>
  396. </itemizedlist>
  397. </section>
  398. <section id="s1.4"><title>The "dpkg" command-line utility</title>
  399. <section id="s1.4.1"><title>"Documented" command-line interfaces</title>
  400. <para>
  401. As yet unwritten. You can refer to the other manuals for now. See
  402. <citerefentry><refentrytitle>dpkg</refentrytitle><manvolnum>8</manvolnum></citerefentry>.
  403. </para>
  404. </section>
  405. <section id="s1.4.2"><title>Environment variables which dpkg responds to</title>
  406. <itemizedlist>
  407. <listitem>
  408. <para>
  409. DPKG_NO_TSTP - if set to a non-null value, this variable causes dpkg to run a
  410. child shell process instead of sending itself a SIGTSTP, when the user selects
  411. to background the dpkg process when it asks about conffiles.
  412. </para>
  413. </listitem>
  414. <listitem>
  415. <para>
  416. SHELL - used to determine which shell to run in the case when DPKG_NO_TSTP
  417. is set.
  418. </para>
  419. </listitem>
  420. <listitem>
  421. <para>
  422. CC - used as the C compiler to call to determine the target architecture. The
  423. default is "gcc".
  424. </para>
  425. </listitem>
  426. <listitem>
  427. <para>
  428. PATH - dpkg checks that it can find at least the following files in the path
  429. when it wants to run package installation scripts, and gives an error if it
  430. cannot find all of them:-
  431. </para>
  432. <itemizedlist>
  433. <listitem>
  434. <para>
  435. ldconfig
  436. </para>
  437. </listitem>
  438. <listitem>
  439. <para>
  440. start-stop-daemon
  441. </para>
  442. </listitem>
  443. <listitem>
  444. <para>
  445. install-info
  446. </para>
  447. </listitem>
  448. <listitem>
  449. <para>
  450. update-rc.d
  451. </para>
  452. </listitem>
  453. </itemizedlist>
  454. </listitem>
  455. </itemizedlist>
  456. </section>
  457. <section id="s1.4.3"><title>Assertions</title>
  458. <para>
  459. The dpkg utility itself is required for quite a number of packages, even if
  460. they have been installed with a tool totally separate from dpkg. The reason
  461. for this is that some packages, in their pre-installation scripts, check that
  462. your version of dpkg supports certain features. This was broken from the
  463. start, and it should have actually been a control file header "Dpkg-requires",
  464. or similar. What happens is that the configuration scripts will abort or
  465. continue according to the exit code of a call to dpkg, which will stop them
  466. from being wrongly configured.
  467. </para>
  468. <para>
  469. These special command-line options, which simply return as true or false are
  470. all prefixed with "--assert-". Here is a list of them (without the prefix):-
  471. </para>
  472. <itemizedlist>
  473. <listitem>
  474. <para>
  475. support-predepends - Returns success or failure according to whether a version
  476. of dpkg which supports predepends properly (1.1.0 or above) is installed,
  477. according to the database.
  478. </para>
  479. </listitem>
  480. <listitem>
  481. <para>
  482. working-epoch - Return success or failure according to whether a version of
  483. dpkg which supports epochs in version properly (1.4.0.7 or above) is installed,
  484. according to the database.
  485. </para>
  486. </listitem>
  487. </itemizedlist>
  488. <para>
  489. Both these options check the status database to see what version of the
  490. "dpkg" package is installed, and check it against a known working version.
  491. </para>
  492. </section>
  493. <section id="s1.4.4"><title>--predep-package</title>
  494. <para>
  495. This strange option is described as follows in the source code:
  496. </para>
  497. <screen>
  498. /* Print a single package which:
  499. * (a) is the target of one or more relevant predependencies.
  500. * (b) has itself no unsatisfied pre-dependencies.
  501. * If such a package is present output is the Packages file entry,
  502. * which can be massaged as appropriate.
  503. * Exit status:
  504. * 0 = a package printed, OK
  505. * 1 = no suitable package available
  506. * 2 = error
  507. */
  508. </screen>
  509. <para>
  510. On further inspection of the source code, it appears that what is does is
  511. this:-
  512. </para>
  513. <itemizedlist>
  514. <listitem>
  515. <para>
  516. Looks at the packages in the database which are selected as "install",
  517. and are installed.
  518. </para>
  519. </listitem>
  520. <listitem>
  521. <para>
  522. It then looks at the Pre-Depends information for each of these packages
  523. from the available file. When it find a package for which any of the
  524. pre-dependencies are not satisfied, it breaks from the loop through the
  525. packages.
  526. </para>
  527. </listitem>
  528. <listitem>
  529. <para>
  530. It then looks through the unsatisfied pre-dependencies, and looks for
  531. packages which would satisfy this pre-dependency, stopping on the first
  532. it finds. If it finds none, it bombs out with an error.
  533. </para>
  534. </listitem>
  535. <listitem>
  536. <para>
  537. It then continues this for every dependency of the initial package.
  538. </para>
  539. </listitem>
  540. </itemizedlist>
  541. <para>
  542. Eventually, it writes out the record of all the packages to satisfy the
  543. pre-dependencies. This is used by the disk method to make sure that its
  544. dependency ordering is correct. What happens is that all pre-depending
  545. packages are first installed, then it runs dpkg -iGROEB on the directory,
  546. which installs in the order package files are found. Since pre-dependencies
  547. mean that a package may not even be unpacked unless they are satisfied, it
  548. is necessary to do this (usually, since all the package files are unpacked
  549. in one phase, the configured in another, this is not needed).
  550. </para>
  551. </section>
  552. </section>
  553. </chapter>
  554. <chapter id="ch2"><title>dpkg-deb and .deb file internals</title>
  555. <para>
  556. This chapter describes the internals to the "dpkg-deb" tool, which is used by
  557. "dpkg" as a back-end. dpkg-deb has its own tar extraction functions, which is
  558. the source of many problems, as it does not support long filenames, using
  559. extension blocks.
  560. </para>
  561. <section id="s2.1"><title>The .deb archive format</title>
  562. <para>
  563. The main principal of the new-format Debian archive (I won't describe the old
  564. format - for that have a look at deb-old.5), is that the archive really is an
  565. archive - as used by "ar" and friends. However, dpkg-deb uses this format
  566. internally, rather than calling "ar". Inside this archive, there are usually
  567. the following members:-
  568. </para>
  569. <itemizedlist>
  570. <listitem>
  571. <para>
  572. debian-binary
  573. </para>
  574. </listitem>
  575. <listitem>
  576. <para>
  577. control.tar.gz
  578. </para>
  579. </listitem>
  580. <listitem>
  581. <para>
  582. data.tar.gz
  583. </para>
  584. </listitem>
  585. </itemizedlist>
  586. <para>
  587. The debian-binary member consists simply of the string "2.0", indicating
  588. the format version. control.tar.gz contains the control files (and scripts),
  589. and the data.tar.gz contains the actual files to populate the filesystem
  590. with. Both tarfiles extract straight into the current directory. Information
  591. on the tar formats can be found in the GNU tar info page. Since dpkg-deb
  592. calls "tar -cf" to build packages, the Debian packages use the GNU extensions.
  593. </para>
  594. </section>
  595. <section id="s2.2"><title>The dpkg-deb command-line</title>
  596. <para>
  597. dpkg-deb documents itself thoroughly with its '--help' command-line
  598. option. However, I am including a reference to these for
  599. completeness. dpkg-deb supports the following options:-
  600. </para>
  601. <itemizedlist>
  602. <listitem>
  603. <para>
  604. --build (-b) &lt;dir&gt; - builds a .deb archive, takes a directory which
  605. contains all the files as an argument. Note that the directory
  606. &lt;dir&gt;/DEBIAN will be packed separately into the control archive.
  607. </para>
  608. </listitem>
  609. <listitem>
  610. <para>
  611. --contents (-c) &lt;debfile&gt; - Lists the contents of the "data.tar.gz"
  612. member.
  613. </para>
  614. </listitem>
  615. <listitem>
  616. <para>
  617. --control (-e) &lt;debfile&gt; - Extracts the control archive into a directory
  618. called DEBIAN. Alternatively, with another argument, it will extract it into a
  619. different directory.
  620. </para>
  621. </listitem>
  622. <listitem>
  623. <para>
  624. --info (-I) &lt;debfile&gt; - Prints the contents of the "control" file in the
  625. control archive to stdout. Alternatively, giving it other arguments will cause
  626. it to print the contents of those files instead.
  627. </para>
  628. </listitem>
  629. <listitem>
  630. <para>
  631. --field (-f) &lt;debfile&gt; &lt;field&gt; ... - Prints any number of fields
  632. from the "control" file. Giving it extra arguments limits the fields it prints
  633. to only those specified. With no command-line arguments other than a filename,
  634. it is equivalent to -I and just the .deb filename.
  635. </para>
  636. </listitem>
  637. <listitem>
  638. <para>
  639. --extract (-x) &lt;debfile&gt; &lt;dir&gt; - Extracts the data archive of a
  640. debian package under the directory &lt;dir&gt;.
  641. </para>
  642. </listitem>
  643. <listitem>
  644. <para>
  645. --vextract (-X) &lt;debfile&gt; &lt;dir&gt; - Same as --extract, except it
  646. is equivalent of giving tar the '-v' option - it prints the filenames as it
  647. extracts them.
  648. </para>
  649. </listitem>
  650. <listitem>
  651. <para>
  652. --fsys-tarfile &lt;debfile&gt; - This option outputs a gunzip'd version of
  653. data.tar.gz to stdout.
  654. </para>
  655. </listitem>
  656. <listitem>
  657. <para>
  658. --new - sets the archive format to be used to the new Debian format
  659. </para>
  660. </listitem>
  661. <listitem>
  662. <para>
  663. --old - sets the archive format to be used to the old Debian format
  664. </para>
  665. </listitem>
  666. <listitem>
  667. <para>
  668. --debug - Tells dpkg-deb to produce debugging output
  669. </para>
  670. </listitem>
  671. <listitem>
  672. <para>
  673. --nocheck - Tells dpkg-deb not to check the sanity of the control file
  674. </para>
  675. </listitem>
  676. <listitem>
  677. <para>
  678. --help (-h) - Gives a help message
  679. </para>
  680. </listitem>
  681. <listitem>
  682. <para>
  683. --version - Shows the version number
  684. </para>
  685. </listitem>
  686. <listitem>
  687. <para>
  688. --licence/--license (UK/US spellings) - Shows a brief outline of the GPL
  689. </para>
  690. </listitem>
  691. </itemizedlist>
  692. <section id="s2.2.1"><title>Internal checks used by dpkg-deb when building packages</title>
  693. <para>
  694. Here is a list of the internal checks used by dpkg-deb when building
  695. packages. It is in the order they are done.
  696. </para>
  697. <itemizedlist>
  698. <listitem>
  699. <para>
  700. First, the output Debian archive argument, if it is given, is checked using
  701. stat. If it is a directory, an internal flag is set. This check is only made
  702. if the archive name is specified explicitly on the command-line. If the
  703. argument was not given, the default is the directory name, with ".deb"
  704. appended.
  705. </para>
  706. </listitem>
  707. <listitem>
  708. <para>
  709. Next, the control file is checked, unless the --nocheck flag was specified on
  710. the command-line. dpkg-deb will bomb out if the second argument to --build was
  711. a directory, and --nocheck was specified. Note that dpkg-deb will not be able
  712. to determine the name of the package in this case. In the control file, the
  713. following things are checked:-
  714. </para>
  715. <itemizedlist>
  716. <listitem>
  717. <para>
  718. The package name is checked to see if it contains any invalid characters (see
  719. <xref linkend="control"/> for this).
  720. </para>
  721. </listitem>
  722. <listitem>
  723. <para>
  724. The priority field is checked to see if it uses standard values, and
  725. user-defined values are warned against. However, note that this check is now
  726. redundant, since the control file no longer contains the priority - the
  727. changes file now does this.
  728. </para>
  729. </listitem>
  730. <listitem>
  731. <para>
  732. The control file fields are then checked against the standard list of fields
  733. which appear in control files, and any "user-defined" fields are reported as
  734. warnings.
  735. </para>
  736. </listitem>
  737. <listitem>
  738. <para>
  739. dpkg-deb then checks that the control file contains a valid version number.
  740. </para>
  741. </listitem>
  742. </itemizedlist>
  743. </listitem>
  744. <listitem>
  745. <para>
  746. After this, in the case where a directory was specified to build the .deb file
  747. in, the filename is created as "directory/pkg_ver.deb" or
  748. "directory/pkg_ver_arch.deb", depending on whether the control file contains
  749. an architecture field.
  750. </para>
  751. </listitem>
  752. <listitem>
  753. <para>
  754. Next, dpkg-deb checks for the &lt;dir&gt;/DEBIAN directory. It complains if it
  755. doesn't exist, or if it has permissions &lt; 0755, or &gt; 0775.
  756. </para>
  757. </listitem>
  758. <listitem>
  759. <para>
  760. It then checks that all the files in this subdir are either symlinks or plain
  761. files, and have permissions between 0555 and 0775.
  762. </para>
  763. </listitem>
  764. <listitem>
  765. <para>
  766. The conffiles file is then checked to see if the filenames are too
  767. long. Warnings are produced for each that is. After this, it checks
  768. that the package provides initial copies of each of these conffiles,
  769. and that they are all plain files.
  770. </para>
  771. </listitem>
  772. </itemizedlist>
  773. </section>
  774. </section>
  775. </chapter>
  776. <chapter id="ch3"><title>dpkg internals</title>
  777. <para>
  778. This chapter describes the internals of dpkg itself. Although the low-level
  779. formats are quite simple, what dpkg does in certain cases often does not make
  780. sense.
  781. </para>
  782. <section id="updates"><title>Updates</title>
  783. <para>
  784. This describes the /var/lib/dpkg/updates directory. The function of this
  785. directory is somewhat strange, and seems only to be used internally. A
  786. function called cleanupdates is called whenever the database is scanned. This
  787. function in turn uses
  788. <citerefentry><refentrytitle>scandir</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
  789. to sort the files in this directory. Files who names do not consist entirely
  790. of digits are discarded. dpkg also causes a fatal error if any of the
  791. filenames are different lengths.
  792. </para>
  793. <para>
  794. After having scanned the directory, dpkg in turn parses each file the same way
  795. it parses the status file (they are sorted by the scandir to be in numerical
  796. order). After having done this, it then writes the status information back to
  797. the "status" file, and removes all the "updates" files.
  798. </para>
  799. <para>
  800. These files are created internally by dpkg's "checkpoint" function, and are
  801. cleaned up when dpkg exits cleanly.
  802. </para>
  803. <para>
  804. Juding by the use of the updates directory I would call it a Journal. Inorder
  805. to efficiently ensure the complete integrity of the status file dpkg will
  806. "checkpoint" or journal all of it's activities in the updates directory. By
  807. merging the contents of the updates directory (in order!!) against the original
  808. status file it can get the precise current state of the system, even in the
  809. event of a system failure while dpkg is running.
  810. </para>
  811. <para>
  812. The other option would be to sync-rewrite the status file after each operation,
  813. which would kill performance.
  814. </para>
  815. <para>
  816. It is very important that any program that uses the status file abort if the
  817. updates directory is not empty! The user should be informed to run dpkg
  818. manually (what options though??) to correct the situation.
  819. </para>
  820. </section>
  821. <section id="s3.2"><title>What happens when dpkg reads the database</title>
  822. <para>
  823. First, the status file is read. This gives dpkg an initial idea of the
  824. packages that are there. Next, the updates files are read in, overriding the
  825. status file, and if necessary, the status file is re-written, and updates files
  826. are removed. Finally, the available file is read. The available file is read
  827. with flags which preclude dpkg from updating any status information from it,
  828. though - installed version, etc., and is also told to record that the packages
  829. it reads this time are available, not installed.
  830. </para>
  831. <para>
  832. More information on updates is given above.
  833. </para>
  834. </section>
  835. <section id="s3.3"><title>How dpkg compares version numbers</title>
  836. <para>
  837. Version numbers consist of three parts: the epoch, the upstream version, and
  838. the Debian revision. Dpkg compares these parts in that order. If the epochs
  839. are different, it returns immediately, and so on.
  840. </para>
  841. <para>
  842. However, the important part is how it compares the versions which are
  843. essentially stored as just strings. These are compared in two distinct
  844. parts: those consisting of numerical characters (which are evaluated, and
  845. then compared), and those consisting of other characters. When comparing
  846. non-numerical parts, they are compared as the character values (ASCII),
  847. but non-alphabetical characters are considered "greater than" alphabetical
  848. ones. Also note that longer strings (after excluding differences where
  849. numerical values are equal) are considered "greater than" shorter ones.
  850. </para>
  851. <para>
  852. Here are a few examples of how these rules apply:-
  853. </para>
  854. <screen>
  855. 15 &gt; 10
  856. 0010 == 10
  857. d.r &gt; dsr
  858. 32.d.r == 0032.d.r
  859. d.rnr &lt; d.rnrn
  860. </screen>
  861. </section>
  862. </chapter>
  863. </book>