programmer.sgml 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444
  1. <!doctype linuxdoc system "./linuxdoc.dtd" >
  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. 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.
  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. What to do about file aliasing.
  32. -->
  33. <sect>Scope of this manual
  34. <p>
  35. This manual describes the technical aspects of creating Debian binary
  36. packages (<tt/.deb/ files.). It documents the behaviour of the
  37. package management programs <tt/dpkg/, <tt/dselect/ et al and and the
  38. way they interact with packages.
  39. <p>
  40. It documents the utility programs which are provided with <tt/dpkg/
  41. for managing various system configuration and similar issues (such as
  42. <tt/update-rc.d/ and <tt/install-info/.
  43. It also documents the interaction between <tt/dselect/'s core and the
  44. access method scripts it uses to actually install the selected
  45. packages, and describes how to create a new access method.
  46. <p>
  47. It does <em/not/ describe the policy requirements imposed on Debian
  48. packages, such as the permissions on files and directories,
  49. documentation requirements, upload procedure, and so on. You should
  50. see the Debian packaging policy manual for these details. (Many of
  51. them will probably turn out to be helpful even if you don't plan to
  52. upload your package and make it available as part of the
  53. distribution.)
  54. <p>
  55. It is assumed that the reader is reasonably familiar with the
  56. <tt/dpkg/ System Administrators' manual.
  57. <p>
  58. The Debian version of the FSF's GNU hello program is provided as an
  59. example for people wishing to create Debian packages.
  60. <p>
  61. <em>Note that this document is not yet complete !</em>
  62. <sect>Binary package format
  63. <p>
  64. <tt/dpkg/ is a suite of programs for creating binary package files and
  65. installing and removing them on Unix systems.<footnote><tt/dpkg/ is
  66. targetted primarily at Debian Linux, but may work or be ported to
  67. other systems.</footnote>
  68. <p>
  69. The binary package files' contents may be architecture-independent,
  70. but they usually aren't. They aren't designed for the management of
  71. program source code (though examples of this are provided as part of
  72. some packages by way of documentation).
  73. <p>
  74. The binary package has two main sections: the first part consists of
  75. various control information files and scripts used by <tt/dpkg/ when
  76. installing and removing.
  77. <p>
  78. The second part is an archive (currently a <tt/tar/ archive)
  79. containing files and directories to be installed. See <ref
  80. id="controlarea">.
  81. <p>
  82. In the future binary packages may also contain other components, such
  83. as checksums and digital signatures.
  84. <p>
  85. <sect1>Creating package files -- <tt/dpkg-deb/
  86. <p>
  87. All manipulation of binary package files is done by <tt/dpkg-deb/;
  88. it's the only program that has knowledge of the format.
  89. (<tt/dpkg-deb/ may be invoked by calling <tt/dpkg/, as <tt/dpkg/ will
  90. spot that the options requested are appropriate to <tt/dpkg-deb/ and
  91. invoke that instead with the same arguments.)
  92. <p>
  93. In order to create a binary package you must make a directory tree
  94. which contains all the files and directories you want to have in the
  95. filesystem data part of the package.
  96. <p>
  97. They should have the locations (relative to the root of the directory
  98. tree you're constructing) ownerships and permissions which you want
  99. them to have on the system when they are installed.
  100. <p>
  101. With current versions of <tt/dpkg/ the uid/username and gid/groupname
  102. mappings for the users and groups being used should be the same on the
  103. system where the package is built and the one where it is installed.
  104. <p>
  105. You need to add one special directory to the root of the miniature
  106. filesystem tree you're creating: <tt/DEBIAN/. It should contain the
  107. control information files, notably the main package control file (see
  108. <ref id="controlarea">).
  109. <p>
  110. The <tt/DEBIAN/ directory will not appear in the filesystem archive of
  111. the package, and so won't be installed by <tt/dpkg/ when the package
  112. is installed.
  113. <p>
  114. When you've prepared the package, you should invoke:<!--var-->
  115. <example>
  116. dpkg --build <it/directory/
  117. </example>
  118. <p>
  119. This will build the package in <var/directory/<tt/.deb/.
  120. (<tt/dpkg/ knows that <tt/--build/ is a <tt/dpkg-deb/ option, so it
  121. invokes <tt/dpkg-deb/ with the same arguments to build the package.)
  122. <p>
  123. See the manpage for <tt/dpkg-deb/ for details of how to examine the
  124. contents of this newly-created file. You may find the output of
  125. following commands enlightening:
  126. <example>
  127. dpkg-deb --info <var/filename/<tt/.deb/
  128. dpkg-deb --contents <var/filename/<tt/.deb/
  129. </example>
  130. <sect1>Package control information files<label id="controlarea">
  131. <p>
  132. The control information portion of a binary package is a collection of
  133. files with names known to <tt/dpkg/. It will treat the contents of
  134. these files specially - some of them contain information used by
  135. <tt/dpkg/ when installing or removing the package; others are scripts
  136. which the package maintainer wants <tt/dpkg/ to run.
  137. <p>
  138. It is possible to put other files in the package control area, but
  139. this is not generally a good idea (though they will largely be
  140. ignored).
  141. <p>
  142. Here is a brief list of the control info files supported by <tt/dpkg/
  143. and a summary of what they're used for.
  144. <descrip>
  145. <tag/<tt/control//
  146. This is the key description file used by <tt/dpkg/. It specifies the
  147. package's name and version, gives its description for the user, states
  148. its relationships with other packages, and so forth.
  149. See <ref id="controlfile">.
  150. <tag><tt/postinst/, <tt/preinst/, <tt/postrm/, <tt/prerm/</tag>
  151. These are exectuable files (usually scripts) which <tt/dpkg/ runs
  152. during installation, upgrade and removal of packages. They allow the
  153. package to deal with matters which are particular to that package or
  154. require more complicated processing than that provided by <tt/dpkg/.
  155. Details of when and how they are called are in
  156. <ref id="maintainerscripts">.
  157. <tag/<tt/conffiles//
  158. This file contains a list of configuration files which are to be
  159. handled automatically by <tt/dpkg/ (see <ref id="conffiles">). Note
  160. that not necessarily every configuration file should be listed here.
  161. </descrip>
  162. <sect1>The main control information file: <tt/control/<label id="controlfile">
  163. <p>
  164. The most important control information file used by <tt/dpkg/ when it
  165. installs a package is <tt/control/. It contains all the package's
  166. `vital statistics'.
  167. <p>
  168. It is a series of fields and values; each field consists of a name,
  169. followed by a colon and the value. It ends at the end of the line.
  170. Horizontal whitespace (spaces and tabs) may occur before or after the
  171. value and is ignored there; it is conventional to put a single space
  172. after the colon. Many of the fields have a syntax where whitespace is
  173. not significant.
  174. <p>
  175. Some fields' values may span several lines; in this case each
  176. continuation line <em/must/ start with a space or tab. Any trailing
  177. spaces or tabs at the end of individual lines of a field value are
  178. ignored.
  179. <p>
  180. Field names are not case-sensitive, but it is usual to capitalise the
  181. fields as shown below (usually using a form of mixed case).
  182. <p>
  183. Blank lines, or lines consisting only of spaces and tabs, are not allowed.
  184. <p>
  185. Here is a list of the fields which are permitted in packages, together
  186. with a description of the purposes and syntax of each and or a pointer
  187. to further information if appropriate.
  188. <p>
  189. It is important to note that there are several fields which are
  190. optional as far as <tt/dpkg/ is concerned, but which must appear in
  191. every Debian package, or whose omission may cause problems. When
  192. writing the control file for a Debian package you <em/must/ read the
  193. Debian policy manual in conjuction with the list below.
  194. <sect2>List of package control file fields
  195. <p>
  196. <descrip>
  197. <tag/<tt/Package//
  198. The name of the package. Package names consist of the alphanumerics,
  199. plus, minus and dot. They must be at least two characters and must
  200. start with an alphanumeric. In current versions of dpkg they are sort
  201. of case-sensitive; use lowercase package names unless the package
  202. you're building (or referring to, in other fields) is already using
  203. uppercase.
  204. <p>
  205. This field is mandatory.
  206. <tag/<tt/Version//
  207. This lists the package's version number - see <ref id="versions">.
  208. This field is mandatory.
  209. <tag/<tt/Architecture//
  210. This is the architecture string; it is a single word for the CPU
  211. architecture, and <tt/dpkg/ will check it against its own compiled-in
  212. value before it installs a package. The special value <tt/all/
  213. indicates that the package is architecture-independent.
  214. <p>
  215. The value for this field can be obtained using
  216. <example>
  217. dpkg --print-architecture
  218. </example>
  219. This actually invokes
  220. <example>
  221. gcc --print-libgcc-file-name
  222. </example>
  223. and parses and decomposes the output and looks the CPU type from the
  224. GCC configuration in a table in <tt/dpkg/. This is so that it will
  225. work if you're cross-compiling.
  226. <p>
  227. There is a separate option, <tt/--print-installation-architecture/,
  228. for finding out what architecture <tt/dpkg/ is willing to install.
  229. This information is also in the output of <tt/dpkg --version/.
  230. <p>
  231. This field should appear in all packages, though <tt/dpkg/ doesn't
  232. require it yet so that old packages can still be installed.
  233. <tag/<tt/Maintainer//
  234. The package maintainer's name and email address. The name should come
  235. first, then the email address inside angle brackets <tt/&lt;&gt/ (in
  236. RFC822 format).
  237. <p>
  238. If the maintainer's name contains a full stop then the whole field
  239. will not work directly as an email address due to a misfeature in the
  240. syntax for addresses; a program using this field as an address must
  241. check for this and reverse the components if necessary (for example by
  242. putting the name in round brackets or quotes, and perhaps moving it to
  243. the end).
  244. This feature is optional as far as <tt/dpkg/ is concerned, but
  245. <tt/dpkg-deb/ will warn if it is missing.
  246. <tag><tt/Depends/, <tt/Pre-Depends/, <tt/Recommends/, <tt/Suggests/
  247. <tt/Conflicts/, <tt/Provides/, <tt/Replaces/</tag>
  248. These fields describe the package's relationships with other packages.
  249. Their syntax and semantics are described in <ref id="depconoverwr">.
  250. <tag/<tt/Source//
  251. This field identifies the source package name, primarily for the
  252. benefit of humans reading the control file rather than <tt/dpkg/. It
  253. consists solely of the source package name; it may be omitted when the
  254. source package has the same name as the binary package.
  255. This field is optional as far as <tt/dpkg/ is concerned.
  256. <tag/<tt/Description//
  257. This field contains a description of the package, in a special format.
  258. <p>
  259. It is very important that you read <ref id="descriptions">.
  260. <tag/<tt/Essential//
  261. This is a boolean field. If set to <tt/yes/ then <tt/dpkg/ and
  262. <tt/dselect/ will refuse to remove the package (though it can be
  263. upgraded and/or replaced). The other possible value is <tt/no/, which
  264. is the same as not having the field at all.
  265. <p>
  266. This field is optional.
  267. <tag/<tt/Priority//
  268. This specifies the `priority' of the package; this represents how
  269. important that it is that the user have it installed.
  270. <p>
  271. This value isn't used by <tt/dpkg/, but only by <tt/dselect/ when it
  272. sorts packages and selects defaults. See the <tt/dpkg/ System
  273. Administrator's Manual for details of the values it can take, and the
  274. Debian Policy Manual for the criteria for selecting the priority for a
  275. Debian package.
  276. <p>
  277. <tt/dpkg/ and <tt/dselect/ will only use the value from a <tt/.deb/
  278. file if they have no other information; a priority value listed in a
  279. <tt/Packages/ file will always take precedence. This field is
  280. optional as far as <tt/dpkg/ is concerned.
  281. <tag/<tt/Section//
  282. This specifies the `section' of the package, namely the application
  283. area or group of packages which contain it. The value is a simple
  284. string, usually from a set chosen by the distribution maintainers.
  285. <p>
  286. The section isn't used at all except by <tt/dselect/, which only uses
  287. it for sorting packages in the selection display and not even for
  288. choosing defaults.
  289. <p>
  290. Just as with <tt/Priority/, this field is optional as far as <tt/dpkg/
  291. is concerned, and the value from a package file is used only as a last
  292. resort.
  293. </descrip>
  294. <sect2>List of other control fields
  295. <p>
  296. There are several other fields which are used elsewhere by parts of
  297. the system. These should not appear in package control files.
  298. <sect3>Status fields
  299. <p>
  300. These fields appear in <tt/dpkg/'s internal status file; they are also
  301. printed by <tt/dpkg --status/ and can be seen in <tt/dselect/ by
  302. selecting the installed control info display.
  303. <p>
  304. <descrip>
  305. <tag/<tt/Status//
  306. This field in <tt/dpkg/'s status file records whether the user wants a
  307. package installed, removed or left alone, whether it is broken
  308. (requiring reinstallation) or not and what its current state on the
  309. system is. Each of these pieces of information is a single word.
  310. <tag/<tt/Config-Version//
  311. If a package is not installed or not configured, this field in
  312. <tt/dpkg/'s status file records the last version of the package which
  313. was successfully configured.
  314. <tag/<tt/Conffiles//
  315. This field in <tt/dpkg/'s status file contains information about the
  316. automatically-managed configuration files held by a package. Let me
  317. emphasise that this field should <em/not/ appear in a package !
  318. </descrip>
  319. <sect4><tt/Packages/ file (available package) fields
  320. <p>
  321. These fields are found in <tt/Packages/ files (lists of packages
  322. available for installation, which are generated by the distribution
  323. maintainers and used principally by <tt/dselect/) and in <tt/dpkg/'s
  324. database of available packages (which can be inspected using
  325. <tt/dpkg --print-avail/ or by selecting the `available control
  326. information' in <tt/dselect/.
  327. <p>
  328. <descrip>
  329. <tag><tt/Filename/, <tt/MSDOS-Filename/</tag>
  330. These fields in <tt/Packages/ files give the filename(s) of (the parts
  331. of) a package in the distribution directories, relative to the root of
  332. the Debian hierarchy. If the package has been split into several
  333. parts the parts are all listed in order, separated by spaces.
  334. <tag><tt/Size/, <tt/MD5sum/</tag>
  335. These fields in <tt/Packages/ files give the size (in bytes, expressed
  336. in decimal) and MD5 checksum of the file(s) which make(s) up a binary
  337. package in the distribution. If the package is split into several
  338. parts the values for the parts are listed in order, separated by
  339. spaces.
  340. </descrip>
  341. <sect4>Obsolete fields
  342. <p>
  343. These are still recognised by <tt/dpkg/ but should not appear anywhere
  344. any more.
  345. <descrip>
  346. <tag><tt/Revision/, <tt/Package-Revision/, <tt/Package_Revision/</tag>
  347. The Debian revision part of the package version was at one point in a
  348. separate control file field. This field went through several names.
  349. <tag/Recommended/ Old name for <tt/Recommends/.
  350. <tag/Optional/ Old name for <tt/Suggests/.
  351. <tag/Class/ Old name for <tt/Priority/.
  352. </descrip>
  353. <sect1>Version numbering<label id="versions">
  354. <p>
  355. Every package has a version number, in its <tt/Version/ control file
  356. field.
  357. <p>
  358. <tt/dpkg/ imposes an ordering on version numbers, so that it can tell
  359. whether packages are being up- or downgraded and so that <tt/dselect/
  360. can tell whether a package it finds available is newer than the one
  361. installed on the system. The version number format has the most
  362. significant parts (as far as comparison is concerned) at the
  363. beginning.
  364. <p>
  365. The version number format is:
  366. &lsqb<var/epoch/<tt/:/&rsqb;<var/upstream-version/&lsqb;<tt/-/<var/debian-revision/&rsqb;.
  367. <p>
  368. The three components here are:
  369. <descrip>
  370. <tag/<var/epoch//
  371. This is a single unsigned integer, which should usually be small. It
  372. may be omitted, in which case it defaults to zero. If it is omitted
  373. then the <var/upstream-version/ may not contain any colons.
  374. <p>
  375. It is provided to allow mistakes in the version numbers of older
  376. versions of a package, and also a package's previous version numbering
  377. schemes, to be left behind.
  378. <p>
  379. <tt/dpkg/ will not usually display the epoch unless it is essential
  380. (non-zero, or if the <var/upstream-version/ contains a colon);
  381. <tt/dselect/ does not display epochs at all in the main part of the
  382. package selection display.
  383. <tag/<var/upstream-version//
  384. This is the main part of the version. It is usually version number of
  385. the original (`upstream') package of which the <tt/.deb/ file has been
  386. made, if this is applicable. Usually this will be in the same format
  387. as that specified by the upstream author(s); however, it may need to
  388. be reformatted to fit into <tt/dpkg/'s format and comparison scheme.
  389. <p>
  390. The comparison behaviour of <tt/dpkg/ with respect to the
  391. <var/upstream-version/ is described below. The <var/upstream-version/
  392. portion of the version number is mandatory.
  393. <tag/<var/debian-revision//
  394. This part of the version represents the version of the modifications
  395. that were made to the package to make it a Debian binary package. It
  396. is in the same format as the <var/upstream-version/ and <tt/dpkg/
  397. compares it in the same way.
  398. <p>
  399. It is optional; if it isn't present then the <var/upstream-version/
  400. should not contain a hyphen. This format represents the case where a
  401. piece of software was written specifically to be turned into a Debian
  402. binary package, and so there is only one `debianization' of it and
  403. therefore no version indication is require there.
  404. <p>
  405. It is conventional to restart the <var/debian-revision/ at <tt/1/ each
  406. time the <var/upstream-version/ is increased.
  407. <p>
  408. <tt/dpkg/ will break the <var/upstream-version/ and
  409. <var/debian-revision/ apart at the last hyphen in the string. The
  410. absence of a <var/debian-revision/ compares earlier than the presence
  411. of one (but note that the <var/debian-revision/ is the least
  412. significant part of the version number).
  413. </descrip>
  414. The <var/upstream-version/ and <var/debian-revision/ parts are
  415. compared by <tt/dpkg/ using the same algorithm:
  416. <p>
  417. The strings are compared from left to right.
  418. <p>
  419. First the initial part of each string consisting entirely of non-digit
  420. characters is determined. These two parts (one of which may be empty)
  421. are compared lexically. If a difference is found it is returned. The
  422. lexical comparison is a comparison of ASCII values modified so that
  423. all the letters sort earlier than all the non-letters.
  424. <p>
  425. Then the initial part of the remainder of each string which consists
  426. entirely of digit characters is determined. The numerical values of
  427. these two parts are compared, and any difference found is returned as
  428. the result of the comparison. For these purposes an empty string
  429. (which can only occur at the end of one or both version strings being
  430. compared) counts as zero.
  431. <p>
  432. These two steps are repeated (chopping initial non-digit strings and
  433. initial digit strings off from the start) until a difference is found
  434. or both strings are exhausted.
  435. <p>
  436. Note that the purpose of epochs is to allow us to leave behind
  437. mistakes in version numbering, and to cope with situations where the
  438. version numbering changes. It is <em/not/ there to cope with version
  439. numbers containing strings of letters which <tt/dpkg/ cannot interpret
  440. (such as <tt/ALPHA/ or <tt/pre-/), or with silly orderings (the author
  441. of this manual has heard of a package whose versions went <tt/1.1/,
  442. <tt/1.2/, <tt/1.3/, <tt/1/, <tt/2.1/, <tt/2.2/, <tt/2/ and so forth).
  443. <p>
  444. If an upstream package has problematic version numbers they should be
  445. converted to a sane form for use in the <tt/Version/ field.
  446. <sect1>Package maintainer scripts run by <tt/dpkg/<label id="maintainerscripts">
  447. <p>
  448. It is possible supply scripts as part of a package which <tt/dpkg/
  449. will run for you when your package is installed, upgraded or removed.
  450. <p>
  451. These scripts should be the files <tt/preinst/, <tt/postinst/,
  452. <tt/prerm/ and <tt/postrm/ in the control area of the package. They
  453. should be proper exectuable files, so that if they are scripts (which
  454. is to be recommended) they must start with the usual <tt/#!/
  455. convention. They should be readable and executable to anyone, and not
  456. world-writeable.
  457. <p>
  458. <tt/dpkg/ looks at the exit status from these scripts. It is
  459. important that they exit with a non-zero status if there is an error,
  460. so that <tt/dpkg/ can stop its processing. For shell scripts this
  461. means that you <em/almost always/ need to use <tt/set -e/ (this is
  462. usually true when writing shell scripts, in fact). It is also
  463. important, of course, that they don't exit with a non-zero status if
  464. everything went well.
  465. <p>
  466. It is necessary for the error recovery procedures that the scripts be
  467. idempotent: ie, invoking the same script several times in the same
  468. situation should do no harm. If the first call failed, or aborted
  469. half way through for some reason, the second call should merely do the
  470. things that were left undone the first time, if any, and exit with a
  471. success status.
  472. <p>
  473. When a package is upgraded a combination of the scripts from the old
  474. and new packages is called in amongst the other steps of the upgrade
  475. procedure. If your scripts are going to be at all complicated you
  476. need to be aware of this, and may need to check the arguments to your
  477. scripts.
  478. <p>
  479. Broadly speaking the <tt/preinst/ is called before (a particular
  480. version of) a package is installed, and the <tt/postinst/ afterwards;
  481. the <tt/prerm/ before (a version of) a package is removed and the
  482. <tt/postrm/ afterwards.
  483. <p>
  484. See <ref id="maintscripts-instact"> for details of exactly when and
  485. how these scripts are called and with what arguments.
  486. <sect>Declaring relationships between packages<label id="depconoverwr">
  487. <p>
  488. Packages can declare in their control file that they have certain
  489. relationships to other packages - for example, that they may not be
  490. installed at the same time as certain other packages, and/or that they
  491. depend on the presence of others, or that they should overwrite files
  492. in certain other packages if present.
  493. <p>
  494. This is done using the <tt/Depends/, <tt/Recommends/, <tt/Suggests/,
  495. <tt/Conflicts/, <tt/Provides/ and <tt/Replaces/ control file fields.
  496. <p>
  497. <sect1>Syntax of relationship fields
  498. <p>
  499. These fields all have a uniform syntax. They are a list of package
  500. names separated by commas.
  501. <p>
  502. In <tt/Depends/, <tt/Recommends/, <tt/Suggests/ and <tt/Pre-Depends/
  503. (the fields which declare dependencies of the package in which they
  504. occur on other packages) these package names may also be lists of
  505. alternative package names, separated by vertical bar symbols <tt/|/
  506. (pipe symbols).
  507. <p>
  508. All the fields except <tt/Provides/ may restrict their applicability
  509. to particular versions of each named package. This is done in
  510. parentheses after each individual package name; the parentheses should
  511. contain a relation from the list below followed by a version number,
  512. in the format described in <ref id="versions">.
  513. <p>
  514. The relations allowed are
  515. <tt/&lt;&lt;/,
  516. <tt/&lt;=/,
  517. <tt/=/,
  518. <tt/&gt;=/ and
  519. <tt/&gt;&gt;/
  520. for strictly earlier, earlier or equal, exactly equal, later or equal
  521. and strictly later, respectively. The forms <tt/&lt;/ and <tt/&gt;/
  522. were used to mean earlier/later or equal, rather than strictly
  523. earlier/later, so they should not appear in new packages (though
  524. <tt/dpkg/ still supports them).
  525. <p>
  526. Whitespace may appear at any point in the version specification, and
  527. must appear where it's necessary to disambiguate; it is not otherwise
  528. significant. For consistency and in case of future changes to
  529. <tt/dpkg/ it is recommended that a single space be used after a
  530. version relationship and before a version number; it is usual also to
  531. put a single space after each comma, on either side of each vertical
  532. bar, and before each open parenthesis.
  533. <sect1>Dependencies - <tt/Depends/, <tt/Recommends/, <tt/Suggests/, <tt/Pre-Depends/
  534. <p>
  535. These four fields are used to declare a dependency by one package on
  536. another. They appear in the depending package's control file.
  537. <p>
  538. All but <tt/Pre-Depends/ (discussed below) take effect <em/only/ when
  539. a package is to be configured. They do not prevent a package being on
  540. the system in an unconfigured state while its dependencies are
  541. unsatisfied, and it is possible to replace a package whose
  542. dependencies are satisfied and which is properly installed with a
  543. different version whose dependencies are not and cannot be satisfied;
  544. when this is done the depending package will be left unconfigured
  545. (since attempts to configure it will give errors) and will not
  546. function properly.
  547. <p>
  548. For this reason packages in an installation run are usually all
  549. unpacked first and all configured later; this gives later versions of
  550. packages with dependencies on later versions of other packages the
  551. opportunity to have their dependencies satisfied.
  552. <p>
  553. Thus <tt/Depends/ allows package maintainers to impose an order in
  554. which packages should be configured.
  555. <descrip>
  556. <tag/<tt/Depends//
  557. This declares an absolute dependency.
  558. <p>
  559. <tt/dpkg/ will not configure
  560. packages whose dependencies aren't satisfied. If it is asked to make
  561. an installation which would cause an installed package's dependencies
  562. to become unsatisfied it will complain<footnote>Current versions
  563. (1.2.4) of <tt/dpkg/ have a bug in this area which will cause some of
  564. these problems to be ignored.</footnote>, unless
  565. <tt/--auto-deconfigure/ is specified, in which case those packages
  566. will be deconfigured before the installation proceeds.
  567. <p>
  568. <tt/dselect/ makes it hard for the user to select packages for
  569. installation, removal or upgrade in a way that would mean that
  570. packages' <tt/Depends/ fields would be unsatisfied. The user can
  571. override this if they wish, for example if they know that <tt/dselect/
  572. has an out-of-date view of the real package relationships.
  573. **** WHEN TO USE -- POLICY STATEMENT HERE ?
  574. <tag/<tt/Recommends//
  575. This declares a strong, but not absolute, dependency.
  576. <p>
  577. <tt/Recommends/ is ignored by <tt/dpkg/, so that users using the
  578. command-line (who are presumed to know what they're doing) will not be
  579. impeded.
  580. <p>
  581. It is treated by <tt/dselect/ exactly as <tt/Depends/ is; this makes
  582. it hard for the user to select things so as to leave <tt/Recommends/
  583. fields unsatisfied, but they are able to do so by being persistent.
  584. **** WHEN TO USE -- POLICY STATEMENT HERE ?
  585. <tag/<tt/Suggests//
  586. This is used to declare that one package may be more useful with one
  587. or more others.
  588. <p>
  589. <tt/dselect/ will offer suggsted packages to the system administrator
  590. when they select the suggesting package, but the default is not to
  591. install the suggested package.
  592. **** WHEN TO USE -- POLICY STATEMENT HERE ?
  593. <tag/<tt/Pre-Depends//
  594. This field is like <tt/Depends/, except that it also forces <tt/dpkg/
  595. to complete installation of the packages named before even starting
  596. the installation of the package which declares the predependency.
  597. <p>
  598. <tt/dselect/ checks for predependencies when it is doing an
  599. installation run, and will attempt to find the packages which are
  600. required to be installed first and do so in the right order.
  601. <p>
  602. However, this process is slow (because it requires repeated
  603. invocations of <tt/dpkg/) and troublesome (because it requires
  604. guessing where to find the appropriate files).
  605. <p>
  606. For these reasons, and because this field imposes restrictions on the
  607. order in which packages may be unpacked (which can be difficult for
  608. installations from multipart media, for example), <tt/Pre-Depends/
  609. should be used sparingly, preferably only by packages whose premature
  610. upgrade or installation would hamper the ability of the system to
  611. continue with any upgrade that might be in progress.
  612. <p>
  613. When the package declaring it is being configured, a
  614. <tt/Pre-Dependency/ will be considered satisfied only if the depending
  615. package has been correctly configured, just as if an ordinary
  616. <tt/Depends/ had been used.
  617. <p>
  618. However, when a package declaring a predependency is being unpacked
  619. the predependency can be satisfied even if the depended-on package(s)
  620. are only unpacked or half-configured, provided that they have been
  621. configured correctly at some point in the past (and not removed or
  622. partially removed since). In this case both the previously-configured
  623. and currently unpacked or half-configured versions must satisfy any
  624. version clause in the <tt/Pre-Depends/ field.
  625. </descrip>
  626. <sect2>Deconfiguration due to removal during bulk installations
  627. <p>
  628. If <tt/dpkg/ would like to remove a package due to a conflict, as
  629. described above, but this would violate a dependency of some other
  630. package on the system, <tt/dpkg/ will usually not remove the
  631. conflicting package and halt with an error.
  632. <p>
  633. However, if the <tt/--auto-deconfigure/ (<tt/-B/) option is used
  634. <tt/dpkg/ will automatically `deconfigure' the package with the
  635. problematic dependency, so that the conflicting package can be removed
  636. and the package we're trying to install can be installed. If
  637. <tt/dpkg/ is being asked to install packages (rather than just
  638. unpacking them) it will try to reconfigure the package when it has
  639. unpacked all its arguments, in the hope that one of the other packages
  640. it is installing will satisfy the problematic dependency.
  641. <p>
  642. <tt/dselect/ supplies this argument to <tt/dpkg/ when it invokes it,
  643. so that bulk installations proceed smoothly.
  644. <sect1>Alternative packages - <tt/Conflicts/ and <tt/Replaces/<label id="conflicts">
  645. <p>
  646. When one package declares a conflict with another <tt/dpkg/ will
  647. refuse to allow them to be installed on the system at the same time.
  648. <p>
  649. If one package is to be installed, the other must be removed first -
  650. if the package being installed is marked as replacing (<ref
  651. id="replaces">) the one on the system, or the one on the system is
  652. marked as deselected, or both packages are marked <tt/Essential/, then
  653. <tt/dpkg/ will automatically remove the package which is causing the
  654. conflict, otherwise it will halt the installation of the new package
  655. with an error.
  656. <p>
  657. <tt/dselect/ makes it hard to select conflicting packages, though the
  658. user can override this if they wish. If they do not override it then
  659. <tt/dselect/ will select one of the packages for removal, and the user
  660. must make sure it is the right one. In the future <tt/dselect/ will
  661. look for the presence of a <tt/Replaces/ field to help decide which
  662. package should be installed and which removed.
  663. <p>
  664. A package will not cause a conflict merely because its configuration
  665. files are still installed; it must be at least half-installed.
  666. <p>
  667. A special exception is made for packages which declare a conflict with
  668. their own package name, or with a virtual package which they provide
  669. (see below): this does not prevent their installation, and allows a
  670. package to conflict with others providing a replacement for it.
  671. <p>
  672. A <tt/Conflicts/ entry should almost never have an `earlier than'
  673. version clause. This would prevent <tt/dpkg/ from upgrading or
  674. installing the package which declared such a conflict until the
  675. upgrade or removal of the conflicted-with package had been completed.
  676. This aspect of installation ordering is not handled by <tt/dselect/,
  677. so that the use <tt/Conflicts/ in this way is likely to cause problems
  678. for `bulk run' upgrades and installations.
  679. <p>
  680. <sect1>Virtual packages - <tt/Provides/<label id="virtual">
  681. <p>
  682. As well as the names of actual (`concrete') packages, the package
  683. relationship fields <tt/Depends/, <tt/Recommends/, <tt/Suggests/ and
  684. <tt/Conflicts/ may mention virtual packages.
  685. <p>
  686. A virtual package is one which appears in the <tt/Provides/ control
  687. file field of another package. The effect is as if the package(s)
  688. which provide a particular virtual package name had been listed by
  689. name everywhere were the virtual package name appears.
  690. <p>
  691. If there are both a real and a virtual package of the same name then
  692. the dependency may be satisfied (or the conflict caused) by either the
  693. real package or any of the virtual packages which provide it. This is
  694. so that, for example, supposing we have
  695. <p>
  696. If a dependency or a conflict has a version number attached then only
  697. real packages will be considered to see whether the relationship is
  698. satisfied (or prohibited, for a conflict) - it is assumed that a real
  699. package which provides virtual package is not of the `right' version.
  700. So, a <tt/Provides/ field may not contain version numbers, and the
  701. version number of the concrete package which provides a particular
  702. virtual package will not be looked at when considering a dependency on
  703. or conflict with the virtual package name.
  704. <p>
  705. If you want to specify which of a set of real packages should be the
  706. default to satisfy a particular dependency on a virtual package, you
  707. should list the real package as alternative before the virtual.
  708. <p>
  709. <sect1>Defaults for satisfying dependencies - ordering
  710. <p>
  711. Ordering is significant in dependency fields.
  712. <p>
  713. Usually dselect will suggest to the user that they select the package
  714. with the most `fundamental' class (eg, it will prefer Base packages to
  715. Optional ones), or the one that they `most wanted' to select in some
  716. sense.
  717. <p>
  718. However, in the absence of other information <tt/dselect/ will offer a
  719. default selection of the first named package in a list of
  720. alternatives.
  721. <p>
  722. However, there is no way to specify the `order' of several packages
  723. which all provide the same thing, when that thing is listed as a
  724. dependency.
  725. <p>
  726. Therefore a dependency on a virtual package should contain a concrete
  727. package name as the first alternative, so that this is the default.
  728. <p>
  729. For example, consider the set of packages:
  730. <example>
  731. Package: glibcdoc
  732. Recommends: info-browser
  733. Package: info
  734. Provides: info-browser
  735. Package: emacs
  736. Provides: info-browser
  737. </example>
  738. If <tt/emacs/ and <tt/info/ both have the same priority then
  739. <tt/dselect/'s choice is essentially random. Better would be
  740. <example>
  741. Package: glibcdoc
  742. Recommends: info | info-browser
  743. </example>
  744. so that <tt/dselect/ defaults to selecting the lightweight standalone
  745. info browser.
  746. <sect1><tt/Replaces/ - overwriting files and replacing packages<label id="replaces">
  747. <p>
  748. The <tt/Replaces/ control file field has two purposes, which come into
  749. play in different situations.
  750. <p>
  751. Virtual packages (<ref id="virtual">) are not considered when looking
  752. at a <tt/Replaces/ field - the packages declared as being replaced
  753. must be mentioned by their real names.
  754. <sect2>Overwriting files in other packages
  755. <p>
  756. Firstly, as mentioned before, it is usually an error for a package to
  757. contains files which are on the system in another package, though
  758. currently the <tt/--force-overwrite/ flag is enabled by default,
  759. downgrading the error to a warning,
  760. <p>
  761. If the overwriting package declares that it replaces the one
  762. containing the file being overwritten then <tt/dpkg/ will proceed, and
  763. replace the file from the old package with that from the new. The
  764. file will no longer be listed as `owned' by the old package.
  765. <p>
  766. If a package is completely replaced in this way, so that <tt/dpkg/
  767. does not know of any files it still contains, it is considered to have
  768. disappeared. It will be marked as not wanted on the system (selected
  769. for removal) and not installed. Any conffiles details noted in the
  770. package will be ignored, as they will have been taken over by the
  771. replacing package(s). The package's <tt/postrm/ script will be run to
  772. allow the package to do any final cleanup required.
  773. See <ref id="maintscripts-instact">.
  774. <p>
  775. In the future <tt/dpkg/ will discard files which overwrite those from
  776. another package which declares that it replaces the one being
  777. installed (so that you can install an older version of a package
  778. without problems).
  779. <p>
  780. This usage of <tt/Replaces/ only takes effect when both packages are
  781. at least partially on the system at once, so that it can only happen
  782. if they do not conflict or if the conflict has been overridden.
  783. <sect2>Replacing whole packages, forcing their removal
  784. <p>
  785. Secondly, <tt/Replaces/ allows <tt/dpkg/ and <tt/dselect/ to resolve
  786. which package should be removed when a conflict - see
  787. <ref id="conflicts">. This usage only takes effect when the two
  788. packages <em/do/ conflict, so that the two effects do not interfere
  789. with each other.
  790. <p>
  791. <sect>Order of processing steps and maintainer script arguments<label id="maintscripts-instact">
  792. <p>
  793. <sect1>Summary of ways maintainer scripts are called
  794. <p>
  795. <itemize>
  796. <item><var/new preinst/ <tt/install/
  797. <item><var/new preinst/ <tt/install/ <var/old-version/
  798. <item><var/new preinst/ <tt/upgrade/ <var/old-version/
  799. <item><var/old preinst/ <tt/abort-upgrade/ <var/new-version/
  800. </itemize>
  801. <itemize>
  802. <item><var/postinst/ <tt/configure/ <var/most-recently-configured-version/
  803. <item><var/old-postinst/ <tt/abort-upgrade/ <var/new version/
  804. <item><var/conflictor's-postinst/ <tt/abort-remove/
  805. in-favour <var/package/ <var/new-version/
  806. <item><var/deconfigured's-postinst/ <tt/abort-deconfigure/
  807. <tt/in-favour/ <var/failed-install-package/ <var/version/
  808. <tt/removing/ <var/conflicting-package/ <var/version/
  809. </itemize>
  810. <itemize>
  811. <item><var/prerm/ <tt/remove/
  812. <item><var/old-prerm/ <tt/upgrade/ <var/new-version/
  813. <item><var/new-prerm/ <tt/failed-upgrade/ <var/old-version/
  814. <item><var/conflictor's-prerm/ <tt/remove/ <tt/in-favour/
  815. <var/package/ <var/new-version/
  816. <item><var/deconfigured's-prerm/ <tt/deconfigure/
  817. <tt/in-favour/ <var/package-being-installed/ <var/version/
  818. <tt/removing/ <var/conflicting-package/ <var/version/
  819. </itemize>
  820. <itemize>
  821. <item><var/postrm/ <tt/remove/
  822. <item><var/postrm/ <tt/purge/
  823. <item><var/old-postrm/ <tt/upgrade/ <var/new-version/
  824. <item><var/new-postrm/ <tt/failed-upgrade/ <var/old-version/
  825. <item><var/new-postrm/ <tt/abort-install/
  826. <item><var/new-postrm/ <tt/abort-install/ <var/old-version/
  827. <item><var/new-postrm/ <tt/abort-upgrade/ <var/old-version/
  828. <item><var/disappearer's-postrm/ <tt/disappear/ <var/overwriter/ <var/new-version/
  829. </itemize>
  830. <sect1>Details of unpack phase of installation or upgrade
  831. <p>
  832. The procedure on installation/upgrade/overwrite/disappear (ie, when
  833. running <tt/dpkg --unpack/, or the unpack stage of <tt/dpkg
  834. --install/) is as follows. In each case if an error occurs the
  835. actions in are general run backwards - this means that the maintainer
  836. scripts are run with different arguments in reverse order. These are
  837. the `error unwind' calls listed below.
  838. <enum>
  839. <item>
  840. <enum>
  841. <item>
  842. If a version the package is already
  843. installed, call
  844. <example>
  845. <var/old-prerm/ <tt/upgrade/ <var/new-version/
  846. </example>
  847. <item>
  848. If this gives an error (ie, a non-zero exit status), dpkg will
  849. attempt instead:
  850. <example>
  851. <var/new-prerm/ <tt/failed-upgrade/ <var/old-version/
  852. </example>
  853. Error unwind, for both the above cases:
  854. <example>
  855. <var/old-postinst/ <tt/abort-upgrade/ <var/new-version/
  856. </example>
  857. </enum>
  858. <item>
  859. If a `conflicting' package is being removed at the same time:
  860. <enum>
  861. <item>
  862. If any packages depended on that conflicting package and
  863. <tt/--auto-deconfigure/ is specified, call, for each such package:
  864. <example>
  865. <var/deconfigured's-prerm/ <tt/deconfigure/
  866. <tt/in-favour/ <var/package-being-installed/ <var/version/
  867. <tt/removing/ <var/conflicting-package/ <var/version/
  868. </example>
  869. Error unwind:
  870. <example>
  871. <var/deconfigured's-postinst/ <tt/abort-deconfigure/
  872. <tt/in-favour/ <var/package-being-installed-but-failed/ <var/version/
  873. <tt/removing/ <var/conflicting-package/ <var/version/
  874. </example>
  875. The deconfigured packages are marked as requiring configuration, so
  876. that if <tt/--install/ is used they will be configured again if
  877. possible.
  878. <item>
  879. To prepare for removal of the conflicting package, call:
  880. <example>
  881. <var/conflictor's-prerm/ <tt/remove/
  882. <tt/in-favour/ <var/package/ <var/new-version/
  883. </example>
  884. Error unwind:
  885. <example>
  886. <var/conflictor's-postinst/ <tt/abort-remove/
  887. <tt/in-favour/ <var/package/ <var/new-version/
  888. </example>
  889. </enum>
  890. <item>
  891. <enum>
  892. <item>
  893. If the package is being upgraded, call:
  894. <example>
  895. <var/new-preinst/ <tt/upgrade/ <var/old-version/
  896. </example>
  897. <item>
  898. Otherwise, if the package had some configuration files from a previous
  899. version installed (ie, it is in the `configuration files only' state):
  900. <example>
  901. <var/new-preinst/ <tt/install/ <var/old-version/
  902. </example>
  903. <item>
  904. Otherwise (ie, the package was completely purged):
  905. <example>
  906. <var/new-preinst/ <tt/install/
  907. </example>
  908. Error unwind versions, respectively:
  909. <example>
  910. <var/new-postrm/ <tt/abort-upgrade/ <var/old-version/
  911. <var/new-postrm/ <tt/abort-install/ <var/old-version/
  912. <var/new-postrm/ <tt/abort-install/
  913. </example>
  914. </enum>
  915. <item>
  916. The new package's files are unpacked, overwriting any that may be on
  917. the system already, for example any from the old version of the same
  918. package or from another package (backups of the old files are left
  919. around, and if anything goes wrong dpkg will attempt to put them back
  920. as part of the error unwind).
  921. <p>
  922. It is an error for a package to contains files which are on the system
  923. in another package, unless <tt/Replaces/ is used
  924. (see <ref id="replaces">). Currently the <tt/--force-overwrite/ flag
  925. is enabled, downgrading it to a warning, but this will not always be
  926. the case.
  927. <p>
  928. Packages which overwrite each other's files produce behaviour which
  929. (though deterministic) is hard for the system administrator to
  930. understand and can easily lead to `missing' programs (for example, if
  931. a package is installed which overwrites a file from another package,
  932. and then it is removed again).
  933. <item>
  934. <enum>
  935. <item>
  936. If the package is being upgraded, call
  937. <example>
  938. <var/old-postrm/ <tt/upgrade/ <var/new-version/
  939. </example>
  940. <item>
  941. If this fails, <tt/dpkg/ will attempt:
  942. <example>
  943. <var/new-postrm/ <tt/failed-upgrade/ <var/old-version/
  944. </example>
  945. Error unwind, for both cases:
  946. <example>
  947. <var/old-preinst/ <tt/abort-upgrade/ <var/new-version/
  948. </example>
  949. </enum>
  950. This is the point of no return - if <tt/dpkg/ gets this far, it won't
  951. back off past this point if an error occurs. This will leave the
  952. package in a fairly bad state, which will require a successful
  953. reinstallation to clear up, but it's when <tt/dpkg/ starts doing
  954. things that are irreversible.
  955. <item>
  956. Any files which were in the old version of the package but not in the
  957. new are removed.
  958. <item>
  959. The new file list replaces the old.
  960. <item>
  961. The new maintainer scripts replace the old.
  962. <item>
  963. Any packages all of whose files have been overwritten during the
  964. installation, and which aren't required for dependencies, are considered
  965. to have been removed. For each such package,
  966. <enum>
  967. <item>
  968. <tt/dpkg/ calls:
  969. <example>
  970. <var/disappearer's-postrm/ <tt/disappear/ <var/overwriter/ <var/overwriter-version/
  971. </example>
  972. <item>
  973. The package's maintainer scripts are removed.
  974. <item>
  975. It is noted in the status database as being in a sane state, namely
  976. not installed (any conffiles it may have are ignored, rather than
  977. being removed by <tt/dpkg/). Note that disappearing packages do not
  978. have their prerm called, because <tt/dpkg/ doesn't know in advance
  979. that the package is going to vanish.
  980. </enum>
  981. <item>
  982. Any files in the package we're unpacking that are also listed in the
  983. file lists of other packages are removed from those lists. (This will
  984. lobotomise the file list of the `conflicting' package if there is one.)
  985. <item>
  986. The backup files made during installation, above, are deleted.
  987. <item>
  988. The new package's status is now sane, and recorded as `unpacked'. Here
  989. is another point of no return - if the conflicting package's removal
  990. fails we do not unwind the rest of the installation; the conflicting
  991. package is left in a half-removed limbo.
  992. <item>
  993. If there was a conflicting package we go and do the removal actions
  994. (described below), starting with the removal of the conflicting
  995. package's files (any that are also in the package being installed
  996. have already been removed from the conflicting package's file list,
  997. and so do not get removed now).
  998. </enum>
  999. <sect1>Details of configuration
  1000. <p>
  1001. When we configure a package (this happens with <tt/dpkg --install/, or
  1002. with <tt/--configure/), we first update the conffiles and then call:
  1003. <example>
  1004. <var/postinst/ <tt/configure/ <var/most-recently-configured-version/
  1005. </example>
  1006. <p>
  1007. No attempt is made to unwind after errors during configuration.
  1008. <p>
  1009. If there is no most recently configured version <tt/dpkg/ will pass a
  1010. null argument; older versions of dpkg may pass
  1011. <tt>&lt;unknown&gt;</tt> (including the angle brackets) in this case.
  1012. Even older ones do not pass a second argument at all, under any
  1013. circumstances.
  1014. <sect1>Details of removal and/or configration purging
  1015. <p>
  1016. <enum>
  1017. <item>
  1018. <example>
  1019. <var/prerm/ <tt/remove/
  1020. </example>
  1021. <item>
  1022. The package's files are removed (except conffiles).
  1023. <item>
  1024. <example>
  1025. <var/postrm/ <tt/remove/
  1026. </example>
  1027. <item>
  1028. All the maintainer scripts except the postrm are removed.
  1029. <p>
  1030. If we aren't purging the package we stop here. Note that packages
  1031. which have no postrm and no conffiles are automatically purged when
  1032. removed, as there is no difference except for the <tt/dpkg/ status.
  1033. <item>
  1034. The conffiles and any backup files (<tt/~/-files, <tt/#*#/ files,
  1035. <tt/%/-files, <tt/.dpkg-{old,new,tmp}/, etc.) are removed.
  1036. <item>
  1037. <example>
  1038. <var/postrm/ <tt/purge/
  1039. </example>
  1040. <item>
  1041. The package's file list is removed.
  1042. </enum>
  1043. No attempt is made to unwind after errors during removal.
  1044. <sect>Configuration file handling<label id="conffiles">
  1045. <tt/dpkg/ can do a certain amount of automatic handling of package
  1046. configuration files.
  1047. <p>
  1048. Whether this mechanism is appropriate depends on a number of factors,
  1049. but basically there are two approaches to any particular configuration
  1050. file.
  1051. <p>
  1052. The easy method is to ship a best-effort configuration in the package,
  1053. and use <tt/dpkg/'s conffile mechanism to handle updates. If the user
  1054. is unlikely to want to edit the file, but you need them to be able to
  1055. without losing their changes, and a new package with a changed version
  1056. of the file is only released infrequently, this is a good approach.
  1057. <p>
  1058. The hard method is to build the configuration file from scratch in the
  1059. <tt/postinst/ script, and to take the responsibility for fixing any
  1060. mistakes made in earlier versions of the package automatically. This
  1061. will be appropriate if the file is likely to need to be different on
  1062. each system.
  1063. <sect1>Automatic handling of configuration files by <tt/dpkg/
  1064. <p>
  1065. A package may contain a control area file called <tt/conffiles/. This
  1066. file should be a list of filenames of configuration files needing
  1067. automatic handling, separated by newlines. The filenames should be
  1068. absolute pathnames, and the files referred to should actually exist in
  1069. the package.
  1070. <p>
  1071. When a package is upgraded, during the configuration state shortly
  1072. before <tt/dpkg/ runs the package's <tt/postinst/ script, it will
  1073. process the configuration files.
  1074. <p>
  1075. For each file it checks to see whether the version of the file
  1076. included in the package is the same as the one that was included in
  1077. the last version of the package (the one that is being upgraded
  1078. from); it also compares the version currently installed on the system
  1079. with the one shipped with the last version.
  1080. <p>
  1081. If neither the user nor the package maintainer has changed the file,
  1082. it is left alone. If one or the other has changed their version, then
  1083. the changed version is preferred - ie, if the user edits their file,
  1084. but the package maintainer doesn't ship a different version, the
  1085. user's changes will stay, silently, but if the maintainer ships a new
  1086. version and the user hasn't edited it the new version will be
  1087. installed (with an informative message). If both have changed their
  1088. version the user is prompted about the problem and must resolve the
  1089. differences themselves.
  1090. <p>
  1091. The comparisons are done by calculating the MD5 message digests of the
  1092. files, and storing the MD5 of the file as it was included in the most
  1093. recent version of the package.
  1094. <p>
  1095. When a package is installed for the first time <tt/dpkg/ will install
  1096. the file that comes with it, unless that would mean overwriting a file
  1097. already on the filesystem.
  1098. <p>
  1099. However, note that <tt/dpkg/ will <em/not/ replace a conffile file
  1100. that was removed by the user (or by a script). This is necessary
  1101. because for some programs' configuration files a missing file produces
  1102. an effect hard or impossible to achieve in another way, so that a
  1103. missing file needs to be kept that way if the user did it.
  1104. <p>
  1105. Note that a package should <em/not/ modify a <tt/dpkg/-handled
  1106. conffile in its maintainer scripts. Doing this will lead to <tt/dpkg/
  1107. asking the user confusing and possibly dangerous questions when the
  1108. package is upgraded.
  1109. <sect2>Fully-featured maintainer script configuration handling
  1110. <p>
  1111. For files which contain site-specific information such as thep
  1112. hostname and networking details and so forth, it is better to create
  1113. the file in the package's <tt/postinst/ script.
  1114. <p>
  1115. This will typically involve examining the state of the rest of the
  1116. system to determine values and other information, and may involve
  1117. prompting the user for some information which can't be obtained some
  1118. other way.
  1119. <p>
  1120. When using this method there are a number of important issues which
  1121. should be considered:
  1122. <p>
  1123. The package's <tt/postinst/ should be written so that
  1124. <sect>Dangling references
  1125. <p>
  1126. <sect1>Would dangle to conffiles<label id="conffiles">
  1127. <p>
  1128. There would be a dangling xref here. Instead I've just put this dummy
  1129. text in.
  1130. <sect1>Would dangle to descriptions<label id="descriptions">
  1131. <p>
  1132. There would be a dangling xref here. Instead I've just put this dummy
  1133. text in.
  1134. </article>