programmer.sgml 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. <!doctype linuxdoc system>
  2. <!--
  3. Debian Linux dpkg package installation tool.
  4. Programmers' manual.
  5. Copyright (C)1996 Ian Jackson; released under the terms of the GNU
  6. General Public License, version 2 or (at your option) any later.
  7. -->
  8. <article>
  9. <title><tt/dpkg/ Programmers' manual
  10. <author>Ian Jackson, <tt/ijackson@gnu.ai.mit.edu/
  11. <date>1st June 1996
  12. <abstract>
  13. This manual describes the technical aspects of creating Debian binary
  14. packages. It describes how to use utilities like <tt/install-info/.
  15. It also documents the interface between <tt/dselect/ and its access
  16. method scripts. It does not deal with the Debian Project policy
  17. requirements, and it assumes familiarity with <tt/dpkg/'s functions
  18. from the system administrator's perspective.
  19. </abstract>
  20. <toc>
  21. <!-- Describes the technical interface between a package and dpkg.
  22. Control file fields and their syntax and semantics. How to use
  23. update-rc.d, diversions, update-alternatives, install-info in a
  24. package. How to safely put shared libraries in a package. Details of
  25. dpkg's handling of individual files. Semantics of virtual packages.
  26. Sections on when to use which feature (eg Replaces
  27. vs. Replaces/Conflicts vs. update-alternatives vs. diversions)
  28. Cross-references to the policy document (see below) where appropriate.
  29. Description of the interface between dselect and its access methods.
  30. Hints on where to start with a new package (ie, the hello package).
  31. -->
  32. <sect>Scope of this manual
  33. This manual describes the technical aspects of creating Debian binary
  34. packages (<tt/.deb/ files.). It documents the behaviour of the
  35. package management programs <tt/dpkg/, <tt/dselect/ et al and and the
  36. way they interact with packages.
  37. <p>
  38. It documents the utility programs which are provided with <tt/dpkg/
  39. for managing various system configuration and similar issues (such as
  40. <tt/update-rc.d/ and <tt/install-info/.
  41. <p>
  42. It also documents the interaction between <tt/dselect/'s core and the
  43. access method scripts it uses to actually install the selected
  44. packages, and describes how to create a new access method.
  45. <p>
  46. It does <em/not/ describe the policy requirements imposed on Debian
  47. packages, such as the permissions on files and directories,
  48. documentation requirements, upload procedure, and so on. You should
  49. see the Debian packaging policy manual for these details. (Many of
  50. them will probably turn out to be helpful even if you don't plan to
  51. upload your package and make it available as part of the
  52. distribution.)
  53. <p>
  54. It is assumed that the reader is reasonably familiar with the
  55. <tt/dpkg/ System Administrators' manual.
  56. <p>
  57. The Debian version of the FSF's GNU hello program is provided as an
  58. example for people wishing to create Debian packages.
  59. <p>
  60. <em>Note that this document is not yet complete !</em>
  61. <sect>Binary package format
  62. <tt/dpkg/ is a suite of programs for creating binary package files and
  63. installing and removing them on Unix systems.<footnote><tt/dpkg/ is
  64. targetted primarily at Debian Linux, but may work or be ported to
  65. other systems.</footnote>
  66. <p>
  67. The binary package files' contents may be architecture-independent,
  68. but they usually aren't. They aren't designed for the management of
  69. program source code (though examples of this are provided as part of
  70. some packages by way of documentation).
  71. <p>
  72. The binary package has two main sections: the first part consists of
  73. various control information files and scripts used by <tt/dpkg/ when
  74. installing and removing, and the second part is an archive (currently
  75. a <tt/tar/ archive) containing files and directories to be installed.
  76. In the future binary packages may also contain other components, such
  77. as checksums and digital signatures.
  78. <p>
  79. The control information files are described in <ref id="controlarea"
  80. name="the control information section">.
  81. <sect1>Creating package files -- <tt/dpkg-deb/
  82. All manipulation of binary package files is done by <tt/dpkg-deb/;
  83. it's the only program that has knowledge of the format.
  84. (<tt/dpkg-deb/ may be invoked by calling <tt/dpkg/, as <tt/dpkg/ will
  85. spot that the options requested are appropriate to <tt/dpkg-deb/ and
  86. invoke that instead with the same arguments.)
  87. <p>
  88. In order to create a binary package you must make a directory tree
  89. which contains all the files and directories you want to have in the
  90. filesystem data part of the package.
  91. <p>
  92. They should have the locations (relative to the root of the directory
  93. tree you're constructing) ownerships and permissions which you want
  94. them to have on the system when they are installed.
  95. <p>
  96. With current versions of <tt/dpkg/ the uid/username and gid/groupname
  97. mappings for the users and groups being used should be the same on the
  98. system where the package is built and the one where it is installed.
  99. <p>
  100. You need to add one special directory to the root of the miniature
  101. filesystem tree you're creating: <tt/DEBIAN/. It should contain the
  102. control information files, notably the main package control file (see
  103. <ref id="controlarea" name="later"> for details of what files to put
  104. here.
  105. <p>
  106. The <tt/DEBIAN/ directory will not appear in the filesystem archive of
  107. the package, and so won't be installed by <tt/dpkg/ when the package
  108. is installed.
  109. <p>
  110. When you've prepared the package, you should invoke:<!--var-->
  111. <tscreen><verb>
  112. dpkg --build <it/directory/
  113. </verb></tscreen>
  114. <p>
  115. This will build the package in <var/directory/<tt/.deb/.
  116. (<tt/dpkg/ knows that <tt/--build/ is a <tt/dpkg-deb/ option, so it
  117. invokes <tt/dpkg-deb/ with the same arguments to build the package.)
  118. <p>
  119. See the manpage for <tt/dpkg-deb/ for details of how to examine the
  120. contents of this newly-created file. You may find the output of
  121. following commands enlightening:
  122. <tscreen><verb>
  123. dpkg-deb --info <var/filename/<tt/.deb/
  124. dpkg-deb --contents <var/filename/<tt/.deb/
  125. </verb></tscreen>
  126. <sect1>Package control information files<label id="controlarea">
  127. The control information portion of a binary package is a collection of
  128. files with names known to <tt/dpkg/. It will treat the contents of
  129. these files specially - some of them contain information used by
  130. <tt/dpkg/ when installing or removing the package; others are scripts
  131. which the package maintainer wants <tt/dpkg/ to run.
  132. <p>
  133. It is possible to put other files in the package control area, but
  134. this is not generally a good idea (though they will largely be
  135. ignored).
  136. <p>
  137. Here is a brief list of the control info files supported by <tt/dpkg/
  138. and a summary of what they're used for.
  139. <descrip>
  140. <tag/<tt/control//
  141. This is the key description file used by <tt/dpkg/. It specifies the
  142. package's name and version, gives its description for the user, states
  143. its relationships with other packages, and so forth. Its format is
  144. described in more detail in <ref id="controlfile"
  145. name="its own section">.
  146. <tag><tt/postinst/, <tt/preinst/, <tt/postrm/, <tt/prerm/</tag>
  147. These are exectuable files (usually scripts) which <tt/dpkg/ runs
  148. during installation, upgrade and removal of packages. They allow the
  149. package to deal with matters which are particular to that package or
  150. require more complicated processing than that provided by <tt/dpkg/.
  151. Details of when and how they are called are in <ref
  152. id="maintainerscripts">.
  153. <tag/<tt/conffiles//
  154. This file contains a list of configuration files which are to be
  155. handled automatically by <tt/dpkg/. Details of this mechanism are in
  156. <ref id="conffiles" name="a separate section">. Note that not all a
  157. package's configuration files should be listed here.
  158. </descrip>
  159. <sect1>The main control information file: <tt/control/<label id="controlfile">
  160. The most important control information file used by <tt/dpkg/ when it
  161. installs a package is <tt/control/. It contains all the package's
  162. `vital statistics'.
  163. <p>
  164. It is a series of fields and values; each field consists of a name,
  165. followed by a colon and the value. It ends at the end of the line.
  166. Horizontal whitespace (spaces and tabs) may occur before or after the
  167. value and is ignored there; it is conventional to put a single space
  168. after the colon. Many of the fields have a syntax where whitespace is
  169. not significant.
  170. <p>
  171. Some fields' values may span several lines; in this case each
  172. continuation line <em/must/ start with a space or tab. Any trailing
  173. spaces or tabs at the end of individual lines of a field value are
  174. ignored.
  175. <p>
  176. Field names are not case-sensitive, but it is usual to capitalise the
  177. fields as shown below (usually using a form of mixed case).
  178. <p>
  179. Blank lines, or lines consisting only of spaces and tabs, are not allowed.
  180. <p>
  181. Here is a list of the fields which are permitted in packages, together
  182. with a description of the purposes and syntax of each and or a pointer
  183. to further information if appropriate.
  184. <p>
  185. It is important to note that there are several fields which are
  186. optional as far as <tt/dpkg/ is concerned, but which must appear in
  187. every Debian package, or whose omission may cause problems. When
  188. writing the control file for a Debian package you <em/must/ read the
  189. Debian policy manual in conjuction with the list below.
  190. <sect2>List of package control file fields
  191. <p>
  192. <descrip>
  193. <tag/<tt/Package//
  194. The name of the package. Package names consist of the alphanumerics,
  195. plus, minus and dot. They must be at least two characters and must
  196. start with an alphanumeric. In current versions of dpkg they are sort
  197. of case-sensitive; use lowercase package names unless the package
  198. you're building (or referring to, in other fields) is already using
  199. uppercase.
  200. <p>
  201. This field is mandatory.
  202. <tag/<tt/Version//
  203. This lists the package's version number. See the section on version
  204. numbers <ref id="versions" name="later"> for details.
  205. This field is mandatory.
  206. <tag/<tt/Architecture//
  207. This is the architecture string; it is a single word for the CPU
  208. architecture, and <tt/dpkg/ will check it against its own compiled-in
  209. value before it installs a package. The special value <tt/all/
  210. indicates that the package is architecture-independent.
  211. <p>
  212. The value for this field can be obtained using
  213. <tscreen><verb>
  214. dpkg --print-architecture
  215. </verb></tscreen>
  216. This actually invokes
  217. <tscreen><verb>
  218. gcc --print-libgcc-file-name
  219. </verb></tscreen>
  220. and parses and decomposes the output and looks the CPU type from the
  221. GCC configuration in a table in <tt/dpkg/. This is so that it will
  222. work if you're cross-compiling.
  223. <p>
  224. There is a separate option, <tt/--print-installation-architecture/,
  225. for finding out what architecture <tt/dpkg/ is willing to install.
  226. This information is also in the output of <tt/dpkg --version/.
  227. <p>
  228. This field should appear in all packages, though <tt/dpkg/ doesn't
  229. require it yet so that old packages can still be installed.
  230. <tag/<tt/Maintainer//
  231. The package maintainer's name and email address. The name should come
  232. first, then the email address inside angle brackets <tt/&lt;&gt/ (in
  233. RFC822 format).
  234. <p>
  235. If the maintainer's name contains a full stop then the whole field
  236. will not work directly as an email address due to a misfeature in the
  237. syntax for addresses; a program using this field as an address must
  238. check for this and reverse the components if necessary (for example by
  239. putting the name in round brackets or quotes, and perhaps moving it to
  240. the end).
  241. This feature is optional as far as <tt/dpkg/ is concerned, but
  242. <tt/dpkg-deb/ will warn if it is missing.
  243. <tag><tt/Depends/, <tt/Pre-Depends/, <tt/Recommends/, <tt/Suggests/
  244. <tt/Conflicts/, <tt/Provides/, <tt/Replaces/</tag>
  245. These fields describe the package's relationships with other packages.
  246. Their syntax and semantics are described in the package relationships
  247. section <ref id="depconoverwr" name="later">.
  248. <tag/<tt/Source//
  249. This field identifies the source package name, primarily for the
  250. benefit of humans reading the control file rather than <tt/dpkg/. It
  251. consists solely of the source package name; it may be omitted when the
  252. source package has the same name as the binary package.
  253. This field is optional as far as <tt/dpkg/ is concerned.
  254. <tag/<tt/Description//
  255. This field contains a description of the package, in a special format.
  256. <p>
  257. It is very important that you read the section <ref id="descriptions"
  258. name="later"> on how to write a description.
  259. <tag/<tt/Essential//
  260. This is a boolean field. If set to <tt/yes/ then <tt/dpkg/ and
  261. <tt/dselect/ will refuse to remove the package (though it can be
  262. upgraded and/or replaced). The other possible value is <tt/no/, which
  263. is the same as not having the field at all.
  264. <p>
  265. This field is optional.
  266. <tag/<tt/Priority//
  267. This specifies the `priority' of the package; this represents how
  268. important that it is that the user have it installed.
  269. <p>
  270. This value isn't used by <tt/dpkg/, but only by <tt/dselect/ when it
  271. sorts packages and selects defaults. See the <tt/dpkg/ System
  272. Administrator's Manual for details of the values it can take, and the
  273. Debian Policy Manual for the criteria for selecting the priority for a
  274. Debian package.
  275. <p>
  276. <tt/dpkg/ and <tt/dselect/ will only use the value from a <tt/.deb/
  277. file if they have no other information; a priority value listed in a
  278. <tt/Packages/ file will always take precedence. This field is
  279. optional as far as <tt/dpkg/ is concerned.
  280. <tag/<tt/Section//
  281. This specifies the `section' of the package, namely the application
  282. area or group of packages which contain it. The value is a simple
  283. string, usually from a set chosen by the distribution maintainers.
  284. <p>
  285. The section isn't used at all except by <tt/dselect/, which only uses
  286. it for sorting packages in the selection display and not even for
  287. choosing defaults.
  288. <p>
  289. Just as with <tt/Priority/, this field is optional as far as <tt/dpkg/
  290. is concerned, and the value from a package file is used only as a last
  291. resort.
  292. </descrip>
  293. <sect2>List of other control fields
  294. There are several other fields which are used elsewhere by parts of
  295. the system. These should not appear in package control files.
  296. <sect3>Status fields
  297. These fields appear in <tt/dpkg/'s internal status file; they are also
  298. printed by <tt/dpkg --status/ and can be seen in <tt/dselect/ by
  299. selecting the installed control info display.
  300. <p>
  301. <descrip>
  302. <tag/<tt/Status//
  303. This field in <tt/dpkg/'s status file records whether the user wants a
  304. package installed, removed or left alone, whether it is broken
  305. (requiring reinstallation) or not and what its current state on the
  306. system is. Each of these pieces of information is a single word.
  307. <tag/<tt/Config-Version//
  308. If a package is not installed or not configured, this field in
  309. <tt/dpkg/'s status file records the last version of the package which
  310. was successfully configured.
  311. <tag/<tt/Conffiles//
  312. This field in <tt/dpkg/'s status file contains information about the
  313. automatically-managed configuration files held by a package. Let me
  314. emphasise that this field should <em/not/ appear in a package !
  315. </descrip>
  316. <sect4><tt/Packages/ file (available package) fields
  317. These fields are found in <tt/Packages/ files (lists of packages
  318. available for installation, which are generated by the distribution
  319. maintainers and used principally by <tt/dselect/) and in <tt/dpkg/'s
  320. database of available packages (which can be inspected using
  321. <tt/dpkg --print-avail/ or by selecting the `available control
  322. information' in <tt/dselect/.
  323. <p>
  324. <descrip>
  325. <tag><tt/Filename/, <tt/MSDOS-Filename/</tag>
  326. These fields in <tt/Packages/ files give the filename(s) of (the parts
  327. of) a package in the distribution directories, relative to the root of
  328. the Debian hierarchy. If the package has been split into several
  329. parts the parts are all listed in order, separated by spaces.
  330. <tag><tt/Size/, <tt/MD5sum/</tag>
  331. These fields in <tt/Packages/ files give the size (in bytes, expressed
  332. in decimal) and MD5 checksum of the file(s) which make(s) up a binary
  333. package in the distribution. If the package is split into several
  334. parts the values for the parts are listed in order, separated by
  335. spaces.
  336. </descrip>
  337. <sect4>Obsolete fields
  338. These are still recognised by <tt/dpkg/ but should not appear anywhere
  339. any more.
  340. <p><descrip>
  341. <tag><tt/Revision/, <tt/Package-Revision/, <tt/Package_Revision/</tag>
  342. The Debian revision part of the package version was at one point in a
  343. separate control file field. This field went through several names.
  344. <tag/Recommended/ Old name for <tt/Recommends/.
  345. <tag/Optional/ Old name for <tt/Suggests/.
  346. <tag/Class/ Old name for <tt/Priority/.
  347. </descrip>
  348. <sect1>Version numbering<label id="versions">
  349. Every package has a version number, in its <tt/Version/ control file
  350. field.
  351. <p>
  352. <tt/dpkg/ imposes an ordering on version numbers, so that it can tell
  353. whether packages are being up- or downgraded and so that <tt/dselect/
  354. can tell whether a package it finds available is newer than the one
  355. installed on the system. The version number format has the most
  356. significant parts (as far as comparison is concerned) at the
  357. beginning.
  358. <p>
  359. The version number format is:
  360. &lsqb<var/epoch/<tt/:/&rsqb;<var/upstream-version/&lsqb;<tt/-/<var/debian-revision/&rsqb;.
  361. <p>
  362. The three components here are:
  363. <descrip>
  364. <tag/<var/epoch//
  365. This is a single unsigned integer, which should usually be small. It
  366. may be omitted, in which case it defaults to zero. If it is omitted
  367. then the <var/upstream-version/ may not contain any colons.
  368. <p>
  369. It is provided to allow mistakes in the version numbers of older
  370. versions of a package, and also a package's previous version numbering
  371. schemes, to be left behind.
  372. <p>
  373. <tt/dpkg/ will not usually display the epoch unless it is essential
  374. (non-zero, or if the <var/upstream-version/ contains a colon);
  375. <tt/dselect/ does not display epochs at all in the main part of the
  376. package selection display.
  377. <tag/<var/upstream-version//
  378. This is the main part of the version. It is usually version number of
  379. the original (`upstream') package of which the <tt/.deb/ file has been
  380. made, if this is applicable. Usually this will be in the same format
  381. as that specified by the upstream author(s); however, it may need to
  382. be reformatted to fit into <tt/dpkg/'s format and comparison scheme.
  383. <p>
  384. The comparison behaviour of <tt/dpkg/ with respect to the
  385. <var/upstream-version/ is described below. The <var/upstream-version/
  386. portion of the version number is mandatory.
  387. <tag/<var/debian-revision//
  388. This part of the version represents the version of the modifications
  389. that were made to the package to make it a Debian binary package. It
  390. is in the same format as the <var/upstream-version/ and <tt/dpkg/
  391. compares it in the same way.
  392. <p>
  393. It is optional; if it isn't present then the <var/upstream-version/
  394. should not contain a hyphen. This format represents the case where a
  395. piece of software was written specifically to be turned into a Debian
  396. binary package, and so there is only one `debianization' of it and
  397. therefore no version indication is require there.
  398. <p>
  399. It is conventional to restart the <var/debian-revision/ at <tt/1/ each
  400. time the <var/upstream-version/ is increased.
  401. <p>
  402. <tt/dpkg/ will break the <var/upstream-version/ and
  403. <var/debian-revision/ apart at the last hyphen in the string. The
  404. absence of a <var/debian-revision/ compares earlier than the presence
  405. of one (but note that the <var/debian-revision/ is the least
  406. significant part of the version number).
  407. </descrip>
  408. The <var/upstream-version/ and <var/debian-revision/ parts are
  409. compared by <tt/dpkg/ using the same algorithm:
  410. <p>
  411. The strings are compared from left to right.
  412. <p>
  413. First the initial part of each string consisting entirely of non-digit
  414. characters is determined. These two parts (one of which may be empty)
  415. are compared lexically. If a difference is found it is returned. The
  416. lexical comparison is a comparison of ASCII values modified so that
  417. all the letters sort earlier than all the non-letters.
  418. <p>
  419. Then the initial part of the remainder of each string which consists
  420. entirely of digit characters is determined. The numerical values of
  421. these two parts are compared, and any difference found is returned as
  422. the result of the comparison. For these purposes an empty string
  423. (which can only occur at the end of one or both version strings being
  424. compared) counts as zero.
  425. <p>
  426. These two steps are repeated (chopping initial non-digit strings and
  427. initial digit strings off from the start) until a difference is found
  428. or both strings are exhausted.
  429. <p>
  430. Note that the purpose of epochs is to allow us to leave behind
  431. mistakes in version numbering, and to cope with situations where the
  432. version numbering changes. It is <em/not/ there to cope with version
  433. numbers containing strings of letters which <tt/dpkg/ cannot interpret
  434. (such as <tt/ALPHA/ or <tt/pre-/), or with silly orderings (the author
  435. of this manual has heard of a package whose versions went <tt/1.1/,
  436. <tt/1.2/, <tt/1.3/, <tt/1/, <tt/2.1/, <tt/2.2/, <tt/2/ and so forth).
  437. <p>
  438. If an upstream package has problematic version numbers they should be
  439. converted to a sane form for use in the <tt/Version/ field.
  440. <sect1>Package maintainer scripts run by <tt/dpkg/<label id="maintainerscripts">
  441. It is possible supply scripts as part of a package which <tt/dpkg/
  442. will run for you when your package is installed, upgraded or removed.
  443. <p>
  444. These scripts should be the files <tt/preinst/, <tt/postinst/,
  445. <tt/prerm/ and <tt/postrm/ in the control area of the package. They
  446. should be proper exectuable files, so that if they are scripts (which
  447. is to be recommended) they must start with the usual <tt/#!/
  448. convention. They should be readable and executable to anyone, and not
  449. world-writeable.
  450. <p>
  451. <tt/dpkg/ looks at the exit status from these scripts. It is
  452. important that they exit with a non-zero status if there is an error,
  453. so that <tt/dpkg/ can stop its processing. For shell scripts this
  454. means that you <em/almost always/ need to use <tt/set -e/ (this is
  455. usually true when writing shell scripts, in fact). It is also
  456. important, of course, that they don't exit with a non-zero status if
  457. everything went well.
  458. <p>
  459. It is necessary for the error recovery procedures that the scripts be
  460. idempotent: ie, invoking the same script several times in the same
  461. situation should do no harm. If the first call failed, or aborted
  462. half way through for some reason, the second call should merely do the
  463. things that were left undone the first time, if any, and exit with a
  464. success status.
  465. <p>
  466. When a package is upgraded a combination of the scripts from the old
  467. and new packages is called in amongst the other steps of the upgrade
  468. procedure. If your scripts are going to be at all complicated you
  469. need to be aware of this, and may need to check the arguments to your
  470. scripts.
  471. <p>
  472. Broadly speaking the <tt/preinst/ is called before (a particular
  473. version of) a package is installed, and the <tt/postinst/ afterwards;
  474. the <tt/prerm/ before (a version of) a package is removed and the
  475. <tt/postrm/ afterwards.
  476. <p>
  477. See <ref id="maintscripts-instact" name="later"> for details of
  478. exactly when and how these scripts are called and with what arguments.
  479. <sect>Declaring relationships between packages<label id="depconoverwr">
  480. Packages can declare in their control file that they have certain
  481. relationships to other packages - for example, that they may not be
  482. installed at the same time as certain other packages, and/or that they
  483. depend on the presence of others.
  484. <p>
  485. This is done using the <tt/Depends/, <tt/Recommends/, <tt/Suggests/,
  486. <tt/Conflicts/, <tt/Provides/ and <tt/Replaces control file fields.
  487. <p>
  488. <sect>Syntax of relationship fields
  489. These fields all have a uniform syntax. They are a list of package
  490. names separated by commas.
  491. <p>
  492. In <tt/Depends/, <tt/Recommends/, <tt/Suggests/ and <tt/Pre-Depends/
  493. (the fields which declare dependencies of the package in which they
  494. occur on other packages) these package names may also be lists of
  495. alternative package names, separated by vertical bar symbols <tt/|/
  496. (pipe symbols).
  497. <p>
  498. All the fields except <tt/Provides/ may restrict their applicability
  499. to particular versions of each named package. This is done in
  500. parentheses after each individual package name; the parentheses should
  501. contain a relation from the list below followed by a version number,
  502. in the format described in <ref id="versions" name="the version number
  503. section, above">.
  504. <p>
  505. The relations allowed are
  506. <tt/&lt;&lt;/,
  507. <tt/&lt;=/,
  508. <tt/=/,
  509. <tt/&gt;=/ and
  510. <tt/&gt;&gt;/
  511. for strictly earlier, earlier or equal, exactly equal, later or equal
  512. and strictly later, respectively. The forms <tt/&lt;/ and <tt/&gt;/
  513. were used to mean earlier/later or equal, rather than strictly
  514. earlier/later, and so (while <tt/dpkg/ still supports them) they
  515. should not appear in new packages.
  516. <p>
  517. Whitespace may appear at any point in the version specification, and
  518. must appear where it's necessary to disambiguate; it is not otherwise
  519. significant. For consistency and in case of future changes to
  520. <tt/dpkg/ it is recommended that a single space be used after a
  521. version relationship and before a version number; it is usual also to
  522. put a single space after each comma, on either side of each vertical
  523. bar, and before each open parenthesis.
  524. <sect1>Dependencies - <tt/Depends/, <tt/Recommends/, <tt/Suggests/, <tt/Pre-Depends/
  525. These three fields are used to declare a dependency by one package on
  526. another. They appear in the depending package's control file.
  527. <p>
  528. All but <tt/Pre-Depends/ (discussed below) take effect <em/only/ when
  529. a package is to be configured. They do not prevent a package being on
  530. the system in an unconfigured state while its dependencies are
  531. unsatisfied, and it is possible to replace a package whose
  532. dependencies are satisfied and which is properly installed with a
  533. different version whose dependencies are not and cannot be satisfied;
  534. when this is done the depending package will be left unconfigured
  535. (since attempts to configure it will give errors) and will not
  536. function properly.
  537. <p>
  538. For this reason packages in an installation run are usually all
  539. unpacked first and all configured later; this gives later versions of
  540. packages with dependencies on later versions of other packages the
  541. opportunity to have their dependencies satisfied.
  542. <descrip>
  543. <tag/<tt/Depends//
  544. This declares an absolute dependency.
  545. <p>
  546. <tt/dpkg/ will not configure
  547. packages whose dependencies aren't satisfied. If it is asked to make
  548. an installation which would cause an installed package's dependencies
  549. to become unsatisfied it will complain<footnote>Current versions
  550. (1.2.4) of <tt/dpkg/ have a bug in this area which will cause some of
  551. these problems to be ignored.</footnote>, unless
  552. <tt/--auto-deconfigure/ is specified, in which case those packages
  553. will be deconfigured before the installation proceeds.
  554. <p>
  555. <tt/dselect/ makes it hard for the user to select packages for
  556. installation, removal or upgrade in a way that would mean that
  557. packages' <tt/Depends/ fields would be unsatisfied. The user can
  558. override this if they wish, for example if they know that <tt/dselect/
  559. has an out-of-date view of the real package relationships.
  560. **** WHEN TO USE -- POLICY STATEMENT HERE ?
  561. <tag/<tt/Recommends//
  562. This declares a strong, but not absolute, dependency.
  563. <p>
  564. <tt/Recommends/ is ignored by <tt/dpkg/, so that users using the
  565. command-line (who are presumed to know what they're doing) will not be
  566. impeded.
  567. <p>
  568. It is treated by <tt/dselect/ exactly as <tt/Depends/ is; this makes
  569. it hard for the user to select things so as to leave <tt/Recommends/
  570. fields unsatisfied, but they are able to do so by being persistent.
  571. **** WHEN TO USE -- POLICY STATEMENT HERE ?
  572. <tt/<tt/Suggests//
  573. This declares a
  574. **** WRITE THIS
  575. <sect1>Alternative packages - <tt/Conflicts/
  576. **** WRITE THIS
  577. <sect1>Virtual packages - <tt/Provides/
  578. **** WRITE THIS
  579. <sect1>Overwriting files - <tt/Replaces/
  580. **** WRITE THIS
  581. <tt/&lt;&lt;/
  582. <tt/&lt;&lt;/
  583. <tt/&lt;&lt;/
  584. <descrip>
  585. <tag>&lt
  586. <sect>Order of processing steps and maintainer script arguments<label id="maintscripts-instact">
  587. <sect1>Summary of ways maintainer scripts are called
  588. <p>
  589. <itemize>
  590. <item><var/new preinst/ <tt/install/
  591. <item><var/new preinst/ <tt/install/ <var/old-version/
  592. <item><var/new preinst/ <tt/upgrade/ <var/old-version/
  593. <item><var/old preinst/ <tt/abort-upgrade/ <var/new-version/
  594. </itemize>
  595. <itemize>
  596. <item><var/postinst/ <tt/configure/ <var/most-recently-configured-version/
  597. <item><var/old-postinst/ <tt/abort-upgrade/ <var/new version/
  598. <item><var/conflictor's-postinst/ <tt/abort-remove/
  599. in-favour <var/package/ <var/new-version/
  600. <item><var/deconfigured's-postinst/ <tt/abort-deconfigure/
  601. <tt/in-favour/ <var/failed-install-package/ <var/version/
  602. <tt/removing/ <var/conflicting-package/ <var/version/
  603. </itemize>
  604. <itemize>
  605. <item><var/prerm/ <tt/remove/
  606. <item><var/old-prerm/ <tt/upgrade/ <var/new-version/
  607. <item><var/new-prerm/ <tt/failed-upgrade/ <var/old-version/
  608. <item><var/conflictor's-prerm/ <tt/remove/ <tt/in-favour/
  609. <var/package/ <var/new-version/
  610. <item><var/deconfigured's-prerm/ <tt/deconfigure/
  611. <tt/in-favour/ <var/package-being-installed/ <var/version/
  612. <tt/removing/ <var/conflicting-package/ <var/version/
  613. </itemize>
  614. <itemize>
  615. <item><var/postrm/ <tt/remove/
  616. <item><var/postrm/ <tt/purge/
  617. <item><var/old-postrm/ <tt/upgrade/ <var/new-version/
  618. <item><var/new-postrm/ <tt/failed-upgrade/ <var/old-version/
  619. <item><var/new-postrm/ <tt/abort-install/
  620. <item><var/new-postrm/ <tt/abort-install/ <var/old-version/
  621. <item><var/new-postrm/ <tt/abort-upgrade/ <var/old-version/
  622. <item><var/disappearer's-postrm/ <tt/disappear/ <var/overwriter/ <var/new-version/
  623. </itemize>
  624. <sect1>Details of unpack phase of installation or upgrade
  625. <p>
  626. The procedure on installation/upgrade/overwrite/disappear (ie, when
  627. running <tt/dpkg --unpack/, or the unpack stage of <tt/dpkg
  628. --install/) is as follows. In each case if an error occurs the
  629. actions in are general run backwards - this means that the maintainer
  630. scripts are run with different arguments in reverse order. These are
  631. the `error unwind' calls listed below.
  632. <enum>
  633. <item>
  634. <enum>
  635. <item>
  636. If a version the package is already
  637. installed, call
  638. <tscreen><verb>
  639. <var/old-prerm/ <tt/upgrade/ <var/new-version/
  640. </verb></tscreen>
  641. <item>
  642. If this gives an error (ie, a non-zero exit status), dpkg will
  643. attempt instead:
  644. <tscreen><verb>
  645. <var/new-prerm/ <tt/failed-upgrade/ <var/old-version/
  646. </verb></tscreen>
  647. Error unwind, for both the above cases:
  648. <tscreen><verb>
  649. <var/old-postinst/ <tt/abort-upgrade/ <var/new-version/
  650. </verb></tscreen>
  651. </enum>
  652. <item>
  653. If a `conflicting' package is being removed at the same time:
  654. <enum>
  655. <item>
  656. If any packages depended on that conflicting package and
  657. <tt/--auto-deconfigure/ is specified, call, for each such package:
  658. <tscreen><verb>
  659. <var/deconfigured's-prerm/ <tt/deconfigure/
  660. <tt/in-favour/ <var/package-being-installed/ <var/version/
  661. <tt/removing/ <var/conflicting-package/ <var/version/
  662. </verb></tscreen>
  663. Error unwind:
  664. <tscreen><verb>
  665. <var/deconfigured's-postinst/ <tt/abort-deconfigure/
  666. <tt/in-favour/ <var/package-being-installed-but-failed/ <var/version/
  667. <tt/removing/ <var/conflicting-package/ <var/version/
  668. </verb></tscreen>
  669. The deconfigured packages are marked as requiring configuration, so
  670. that if <tt/--install/ is used they will be configured again if
  671. possible.
  672. <item>
  673. To prepare for removal of the conflicting package, call:
  674. <tscreen><verb>
  675. <var/conflictor's-prerm/ <tt/remove/
  676. <tt/in-favour/ <var/package/ <var/new-version/
  677. </verb></tscreen>
  678. Error unwind:
  679. <tscreen><verb>
  680. <var/conflictor's-postinst/ <tt/abort-remove/
  681. <tt/in-favour/ <var/package/ <var/new-version/
  682. </verb></tscreen>
  683. </enum>
  684. <item>
  685. <enum>
  686. <item>
  687. If the package is being upgraded, call:
  688. <tscreen><verb>
  689. <var/new-preinst/ <tt/upgrade/ <var/old-version/
  690. </verb></tscreen>
  691. <item>
  692. Otherwise, if the package had some configuration files from a previous
  693. version installed (ie, it is in the `configuration files only' state):
  694. <tscreen><verb>
  695. <var/new-preinst/ <tt/install/ <var/old-version/
  696. </verb></tscreen>
  697. <item>
  698. Otherwise (ie, the package was completely purged):
  699. <tscreen><verb>
  700. <var/new-preinst/ <tt/install/
  701. </verb></tscreen>
  702. Error unwind versions, respectively:
  703. <tscreen><verb>
  704. <var/new-postrm/ <tt/abort-upgrade/ <var/old-version/
  705. <var/new-postrm/ <tt/abort-install/ <var/old-version/
  706. <var/new-postrm/ <tt/abort-install/
  707. </verb></tscreen>
  708. </enum>
  709. <item>
  710. The new package's files are unpacked, overwriting any that may be on
  711. the system already, for example any from the old version of the same
  712. package or from another package (backups of the old files are left
  713. around, and if anything goes wrong dpkg will attempt to put them back
  714. as part of the error unwind).
  715. <p>
  716. It is an error for a package to contains files which are on the system
  717. in another package, unless <tt/Replaces/ is used (see <ref
  718. id="replaces" name="earlier">). Currently the <tt/--force-overwrite/
  719. flag is enabled, downgrading it to a warning, but this will not always
  720. be the case.
  721. <p>
  722. Packages which overwrite each other's files produce behaviour which
  723. (though deterministic) is hard for the system administrator to
  724. understand and can easily lead to `missing' programs (for example, if
  725. a package is installed which overwrites a file from another package,
  726. and then it is removed again).
  727. <item>
  728. <enum>
  729. <item>
  730. If the package is being upgraded, call
  731. <tscreen><verb>
  732. <var/old-postrm/ <tt/upgrade/ <var/new-version/
  733. </verb></tscreen>
  734. <item>
  735. If this fails, <tt/dpkg/ will attempt:
  736. <tscreen><verb>
  737. <var/new-postrm/ <tt/failed-upgrade/ <var/old-version/
  738. </verb></tscreen>
  739. Error unwind, for both cases:
  740. <tscreen><verb>
  741. <var/old-preinst/ <tt/abort-upgrade/ <var/new-version/
  742. </verb></tscreen>
  743. </enum>
  744. This is the point of no return - if <tt/dpkg/ gets this far, it won't
  745. back off past this point if an error occurs. This will leave the
  746. package in a fairly bad state, which will require a successful
  747. reinstallation to clear up, but it's when <tt/dpkg/ starts doing
  748. things that are irreversible.
  749. <item>
  750. Any files which were in the old version of the package but not in the
  751. new are removed.
  752. <item>
  753. The new file list replaces the old.
  754. <item>
  755. The new maintainer scripts replace the old.
  756. <item>
  757. Any packages all of whose files have been overwritten during the
  758. installation, and which aren't required for dependencies, are considered
  759. to have been removed. For each such package,
  760. <enum>
  761. <item>
  762. <tt/dpkg/ calls:
  763. <tscreen><verb>
  764. <var/disappearer's-postrm/ <tt/disappear/ <var/overwriter/ <var/overwriter-version/
  765. </verb></tscreen>
  766. <item>
  767. The package's maintainer scripts are removed.
  768. <item>
  769. It is noted in the status database as being in a sane state, namely
  770. not installed (any conffiles it may have are ignored). Note that
  771. disappearing packages do not have their prerm called, because
  772. <tt/dpkg/ doesn't know in advance that the package is going to vanish.
  773. </enum>
  774. <item>
  775. Any files in the package we're unpacking that are also listed in the
  776. file lists of other packages are removed from those lists. (This will
  777. lobotomise the file list of the `conflicting' package if there is one.)
  778. <item>
  779. The backup files made during installation, above, are deleted.
  780. <item>
  781. The new package's status is now sane, and recorded as `unpacked'. Here
  782. is another point of no return - if the conflicting package's removal
  783. fails we do not unwind the rest of the installation; the conflicting
  784. package is left in a half-removed limbo.
  785. <item>
  786. If there was a conflicting package we go and do the removal actions
  787. (described below), starting with the removal of the conflicting
  788. package's files (any that are also in the package being installed
  789. have already been removed from the conflicting package's file list,
  790. and so do not get removed now).
  791. </enum>
  792. <sect1>Details of configuration
  793. <p>
  794. When we configure a package (this happens with <tt/dpkg --install/, or
  795. with <tt/--configure/), we first update the conffiles and then call:
  796. <tscreen><verb>
  797. <var/postinst/ <tt/configure/ <var/most-recently-configured-version/
  798. </verb></tscreen>
  799. <p>
  800. No attempt is made to unwind after errors during configuration.
  801. <p>
  802. If there is no most recently configured version <tt/dpkg/ will pass a
  803. null argument; older versions of dpkg may pass
  804. <tt>&lt;unknown&gt;</tt> (including the angle brackets) in this case.
  805. Even older ones do not pass a second argument at all, under any
  806. circumstances.
  807. <sect1>Details of removal and/or configration purging
  808. <p>
  809. <enum>
  810. <item>
  811. <tscreen><verb>
  812. <var/prerm/ <tt/remove/
  813. </verb></tscreen>
  814. <item>
  815. The package's files are removed (except conffiles).
  816. <item>
  817. <tscreen><verb>
  818. <var/postrm/ <tt/remove/
  819. </verb></tscreen>
  820. <item>
  821. All the maintainer scripts except the postrm are removed.
  822. <p>
  823. If we aren't purging the package we stop here. Note that packages
  824. which have no postrm and no conffiles are automatically purged when
  825. removed, as there is no difference except for the <tt/dpkg/ status.
  826. <item>
  827. The conffiles and any backup files (<tt/~/-files, <tt/#*#/ files,
  828. <tt/%/-files, <tt/.dpkg-{old,new,tmp}/, etc.) are removed.
  829. <item>
  830. <tscreen><verb>
  831. <var/postrm/ <tt/purge/
  832. </verb></tscreen>
  833. <item>
  834. The package's file list is removed.
  835. </enum>
  836. No attempt is made to unwind after errors during removal.
  837. <sect>Dangling references
  838. <sect1>Would dangle to conffiles<label id="conffiles">
  839. There would be a dangling xref here. Instead I've just put this dummy
  840. text in.
  841. <sect1>Would dangle to descriptions<label id="descriptions">
  842. There would be a dangling xref here. Instead I've just put this dummy
  843. text in.
  844. </article>