programmer.sgml 36 KB

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