programmer.sgml 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357
  1. <!doctype debiandoc system [
  2. <!entity % manuals-version-def system "manuals-version">
  3. %manuals-version-def;
  4. ]>
  5. <!--
  6. Debian Linux dpkg package installation tool.
  7. programmers' manual.
  8. Copyright (C)1996 Ian Jackson; released under the terms of the GNU
  9. General Public License, version 2 or (at your option) any later.
  10. -->
  11. <book>
  12. <title><prgn/dpkg/ programmers' manual
  13. <author>Ian Jackson <email/ijackson@gnu.ai.mit.edu/
  14. <version>version &manuals-version; (dpkg &dpkg-version;), <date>
  15. <abstract>
  16. This manual describes the technical aspects of creating Debian binary
  17. and source packages. It also documents the interface between
  18. <prgn/dselect/ and its access method scripts. It does not deal with
  19. the Debian Project policy requirements, and it assumes familiarity
  20. with <prgn/dpkg/'s functions from the system administrator's
  21. perspective.
  22. <copyright>Copyright &copy;1996 Ian Jackson.
  23. <p>
  24. This manual is free software; you may redistribute it and/or modify it
  25. under the terms of the GNU General Public License as published by the
  26. Free Software Foundation; either version 2, or (at your option) any
  27. later version.
  28. <p>
  29. This is distributed in the hope that it will be useful, but
  30. <em>without any warranty</em>; without even the implied warranty of
  31. merchantability or fitness for a particular purpose. See the GNU
  32. General Public License for more details.
  33. <p>
  34. You should have received a copy of the GNU General Public License with
  35. your Debian GNU/Linux system, in <tt>/usr/doc/copyright/GPL</tt>, or
  36. with the <prgn/dpkg/ source package as the file <tt>COPYING</tt>. If
  37. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  38. Cambridge, MA 02139, USA.
  39. <toc sect>
  40. <!-- Describes the technical interface between a package and dpkg.
  41. How to safely put shared libraries in a package. Details of dpkg's
  42. handling of individual files. Sections on when to use which feature
  43. (eg Replaces vs. Replaces/Conflicts vs. update-alternatives
  44. vs. diversions) Cross-references to the policy document (see below)
  45. where appropriate. Description of the interface between dselect and
  46. its access methods. Hints on where to start with a new package (ie,
  47. the hello package). What to do about file aliasing.
  48. file aliasing
  49. Manpages are required for: update-rc.d, diversions,
  50. update-alternatives, install-info in a package.
  51. -->
  52. <chapt id="scope">Introduction and scope of this manual
  53. <p>
  54. <prgn/dpkg/ is a suite of programs for creating binary package files
  55. and installing and removing them on Unix systems.<footnote><prgn/dpkg/
  56. is targetted primarily at Debian GNU/Linux, but may work on or be
  57. ported to other systems.</footnote>
  58. <p>
  59. The binary packages are designed for the management of installed
  60. executable programs (usually compiled binaries) and their associated
  61. data, though source code examples and documentation are provided as
  62. part of some packages.
  63. <p>
  64. This manual describes the technical aspects of creating Debian binary
  65. packages (<tt/.deb/ files). It documents the behaviour of the
  66. package management programs <prgn/dpkg/, <prgn/dselect/ et al. and and the
  67. way they interact with packages.
  68. <p>
  69. It also documents the interaction between <prgn/dselect/'s core and the
  70. access method scripts it uses to actually install the selected
  71. packages, and describes how to create a new access method.
  72. <p>
  73. This manual does not go into detail about the options and usage of the
  74. package building and installation tools. It should therefore be read
  75. in conjuction with those programs' manpages.
  76. <p>
  77. The utility programs which are provided with <prgn/dpkg/ for managing
  78. various system configuration and similar issues, such as
  79. <prgn/update-rc.d/ and <prgn/install-info/, are not described in
  80. detail here - please see their manpages.
  81. <p>
  82. It does <em/not/ describe the policy requirements imposed on Debian
  83. packages, such as the permissions on files and directories,
  84. documentation requirements, upload procedure, and so on. You should
  85. see the Debian packaging policy manual for these details. (Many of
  86. them will probably turn out to be helpful even if you don't plan to
  87. upload your package and make it available as part of the
  88. distribution.)
  89. <p>
  90. It is assumed that the reader is reasonably familiar with the
  91. <prgn/dpkg/ System Administrators' manual. Unfortunately this manual
  92. does not yet exist.
  93. <p>
  94. The Debian version of the FSF's GNU hello program is provided as an
  95. example for people wishing to create Debian packages.
  96. <p>
  97. <em>Note that this document is still a draft!</em>
  98. <chapt id="binarypkg">Binary packages
  99. <p>
  100. The binary package has two main sections. The first part consists of
  101. various control information files and scripts used by <prgn/dpkg/ when
  102. installing and removing. See <ref id="controlarea">.
  103. <p>
  104. The second part is an archive (currently a <prgn/tar/ archive)
  105. containing files and directories to be installed.
  106. <p>
  107. In the future binary packages may also contain other components, such
  108. as checksums and digital signatures.
  109. <sect id="bincreating">Creating package files - <prgn/dpkg-deb/
  110. <p>
  111. All manipulation of binary package files is done by <prgn/dpkg-deb/;
  112. it's the only program that has knowledge of the format.
  113. (<prgn/dpkg-deb/ may be invoked by calling <prgn/dpkg/, as <prgn/dpkg/ will
  114. spot that the options requested are appropriate to <prgn/dpkg-deb/ and
  115. invoke that instead with the same arguments.)
  116. <p>
  117. In order to create a binary package you must make a directory tree
  118. which contains all the files and directories you want to have in the
  119. filesystem data part of the package. In Debian-format source packages
  120. this directory is usually <tt>debian/tmp</tt>, relative to the top of
  121. the package's source tree.
  122. <p>
  123. They should have the locations (relative to the root of the directory
  124. tree you're constructing) ownerships and permissions which you want
  125. them to have on the system when they are installed.
  126. <p>
  127. With current versions of <prgn/dpkg/ the uid/username and gid/groupname
  128. mappings for the users and groups being used should be the same on the
  129. system where the package is built and the one where it is installed.
  130. <p>
  131. You need to add one special directory to the root of the miniature
  132. filesystem tree you're creating: <prgn/DEBIAN/. It should contain the
  133. control information files, notably the binary package control file
  134. (see <ref id="controlfile">).
  135. <p>
  136. The <prgn/DEBIAN/ directory will not appear in the filesystem archive of
  137. the package, and so won't be installed by <prgn/dpkg/ when the package
  138. is installed.
  139. <p>
  140. When you've prepared the package, you should invoke:
  141. <example>
  142. dpkg --build <var/directory/
  143. </example>
  144. <p>
  145. This will build the package in <tt/<var/directory/.deb/.
  146. (<prgn/dpkg/ knows that <tt/--build/ is a <prgn/dpkg-deb/ option, so it
  147. invokes <prgn/dpkg-deb/ with the same arguments to build the package.)
  148. <p>
  149. See the manpage <manref name="dpkg-deb" section=8> for details of how
  150. to examine the contents of this newly-created file. You may find the
  151. output of following commands enlightening:
  152. <example>
  153. dpkg-deb --info <var/filename/.deb
  154. dpkg-deb --contents <var/filename/.deb
  155. </example>
  156. <sect id="controlarea">Package control information files
  157. <p>
  158. The control information portion of a binary package is a collection of
  159. files with names known to <prgn/dpkg/. It will treat the contents of
  160. these files specially - some of them contain information used by
  161. <prgn/dpkg/ when installing or removing the package; others are scripts
  162. which the package maintainer wants <prgn/dpkg/ to run.
  163. <p>
  164. It is possible to put other files in the package control area, but
  165. this is not generally a good idea (though they will largely be
  166. ignored).
  167. <p>
  168. Here is a brief list of the control info files supported by <prgn/dpkg/
  169. and a summary of what they're used for.
  170. <p>
  171. <taglist>
  172. <tag><tt/control/
  173. <item>
  174. This is the key description file used by <prgn/dpkg/. It specifies the
  175. package's name and version, gives its description for the user, states
  176. its relationships with other packages, and so forth.
  177. See <ref id="controlfile">.
  178. <p>
  179. It is usually generated automatically from information in the source
  180. package by the <prgn/dpkg-gencontrol/ program, and with assistance
  181. from <prgn/dpkg-shlibdeps/. See <ref id="sourcetools">.
  182. <tag><tt/postinst/, <tt/preinst/, <tt/postrm/, <tt/prerm/
  183. <item>
  184. These are exectuable files (usually scripts) which <prgn/dpkg/ runs
  185. during installation, upgrade and removal of packages. They allow the
  186. package to deal with matters which are particular to that package or
  187. require more complicated processing than that provided by <prgn/dpkg/.
  188. Details of when and how they are called are in
  189. <ref id="maintainerscripts">.
  190. <p>
  191. It is very important to make these scripts itempotent.<footnote>That
  192. means that if it runs successfully or fails and then you call it again
  193. it doesn't bomb out, but just ensures that everything is the way it
  194. ought to be.</footnote> This is so that if an error occurs, the user
  195. interrupts <prgn/dpkg/ or some other unforeseen circumstance happens you
  196. don't leave the user with a badly-broken package.
  197. <p>
  198. The maintainer scripts are guaranteed to run with a controlling
  199. terminal and can interact with the user. If they need to prompt for
  200. passwords, do full-screen interaction or something similar you should
  201. do these things to and from <tt>/dev/tty</>, since <prgn/dpkg/ will at
  202. some point redirect scripts' standard input and output so that it can
  203. log the installation process. Likewise, because these scripts may be
  204. executed with standard output redirected into a pipe for logging
  205. purposes, Perl scripts should set unbuffered output by setting
  206. <tt/$|=1/ so that the output is printed immediately rather than being
  207. buffered.
  208. <p>
  209. Each script should return a zero exit status for success, or a nonzero
  210. one for failure.
  211. <tag><tt/conffiles/
  212. <item>
  213. This file contains a list of configuration files which are to be
  214. handled automatically by <prgn/dpkg/ (see <ref id="conffiles">). Note
  215. that not necessarily every configuration file should be listed here.
  216. <tag><tt/shlibs/
  217. <item>
  218. This file contains a list of the shared libraries supplied by the
  219. package, with dependency details for each. This is used by
  220. <prgn/dpkg-shlibdeps/ when it determines what dependencies are
  221. required in a package control file.
  222. <p>
  223. Each line is of the form:
  224. <example>
  225. <var/library-name/ <var/version-or-soname/ <var/dependencies .../
  226. </example>
  227. <p>
  228. <var/library-name/ is the name of the shared library, for example
  229. <tt/libc5/.
  230. <p>
  231. <var/version-or-soname/ is the soname of the library - ie, the thing
  232. that must exactly match for the library to be recognised by
  233. <prgn/ld.so/. Usually this is major version number of the library.
  234. <p>
  235. <var/dependencies/ has the same syntax as a dependency field in a
  236. binary package control file. It should give details of which
  237. package(s) are required to satisfy a binary built against the version
  238. of the library contained in the package. See <ref id="depsyntax">.
  239. <p>
  240. For example, if the package <tt/foo/ contains <tt/libfoo.so.1.2.3/,
  241. where the soname of the library is <tt/libfoo.so.1/, and the first
  242. version of the package which contained a minor number of at least
  243. <tt/2.3/ was <var/1.2.3-1/, then the package's <var/shlibs/ could
  244. say:
  245. <example>
  246. libfoo 1 foo (>= 1.2.3-1)
  247. </example>
  248. <p>
  249. The version-specific dependency is to avoid warnings from <prgn/ld.so/
  250. about using older shared libraries with newer binaries.
  251. </taglist>
  252. <sect id="controlfile">The main control information file: <tt/control/
  253. <p>
  254. The most important control information file used by <prgn/dpkg/ when it
  255. installs a package is <tt/control/. It contains all the package's
  256. `vital statistics'.
  257. <p>
  258. The binary package control files of packages built from Debian sources
  259. are made by a special tool, <prgn/dpkg-gencontrol/, which reads
  260. <tt>debian/control</> and <tt>debian/changelog</> to find the
  261. information it needs. See <ref id="sourcepkg"> for more details.
  262. <p>
  263. The fields in binary package control files are:
  264. <list compact>
  265. <item><qref id="f-Package"><tt/Package/</> (mandatory)
  266. <item><qref id="versions"><tt/Version/</> (mandatory)
  267. <item><qref id="f-Architecture"><tt/Architecture/</>
  268. (mandatory)<footnote>This field should appear in all packages, though
  269. <prgn/dpkg/ doesn't require it yet so that old packages can still be
  270. installed.</footnote>
  271. <item><qref id="relationships"><tt/Depends/, <tt/Provides/ et al.</>
  272. <item><qref id="f-Essential"><tt/Essential/</>
  273. <item><qref id="f-Maintainer"><tt/Maintainer/</>
  274. <item><qref id="f-classification"><tt/Section/, <tt/Priority/</>
  275. <item><qref id="f-Source"><tt/Source/</>
  276. <item><qref id="descriptions"><tt/Description/</>
  277. <item><qref id="f-Installed-Size"><tt/Installed-Size/</>
  278. </list>
  279. <p>
  280. A description of the syntax of control files and the purpose of these
  281. fields is available in <ref id="controlfields">.
  282. <chapt id="sourcepkg">Source packages
  283. <p>
  284. The Debian binary packages in the distribution are generated from
  285. Debian sources, which are in a special format to assist the easy and
  286. automatic building of binaries.
  287. <p>
  288. There was a previous version of the Debian source format, which is now
  289. being phased out. Instructions for converting an old-style package
  290. are given in the Debian policy manual.
  291. <sect id="sourcetools">Tools for processing source packages
  292. <p>
  293. Various tools are provided for manipulating source packages; they pack
  294. and unpack sources and help build of binary packages and help manage
  295. the distribution of new versions.
  296. <p>
  297. They are introduced and typical uses described here; see <manref
  298. name=dpkg-source section=1> for full documentation about their
  299. arguments and operation.
  300. <p>
  301. For examples of how to construct a Debian source package, and how to
  302. use those utilities that are used by Debian source packages, please
  303. see the <prgn/hello/ example package.
  304. <sect1><prgn/dpkg-source/ - packs and unpacks Debian source packages
  305. <p>
  306. This program is frequently used by hand, and is also called from
  307. package-independent automated building scripts such as
  308. <prgn/dpkg-buildpackage/.
  309. <p>
  310. To unpack a package it is typically invoked with
  311. <example>
  312. dpkg-source -x <var>.../path/to/filename</>.dsc
  313. </example>
  314. with the <tt/<var/filename/.tar.gz/ and
  315. <tt/<var/filename/.diff.gz/ (if applicable) in the same directory. It
  316. unpacks into <tt/<var/package/-<var/version//, and if applicable
  317. <tt/<var/package/-<var/version/.orig/, in the current directory.
  318. <p>
  319. To create a packed source archive it is typically invoked:
  320. <example>
  321. dpkg-source -b <var/package/-<var/version/
  322. </example>
  323. This will create the <tt/.dsc/, <tt/.tar.gz/ and <tt/.diff.gz/ (if
  324. appropriate) in the current directory. <prgn/dpkg-source/ does not
  325. clean the source tree first - this must be done separately if it is
  326. required.
  327. <p>
  328. See also <ref id="sourcearchives">.
  329. <sect1><prgn/dpkg-buildpackage/ - overall package-building control
  330. script
  331. <p>
  332. <prgn/dpkg-buildpackage/ is a script which invokes <prgn/dpkg-source/,
  333. the <tt>debian/rules</> targets <prgn/clean/, <prgn/build/ and
  334. <prgn/binary/, <prgn/dpkg-genchanges/ and <prgn/pgp/ to build a signed
  335. source and binary package upload.
  336. <p>
  337. It is usually invoked by hand from the top level of the built or
  338. unbuilt source directory. It may be invoked with no arguments; useful
  339. arguments include:
  340. <taglist compact>
  341. <tag><tt/-uc/, <tt/-us/
  342. <item>Do not PGP-sign the <tt/.changes/ file or the source package
  343. <tt/.dsc/ file, respectively.
  344. <tag><tt/-p<var/pgp-command//
  345. <item>Invoke <var/pgp-command/ instead of finding <tt/pgp/ on the
  346. <prgn/PATH/. <var/pgp-command/ must behave just like <prgn/pgp/.
  347. <tag><tt/-r<var/root-command//
  348. <item>When root privilege is required, invoke the command
  349. <var/root-command/. <var/root-command/ should invoke its first
  350. argument as a command, from the <prgn/PATH/ if necessary, and pass its
  351. second and subsequent arguments to the command it calls. If no
  352. <var/root-command/ is supplied then <var/dpkg-buildpackage/ will take
  353. no special action to gain root privilege, so that for most packages it
  354. will have to be invoked as root to start with.
  355. <tag><tt/-b/, <tt/-B/
  356. <item>Two types of binary-only build and upload - see <manref
  357. name=dpkg-source section=1>.
  358. </taglist>
  359. <sect1><prgn/dpkg-gencontrol/ - generates binary package control files
  360. <p>
  361. This program is usually called from <tt>debian/rules</> (see <ref
  362. id="sourcetree">) in the top level of the source tree.
  363. <p>
  364. This is usually done just before the files and directories in the
  365. temporary directory tree where the package is being built have their
  366. permissions and ownerships set and the package is constructed using
  367. <prgn/dpkg-deb/<footnote>This is so that the control file which is
  368. produced has the right permissions</footnote>.
  369. <p>
  370. <prgn/dpkg-gencontrol/ must be called after all the files which are to
  371. go into the package have been placed in the temporary build directory,
  372. so that its calculation of the installed size of a package is correct.
  373. <p>
  374. It is also necessary for <prgn/dpkg-gencontrol/ to be run after
  375. <prgn/dpkg-shlibdeps/ so that the variable substitutions created by
  376. <prgn/dpkg-shlibdeps/ in <tt>debian/substvars</> are available.
  377. <p>
  378. For a package which generates only one binary package, and which
  379. builds it in <tt>debian/tmp</> relative to the top of the source
  380. package, it is usually sufficient to call:
  381. <example>
  382. dpkg-gencontrol
  383. </example>
  384. <p>
  385. Sources which build several binaries will typically need something
  386. like:
  387. <example>
  388. dpkg-gencontrol -Pdebian/tmp-<var/pkg/ -p<var/package/
  389. </example>
  390. The <tt/-P/ tells <prgn/dpkg-gencontrol/ that the package is being
  391. built in a non-default directory, and the <tt/-p/ tells it which
  392. package's control file should be generated.
  393. <p>
  394. <prgn/dpkg-gencontrol/ also adds information to the list of files in
  395. <tt>debian/files</>, for the benefit of (for example) a future
  396. invocation of <prgn/dpkg-genchanges/.
  397. <sect1><prgn/dpkg-shlibdeps/ - calculates shared library dependencies
  398. <p>
  399. This program is usually called from <tt>debian/rules</> just before
  400. <prgn/dpkg-gencontrol/ (see <ref id="sourcetree">), in the top level
  401. of the source tree.
  402. <p>
  403. Its arguments are executables<footnote>They may be specified either
  404. in the locations in the source tree where they are created or in the
  405. locations in the temporary build tree where they are installed prior
  406. to binary package creation.</footnote> for which shared library
  407. dependencies should be included in the binary package's control file.
  408. <p>
  409. If some of the executable(s) shared libraries should only warrant a
  410. <tt/Recommends/ or <tt/Suggests/, or if some warrant a
  411. <tt/Pre-Depends/, this can be achieved by using the
  412. <tt/-d<var/dependency-field// option before those executable(s).
  413. (Each <tt/-d/ option takes effect until the next <tt/-d/.)
  414. <p>
  415. <prgn/dpkg-shlibdeps/ does not directly cause the output control file
  416. to be modified. Instead by default it adds to the
  417. <tt>debian/substvars</> file variable settings like
  418. <tt/shlibs:Depends/. These variable settings must be referenced in
  419. dependency fields in the appropriate per-binary-package sections of
  420. the source control file.
  421. <p>
  422. For example, the <prgn/procps/ package generates two kinds of
  423. binaries, simple C binaries like <prgn/ps/ which require a
  424. predependency and full-screen ncurses binaries like <prgn/top/ which
  425. require only a recommendation. It can say in its <tt>debian/rules</>:
  426. <example>
  427. dpkg-shlibdeps -dPre-Depends ps -dRecommends top
  428. </example>
  429. and then in its main control file <tt>debian/control</>:
  430. <example>
  431. <var/.../
  432. Package: procps
  433. Pre-Depends: ${shlibs:Pre-Depends}
  434. Recommends: ${shlibs:Recommends}
  435. <var/.../
  436. </example>
  437. <p>
  438. Sources which produce several binary packages with different shared
  439. library dependency requirements can use the <tt/-p<var/varnameprefix//
  440. option to override the default <tt/shlib:/ prefix (one invocation of
  441. <prgn/dpkg-shlibdeps/ per setting of this option). They can thus
  442. produce several sets of dependency variables, each of the form
  443. <tt/<var/varnameprefix/:<var/dependencyfield//, which can be referred
  444. to in the appropriate parts of the binary package control files.
  445. <sect1><prgn/dpkg-distaddfile/ - adds a file to <tt>debian/files</>
  446. <p>
  447. Some packages' uploads need to include files other than the source and
  448. binary package files.
  449. <p>
  450. <prgn/dpkg-distaddfile/ adds a file to the <tt>debian/files</> file so
  451. that it will be included in the <tt/.changes/ file when
  452. <prgn/dpkg-genchanges/ is run.
  453. <p>
  454. It is usually invoked from the <prgn/binary/ target of
  455. <tt>debian/rules</>:
  456. <example>
  457. dpkg-distaddfile <var/filename/ <var/section/ <var/priority/
  458. </example>
  459. The <var/filename/ is relative to the directory where
  460. <prgn/dpkg-genchanges/ will expect to find it - this is usually the
  461. directory above the top level of the source tree. The
  462. <tt>debian/rules</> target should put the file there just before or
  463. just after calling <prgn/dpkg-distaddfile/.
  464. <p>
  465. The <var/section/ and <var/priority/ are passed unchanged into the
  466. resulting <tt/.changes/ file. See <ref id="f-classification">.
  467. <sect1><prgn/dpkg-genchanges/ - generates a <tt/.changes/ upload
  468. control file
  469. <p>
  470. This program is usually called by package-independent automatic
  471. building scripts such as <prgn/dpkg-buildpackage/, but it may also be
  472. called by hand.
  473. <p>
  474. It is usually called in the top level of a built source tree, and when
  475. invoked with no arguments will print out a straightforward
  476. <tt/.changes/ file based on the information in the source package's
  477. changelog and control file and the binary and source packages which
  478. should have been built.
  479. <sect1><prgn/dpkg-parsechangelog/ - produces parsed representation of
  480. a changelog
  481. <p>
  482. This program is used internally by <prgn/dpkg-source/ et al. It may
  483. also occasionally be useful in <tt>debian/rules</> and elsewhere. It
  484. parses a changelog, <tt>debian/changelog</> by default, and prints a
  485. control-file format representation of the information in it to
  486. standard output.
  487. <sect id="sourcetree">The Debianised source tree
  488. <p>
  489. The source archive scheme described later is intended to allow a
  490. Debianised source tree with some associated control information to be
  491. reproduced and transported easily. The Debianised source tree is a
  492. version of the original program with certain files added for the
  493. benefit of the Debianisation process, and with any other changes
  494. required made to the rest of the source code and installation scripts.
  495. <p>
  496. The extra files created for Debian are in the subdirectory <tt/debian/
  497. of the top level of the Debianised source tree. They are described
  498. below.
  499. <sect1><tt>debian/rules</tt> - the main building script
  500. <p>
  501. This file is an executable makefile, and contains the package-specific
  502. recipies for compiling the package and building binary package(s) out
  503. of the source.
  504. <p>
  505. It must start with the line <tt>#!/usr/bin/make -f</tt>, so that it
  506. can be invoked by saying its name rather than invoking <prgn/make/
  507. explicitly.
  508. <p>
  509. The targets which are required to be present are:
  510. <taglist>
  511. <tag/<tt/build//
  512. <item>
  513. This should perform all non-interactive configuration and compilation
  514. of the package. If a package has an interactive pre-build
  515. configuration routine, the Debianised source package should be built
  516. after this has taken place, so that it can be built without rerunning
  517. the configuration.
  518. <p>
  519. For some packages, notably ones where the same source tree is compiled
  520. in different ways to produce two binary packages, the <prgn/build/
  521. target does not make much sense. For these packages it is good enough
  522. to provide two (or more) targets (<tt/build-a/ and <tt/build-b/ or
  523. whatever) for each of the ways of building the package, and a
  524. <prgn/build/ target that does nothing. The <prgn/binary/ target will have
  525. to build the package in each of the possible ways and make the binary
  526. package out of each.
  527. <p>
  528. The <prgn/build/ target must not do anything that might require root
  529. privilege.
  530. <p>
  531. The <prgn/build/ target may need to run <prgn/clean/ first - see below.
  532. <p>
  533. When a package has a configuration routine that takes a long time, or
  534. when the makefiles are poorly designed, or when <prgn/build/ needs to
  535. run <prgn/clean/ first, it is a good idea to <tt/touch build/ when the
  536. build process is complete. This will ensure that if <tt>debian/rules
  537. build</tt> is run again it will not rebuild the whole program.
  538. <tag/<tt/binary/, <tt/binary-arch/, <tt/binary-indep/
  539. <item>
  540. The <prgn/binary/ target should be all that is necessary for the user
  541. to build the binary package. It is split into two parts:
  542. <prgn/binary-arch/ builds the packages' output files which are
  543. specific to a particular architecture, and <prgn/binary-indep/
  544. builds those which are not.
  545. <p>
  546. <prgn/binary/ should usually be a target with no commands which simply
  547. depends on <prgn/binary-arch/ and <prgn/binary-indep/.
  548. <p>
  549. Both <prgn/binary-*/ targets should depend on the <prgn/build/ target,
  550. above, so that the package is built if it has not been already. It
  551. should then create the relevant binary package(s), using
  552. <prgn/dpkg-gencontrol/ to make their control files and <prgn/dpkg-deb/
  553. to build them and place them in the parent of the top level directory.
  554. <p>
  555. If one of the <prgn/binary-*/ targets has nothing to do (this will be
  556. always be the case if the source generates only a single binary
  557. package, whether architecture-dependent or not) it <em/must/ still
  558. exist, but should always succeed.
  559. <p>
  560. <ref id="binarypkg"> describes how to construct binary packages.
  561. <p>
  562. The <prgn/binary/ targets must be invoked as root.
  563. <tag/<tt/clean//
  564. <item>
  565. This should undo any effects that the <prgn/build/ and <prgn/binary/
  566. targets may have had, except that it should leave alone any output
  567. files created in the parent directory by a run of <prgn/binary/.
  568. <p>
  569. If a <prgn/build/ file is touched at the end of the <prgn/build/ target,
  570. as suggested above, it must be removed as the first thing that
  571. <prgn/clean/ does, so that running <prgn/build/ again after an interrupted
  572. <prgn/clean/ doesn't think that everything is already done.
  573. <p>
  574. The <prgn/clean/ target must be invoked as root if <prgn/binary/ has
  575. been invoked since the last <prgn/clean/, or if <prgn/build/ has been
  576. invoked as root (since <prgn/build/ may create directories, for
  577. example).
  578. <tag/<tt/get-orig-source//
  579. <item>
  580. This target fetches the most recent version of the original source
  581. package from a canonical archive site (via FTP or WWW, for example),
  582. does any necessary rearrangement to turn it into the original source
  583. tarfile format described below, and leaves it in the current directory.
  584. <p>
  585. This target may be invoked in any directory, and should take care to
  586. clean up any temporary files it may have left.
  587. <p>
  588. This target is optional, but providing it if possible is a good idea.
  589. </taglist>
  590. The <prgn/build/, <prgn/binary/ and <prgn/clean/ targets must be
  591. invoked with a current directory of the package's top-level
  592. directory.
  593. <p>
  594. Additional targets may exist in <tt>debian/rules</tt>, either as
  595. published or undocumented interfaces or for the package's internal
  596. use.
  597. <sect1><tt>debian/control</tt>
  598. <p>
  599. This file contains version-independent details about the source
  600. package and about the binary packages it creates.
  601. <p>
  602. It is a series of sets of control fields, each syntactically similar
  603. to a binary package control file. The sets are separated by one or
  604. more blank lines. The first set is information about the source
  605. package in general; each subsequent set describes one binary package
  606. that the source tree builds.
  607. <p>
  608. The syntax and semantics of the fields are described below in
  609. <ref id="controlfields">.
  610. <p>
  611. The general (binary-package-independent) fields are:
  612. <list compact>
  613. <item><qref id="f-Source"><tt/Source/</> (mandatory)
  614. <item><qref id="f-Maintainer"><tt/Maintainer/</>
  615. <item><qref id="f-classification"><tt/Section/ and <tt/Priority/</>
  616. (classification, mandatory)
  617. <item><qref id="f-Standards-Version"><tt/Standards-Version/</>
  618. </list>
  619. <p>
  620. The per-binary-package fields are:
  621. <list compact>
  622. <item><qref id="f-Package"><tt/Package/</> (mandatory)
  623. <item><qref id="f-Architecture"><tt/Architecture/</> (mandatory)
  624. <item><qref id="descriptions"><tt/Description/</>
  625. <item><qref id="f-classification"><tt/Section/ and <tt/Priority/</> (classification)
  626. <item><qref id="f-Essential"><tt/Essential/</>
  627. <item><qref id="relationships"><tt/Depends/ et al.</> (package interrelationships)
  628. </list>
  629. <p>
  630. These fields are used by <prgn/dpkg-gencontrol/ to generate control
  631. files for binary packages (see below), by <prgn/dpkg-genchanges/ to
  632. generate the <tt/.changes/ file to accompany the upload, and by
  633. <prgn/dpkg-source/ when it creates the <tt/.dsc/ source control file as
  634. part of a source archive.
  635. <p>
  636. The fields here may contain variable references - their values will be
  637. substituted by <prgn/dpkg-gencontrol/, <prgn/dpkg-genchanges/ or
  638. <prgn/dpkg-source/ when they generate output control files. See <ref
  639. id="srcsubstvars"> for details.
  640. <p>
  641. <sect2>User-defined fields
  642. <p>
  643. Additional user-defined fields may be added to the source package
  644. control file. Such fields will be ignored, and not copied to (for
  645. example) binary or source package control files or upload control
  646. files.
  647. <p>
  648. If you wish to add additional unsupported fields to these output files
  649. you should use the mechanism described here.
  650. <p>
  651. Fields in the main source control information file with names starting
  652. <tt/X/, followed by one or more of the letters <tt/BCS/ and a hyphen
  653. <tt/-/, will be copied to the output files. Only the part of the
  654. field name after the hyphen will be used in the output file. Where
  655. the letter <tt/B/ is used the field will appear in binary package
  656. control files, where the letter <tt/S/ is used in source package
  657. control files and where <tt/C/ is used in upload control
  658. (<tt/.changes/) files.
  659. <p>
  660. For example, if the main source information control file contains the
  661. field
  662. <example>
  663. XBS-Comment: I stand between the candle and the star.
  664. </example>
  665. then the binary and source package control files will contain the
  666. field
  667. <example>
  668. Comment: I stand between the candle and the star.
  669. </example>
  670. <sect1 id="dpkgchangelog"><tt>debian/changelog</>
  671. <p>
  672. This file records the changes to the Debian-specific parts of the
  673. package<footnote>Though there is nothing stopping an author who is
  674. also the Debian maintainer from using it for all their changes, it
  675. will have to be renamed if the Debian and upstream maintainers become
  676. different people.</footnote>.
  677. <p>
  678. It has a special format which allows the package building tools to
  679. discover which version of the package is being built and find out
  680. other release-specific information.
  681. <p>
  682. That format is a series of entries like this:
  683. <example>
  684. <var/package/ (<var/version/) <var/distribution(s)/; urgency=<var/urgency/
  685. * <var/change details/
  686. <var/more change details/
  687. * <var/even more change details/
  688. -- <var/maintainer name and email address/ <var/date/
  689. </example>
  690. <p>
  691. <var/package/ and <var/version/ are the source package name and
  692. version number. <var/distribution(s)/ lists the distributions where
  693. this version should be installed when it is uploaded - it is copied to
  694. the <tt/Distribution/ field in the <tt/.changes/ file. See <ref
  695. id="f-Distribution">.
  696. <p>
  697. <var/urgency/ is the value for the <tt/Urgency/ field in the
  698. <tt/.changes/ file for the upload. See <ref id="f-Urgency">. It is
  699. not possible to specify an urgency containing commas; commas are used
  700. to separate <tt/<var/keyword/=<var/value// settings in the <prgn/dpkg/
  701. changelog format (though there is currently only one useful
  702. <var/keyword/, <tt/urgency/).
  703. <p>
  704. The change details may in fact be any series of lines starting with at
  705. least two spaces, but conventionally each change starts with an
  706. asterisk and a separating space and continuation lines are indented so
  707. as to bring them in line with the start of the text above. Blank
  708. lines may be used here to separate groups of changes, if desired.
  709. <p>
  710. The maintainer name and email address should <em/not/ necessarily be
  711. those of the usual package maintainer. They should be the details of
  712. the person doing <em/this/ version. The information here will be
  713. copied to the <tt/.changes/ file, and then later used to send an
  714. acknowledgement when the upload has been installed.
  715. <p>
  716. The <var/date/ should be in RFC822 format<footnote>This is generated
  717. by the <prgn/822-date/ program.</footnote>; it should include the
  718. timezone specified numerically, with the timezone name or abbreviation
  719. optionally present as a comment.
  720. <p>
  721. The first `title' line with the package name should start at the left
  722. hand margin; the `trailer' line with the maintainer and date details
  723. should be preceded by exactly one space. The maintainer details and
  724. the date must be separated by exactly two spaces.
  725. <p>
  726. An Emacs mode for editing this format is available: it is called
  727. <tt/debian-changelog-mode/. You can have this mode selected
  728. automatically when you edit a Debian changelog by adding a local
  729. variables clause to the end of the changelog.
  730. <sect2>Defining alternative changelog formats
  731. <p>
  732. It is possible to use a different format to the standard one, by
  733. providing a parser for the format you wish to use.
  734. <p>
  735. In order to have <tt/dpkg-parsechangelog/ run your parser, you must
  736. include a line within the last 40 lines of your file matching the Perl
  737. regular expression:
  738. <tt>\schangelog-format:\s+([0-9a-z]+)\W</tt>
  739. The part in parentheses should be the name of the format. For
  740. example, you might say:
  741. <example>
  742. @@@ changelog-format: joebloggs @@@
  743. </example>
  744. Changelog format names are non-empty strings of alphanumerics.
  745. <p>
  746. If such a line exists then <tt/dpkg-parsechangelog/ will look for the
  747. parser as <tt>/usr/lib/dpkg/parsechangelog/<var/format-name/</> or
  748. <tt>/usr/local/lib/dpkg/parsechangelog/<var/format-name/</>; it is an
  749. error for it not to find it, or for it not to be an executable
  750. program. The default changelog format is <tt/dpkg/, and a parser for
  751. it is provided with the <tt/dpkg/ package.
  752. <p>
  753. The parser will be invoked with the changelog open on standard input
  754. at the start of the file. It should read the file (it may seek if it
  755. wishes) to determine the information required and return the parsed
  756. information to standard output in the form of a series of control
  757. fields in the standard format. By default it should return
  758. information about only the most recent version in the changelog; it
  759. should accept a <tt/-v<var/version// option to return changes
  760. information from all versions present <em/strictly after/
  761. <var/version/, and it should then be an error for <var/version/ not to
  762. be present in the changelog.
  763. <p>
  764. The fields are:
  765. <list compact>
  766. <item><qref id="f-Source"><tt/Source/</>
  767. <item><qref id="versions"><tt/Version/</> (mandatory)
  768. <item><qref id="f-Distribution"><tt/Distribution/</> (mandatory)
  769. <item><qref id="f-Urgency"><tt/Urgency/</> (mandatory)
  770. <item><qref id="f-Maintainer"><tt/Maintainer/</> (mandatory)
  771. <item><qref id="f-Date"><tt/Date/</>
  772. <item><qref id="f-Changes"><tt/Changes/</> (mandatory)
  773. </list>
  774. <p>
  775. If several versions are being returned (due to the use of <tt/-v/),
  776. the urgency value should be of the highest urgency code listed at the
  777. start of any of the versions requested followed by the concatenated
  778. (space-separated) comments from all the versions requested; the
  779. maintainer, version, distribution and date should always be from the
  780. most recent version.
  781. <p>
  782. For the format of the <tt/Changes/ field see <ref id="f-Changes">.
  783. <p>
  784. If the changelog format which is being parsed always or almost always
  785. leaves a blank line between individual change notes these blank lines
  786. should be stripped out, so as to make the resulting output compact.
  787. <p>
  788. If the changelog format does not contain date or package name
  789. information this information should be omitted from the output. The
  790. parser should not attempt to synthesise it or find it from other
  791. sources.
  792. <p>
  793. If the changelog does not have the expected format the parser should
  794. exit with a nonzero exit status, rather than trying to muddle through
  795. and possibly generating incorrect output.
  796. <p>
  797. A changelog parser may not interact with the user at all.
  798. <sect1 id="srcsubstvars"><tt>debian/substvars</> and variable substitutions
  799. <p>
  800. When <prgn/dpkg-gencontrol/, <prgn/dpkg-genchanges/ and
  801. <prgn/dpkg-source/ generate control files they do variable
  802. substitutions on their output just before writing it. Variable
  803. substitutions have the form <tt/${<var/variable-name/}/. The optional
  804. file <tt>debian/substvars</> contains variable substitutions to be
  805. used; variables can also be set directly from <tt>debian/rules</>
  806. using the <tt/-V/ option to the source packaging commands, and certain
  807. predefined variables are available.
  808. <p>
  809. The file may be a static part of the source archive, or generated and
  810. modified dynamically by <tt>debian/rules</> targets. In the latter
  811. case it must be removed by the <prgn/clean/ target.
  812. <p>
  813. See <manref name=dpkg-source section=1> for full details about source
  814. variable substitutions, including the format of
  815. <tt>debian/substvars</>.
  816. <sect1><tt>debian/files</>
  817. <p>
  818. This file is not a permanent part of the source tree; it is used while
  819. building packages to record which files are being generated.
  820. <prgn/dpkg-genchanges/ uses it when it generates a <tt/.changes/ file.
  821. <p>
  822. It should not exist in a shipped source package, and so it (and any
  823. backup files or temporary files such as
  824. <tt/files.new/<footnote><tt/files.new/ is used as a temporary file by
  825. <prgn/dpkg-gencontrol/ and <prgn/dpkg-distaddfile/ - they write a new
  826. version of <tt/files/ here before renaming it, to avoid leaving a
  827. corrupted copy if an error occurs</footnote>) should be removed by the
  828. <prgn/clean/ target. It may also be wise to ensure a fresh start by
  829. emptying or removing it at the start of the <prgn/binary/ target.
  830. <p>
  831. <prgn/dpkg-gencontrol/ adds an entry to this file for the <tt/.deb/
  832. file that will be created by <prgn/dpkg-deb/ from the control file
  833. that it generates, so for most packages all that needs to be done with
  834. this file is to delete it in <prgn/clean/.
  835. <p>
  836. If a package upload includes files besides the source package and any
  837. binary packages whose control files were made with
  838. <prgn/dpkg-gencontrol/ then they should be placed in the parent of the
  839. package's top-level directory and <prgn/dpkg-distaddfile/ should be
  840. called to add the file to the list in <tt>debian/files</>.
  841. <sect1><tt>debian/tmp</>
  842. <p>
  843. This is the canonical temporary location for the construction of
  844. binary packages by the <prgn/binary/ target. The directory <tt/tmp/
  845. serves as the root of the filesystem tree as it is being constructed
  846. (for example, by using the package's upstream makefiles install
  847. targets and redirecting the output there), and it also contains the
  848. <tt/DEBIAN/ subdirectory. See <ref id="bincreating">.
  849. <p>
  850. If several binary packages are generated from the same source tree it
  851. is usual to use several <tt>debian/tmp<var/something/</> directories,
  852. for example <tt/tmp-a/ or <tt/tmp-doc/.
  853. <p>
  854. Whatever <tt>tmp</> directories are created and used by <prgn/binary/
  855. must of course be removed by the <prgn/clean/ target.
  856. <sect id="sourcearchives">Source packages as archives
  857. <p>
  858. As it exists on the FTP site, a Debian source package consists of
  859. three related files. You must have the right versions of all three to
  860. be able to use them.
  861. <p>
  862. <taglist>
  863. <tag/Debian source control file - <tt/.dsc//
  864. <item>
  865. This file contains a series of fields, identified and separated just
  866. like the fields in the control file of a binary package. The fields
  867. are listed below; their syntax is described above, in
  868. <ref id="controlfields">.
  869. <list compact>
  870. <item><qref id="f-Source"><tt/Source/</>
  871. <item><qref id="versions"><tt/Version/</>
  872. <item><qref id="f-Maintainer"><tt/Maintainer/</>
  873. <item><qref id="f-Binary"><tt/Binary/</>
  874. <item><qref id="f-Architecture"><tt/Architecture/</>
  875. <item><qref id="f-Standards-Version"><tt/Standards-Version/</>
  876. <item><qref id="f-Files"><tt/Files/</>
  877. </list>
  878. <p>
  879. The source package control file is generated by <prgn/dpkg-source/
  880. when it builds the source archive, from other files in the source
  881. package, described above. When unpacking it is checked against the
  882. files and directories in the other parts of the source package, as
  883. described below.
  884. <tag/Original source archive - <tt/<var/package/_<var/upstream-version/.orig.tar.gz//
  885. <item>
  886. This is a compressed (with <tt/gzip -9/) <prgn/tar/ file containing
  887. the source code from the upstream authors of the program. The tarfile
  888. unpacks into a directory
  889. <tt/<var/package/-<var/upstream-version/.orig/, and does not contain
  890. files anywhere other than in there or in its subdirectories.
  891. <tag/Debianisation diff - <tt/<var/package/_<var/version-revision/.diff.gz//
  892. <item>
  893. This is a unified context diff (<tt/diff -u/) giving the changes which
  894. are required to turn the original source into the Debian source.
  895. These changes may only include editing and creating plain files. The
  896. permissions of files, the targets of symbolic links and the
  897. characteristics of special files or pipes may not be changed and no
  898. files may be removed or renamed.
  899. <p>
  900. All the directories in the diff must exist, except the <tt/debian/
  901. subdirectory of the top of the source tree, which will be created by
  902. <prgn/dpkg-source/ if necessary when unpacking.
  903. <p>
  904. The <prgn/dpkg-source/ program will automatically make the
  905. <tt>debian/rules</tt> file executable (see below).
  906. </taglist>
  907. <p>
  908. If there is no original source code - for example, if the package is
  909. specially prepared for Debian or the Debian maintainer is the same as
  910. the upstream maintainer - the format is slightly different: then there
  911. is no diff, and the tarfile is named
  912. <tt/<var/package/_<var/version/.tar.gz</> and contains a directory
  913. <tt/<var/package/-<var/version/</>.
  914. <sect>Unpacking a Debian source package without <prgn/dpkg-source/
  915. <p>
  916. <tt/dpkg-source -x/ is the recommended way to unpack a Debian source
  917. package. However, if it is not available it is possible to unpack a
  918. Debian source archive as follows:
  919. <enumlist compact>
  920. <item>Untar the tarfile, which will create a <tt/.orig/ directory.
  921. <item>Rename the <tt/.orig/ directory to
  922. <tt/<var/package/-<var/version//.
  923. <item>Create the subdirectory <tt/debian/ at the top of the source
  924. tree.
  925. <item>Apply the diff using <tt/patch -p0/.
  926. <item>Untar the tarfile again if you want a copy of the original
  927. source code alongside the Debianised version.
  928. </enumlist>
  929. <p>
  930. It is not possible to generate a valid Debian source archive without
  931. using <prgn/dpkg-source/. In particular, attempting to use
  932. <prgn/diff/ directly to generate the <tt/.diff.gz/ file will not work.
  933. <sect1>Restrictions on objects in source packages
  934. <p>
  935. The source package may not contain any device special files, sockets
  936. or setuid or setgid files.<footnote>Setgid directories are
  937. allowed.</footnote>
  938. <p>
  939. The source packaging tools manage the changes between the original and
  940. Debianised source using <prgn/diff/ and <prgn/patch/. Turning the
  941. original source tree as included in the <tt/.orig.tar.gz/ into the
  942. debianised source must not involve any changes which cannot be handled
  943. by these tools. Problematic changes which cause <prgn/dpkg-source/ to
  944. halt with an error when building the source package are:
  945. <list compact>
  946. <item>Adding or removing symbolic links, sockets or pipes.
  947. <item>Changing the targets of symbolic links.
  948. <item>Creating directories, other than <tt/debian/.
  949. <item>Changes to the contents of binary files.
  950. </list>
  951. Changes which cause <prgn/dpkg-source/ to print a warning but continue
  952. anyway are:
  953. <list compact>
  954. <item>Removing files, directories or symlinks. <footnote>Renaming a
  955. file is not treated specially - it is seen as the removal of the old
  956. file (which generates a warning, but is otherwise ignored), and the
  957. creation of the new one.</footnote>
  958. <item>Changed text files which are missing the usual final newline
  959. (either in the original or the modified source tree).
  960. </list>
  961. Changes which are not represented, but which are not detected by
  962. <prgn/dpkg-source/, are:
  963. <list compact>
  964. <item>Changing the permissions of files (other than
  965. <tt>debian/rules</>) and directories.
  966. </list>
  967. <p>
  968. The <tt/debian/ directory and <tt>debian/rules</> are handled
  969. specially by <prgn/dpkg-source/ - before applying the changes it will
  970. create the <tt/debian/ directory, and afterwards it will make
  971. <tt>debian/rules</> world-exectuable.
  972. <chapt id="controlfields">Control files and their fields
  973. <p>
  974. Many of the tools in the <prgn/dpkg/ suite manipulate data in a common
  975. format, known as control files. Binary and source packages have
  976. control data as do the <tt/.changes/ files which control the
  977. installation of uploaded files, and <prgn/dpkg/'s internal databases
  978. are in a similar format.
  979. <sect>Syntax of control files
  980. <p>
  981. A file consists of one or more paragraphs of fields. The paragraphs
  982. are separated by blank lines. Some control files only allow one
  983. paragraph; others allow several, in which case each paragraph often
  984. refers to a different package.
  985. <p>
  986. Each paragraph is a series of fields and values; each field consists
  987. of a name, followed by a colon and the value. It ends at the end of
  988. the line. Horizontal whitespace (spaces and tabs) may occur before or
  989. after the value and is ignored there; it is conventional to put a
  990. single space after the colon.
  991. <p>
  992. Some fields' values may span several lines; in this case each
  993. continuation line <em/must/ start with a space or tab. Any trailing
  994. spaces or tabs at the end of individual lines of a field value are
  995. ignored.
  996. <p>
  997. Except where otherwise stated only a single line of data is allowed
  998. and whitespace is not significant in a field body. Whitespace may
  999. never appear inside names (of packages, architectures, files or
  1000. anything else), version numbers or in between the characters of
  1001. multi-character version relationships.
  1002. <p>
  1003. Field names are not case-sensitive, but it is usual to capitalise the
  1004. fields using mixed case as shown below.
  1005. <p>
  1006. Blank lines, or lines consisting only of spaces and tabs, are not
  1007. allowed within field values or between fields - that would mean a new
  1008. paragraph.
  1009. <p>
  1010. It is important to note that there are several fields which are
  1011. optional as far as <prgn/dpkg/ and the related tools are concerned,
  1012. but which must appear in every Debian package, or whose omission may
  1013. cause problems. When writing the control files for Debian packages
  1014. you <em/must/ read the Debian policy manual in conjuction with the
  1015. details below and the list of fields for the particular file.
  1016. <sect>List of fields
  1017. <sect1 id="f-Package"><tt/Package/
  1018. <p>
  1019. The name of the binary package. Package names consist of the
  1020. alphanumerics and <tt/+/ <tt/-/ <tt/./ (plus, minus and full
  1021. stop).<footnote>The characters <tt/@/ <tt/:/ <tt/=/ <tt/%/ <tt/_/ (at,
  1022. colon, equals, percent and underscore) used to be legal and are still
  1023. accepted when found in a package file, but may not be used in new
  1024. packages</footnote>
  1025. <p>
  1026. They must be at least two characters and must start with an
  1027. alphanumeric. In current versions of dpkg they are sort of
  1028. case-sensitive<footnote>This is a bug.</footnote>; use lowercase
  1029. package names unless the package you're building (or referring to, in
  1030. other fields) is already using uppercase.
  1031. <sect1 id="f-Version"><tt/Version/
  1032. <p>
  1033. This lists the source or binary package's version number - see <ref
  1034. id="versions">.
  1035. <sect1 id="f-Architecture"><tt/Architecture/
  1036. <p>
  1037. This is the architecture string; it is a single word for the CPU
  1038. architecture.
  1039. <p>
  1040. <prgn/dpkg/ will check the declared architecture of a binary package
  1041. against its own compiled-in value before it installs it.
  1042. <p>
  1043. The special value <tt/all/ indicates that the package is
  1044. architecture-independent.
  1045. <p>
  1046. In the main <tt>debian/control</> file in the source package, or in
  1047. the source package control file <tt/.dsc/, a list of architectures
  1048. (separated by spaces) is also allowed, as is the special value
  1049. <tt/any/. A list indicates that the source will build an
  1050. architecture-dependent package, and will only work correctly on the
  1051. listed architectures. <tt/any/ indicates that though the source
  1052. package isn't dependent on any particular architecture and should
  1053. compile fine on any one, the binary package(s) produced are not
  1054. architecture-independent but will instead be specific to whatever the
  1055. current build architecture is.
  1056. <p>
  1057. In a <tt/.changes/ file the <tt/Architecture/ field lists the
  1058. architecture(s) of the package(s) currently being uploaded. This will
  1059. be a list; if the source for the package is being uploaded too the
  1060. special entry <tt/source/ is also present.
  1061. <p>
  1062. The current build architecture can be determined using <tt/dpkg
  1063. --print-architecture/.<footnote>This actually invokes
  1064. <example>
  1065. gcc --print-libgcc-file-name
  1066. </example>
  1067. and parses and decomposes the output and looks the CPU type from the
  1068. GCC configuration in a table in <prgn/dpkg/. This is so that it will
  1069. work if you're cross-compiling.
  1070. </footnote>
  1071. This value is automatically used by <prgn/dpkg-gencontrol/ when
  1072. building the control file for a binary package for which the source
  1073. control information doesn't specify architecture <tt/all/.
  1074. <p>
  1075. There is a separate option, <tt/--print-installation-architecture/,
  1076. for finding out what architecture <prgn/dpkg/ is willing to install.
  1077. This information is also in the output of <tt/dpkg --version/.
  1078. <sect1 id="f-Maintainer"><tt/Maintainer/
  1079. <p>
  1080. The package maintainer's name and email address. The name should come
  1081. first, then the email address inside angle brackets <tt/&lt;&gt/ (in
  1082. RFC822 format).
  1083. <p>
  1084. If the maintainer's name contains a full stop then the whole field
  1085. will not work directly as an email address due to a misfeature in the
  1086. syntax specified in RFC822; a program using this field as an address
  1087. must check for this and correct the problem if necessary (for example
  1088. by putting the name in round brackets and moving it to the end, and
  1089. bringing the email address forward).
  1090. <p>
  1091. In a <tt/.changes/ file or parsed changelog data this contains the
  1092. name and email address of the person responsible for the particular
  1093. version in question - this may not be the package's usual maintainer.
  1094. <p>
  1095. This field is usually optional in as far as the <prgn/dpkg/ are
  1096. concerned, but its absence when building packages usually generates a
  1097. warning.
  1098. <sect1 id="f-Source"><tt/Source/
  1099. <p>
  1100. This field identifies the source package name.
  1101. <p>
  1102. In a main source control information or a <tt/.changes/ or <tt/.dsc/
  1103. file or parsed changelog data this may contain only the name of the
  1104. source package.
  1105. <p>
  1106. In the control file of a binary package (or in a <tt/Packages/ file)
  1107. it may be followed by a version number in parentheses.<footnote>It is
  1108. usual to leave a space after the package name if a version number is
  1109. specified.</footnote> This version number may be omitted (and is, by
  1110. <prgn/dpkg-gencontrol/) if it has the same value as the <tt/Version/
  1111. field of the binary package in question. The field itself may be
  1112. omitted from a binary package control file when the source package has
  1113. the same name and version as the binary package.
  1114. <sect1>Package interrelationship fields:
  1115. <tt/Depends/, <tt/Pre-Depends/, <tt/Recommends/
  1116. <tt/Suggests/, <tt/Conflicts/, <tt/Provides/, <tt/Replaces/
  1117. <p>
  1118. These fields describe the package's relationships with other packages.
  1119. Their syntax and semantics are described in <ref id="relationships">.
  1120. <sect1 id="f-Description"><tt/Description/
  1121. <p>
  1122. In a binary package <tt/Packages/ file or main source control file
  1123. this field contains a description of the binary package, in a special
  1124. format. See <ref id="descriptions"> for details.
  1125. <p>
  1126. In a <tt/.changes/ file it contains a summary of the descriptions for
  1127. the packages being uploaded. The part of the field before the first
  1128. newline is empty; thereafter each line has the name of a binary
  1129. package and the summary description line from that binary package.
  1130. Each line is indented by one space.
  1131. <sect1 id="f-Essential"><tt/Essential/
  1132. <p>
  1133. This is a boolean field which may occur only in the control file of a
  1134. binary package (or in the <tt/Packages/ file) or in a per-package
  1135. fields paragraph of a main source control data file.
  1136. <p>
  1137. If set to <tt/yes/ then <prgn/dpkg/ and <prgn/dselect/ will refuse to
  1138. remove the package (though it can be upgraded and/or replaced). The
  1139. other possible value is <tt/no/, which is the same as not having the
  1140. field at all.
  1141. <sect1 id="f-classification"><tt/Section/ and <tt/Priority/
  1142. <p>
  1143. These two fields classify the package. The <tt/Priority/ represents
  1144. how important that it is that the user have it installed; the
  1145. <tt/Section/ represents an application area into which the package has
  1146. been classified.
  1147. <p>
  1148. When they appear in the <tt>debian/control</> file these fields give
  1149. values for the section and priority subfields of the <tt/Files/ field
  1150. of the <tt/.changes/ file, and give defaults for the section and
  1151. priority of the binary packages.
  1152. <p>
  1153. The section and priority are represented, though not as separate
  1154. fields, in the information for each file in the <qref
  1155. id="f-Files"><tt/Files/</> field of a <tt/.changes/ file. The
  1156. section value in a <tt/.changes/ file is used to decide where to
  1157. install a package in the FTP archive.
  1158. <p>
  1159. These fields are not used by by <prgn/dpkg/ proper, but by
  1160. <prgn/dselect/ when it sorts packages and selects defaults. See the
  1161. Debian policy manual for the priorities in use and the criteria for
  1162. selecting the priority for a Debian package, and look at the Debian
  1163. FTP archive for a list of currently in-use priorities.
  1164. <p>
  1165. These fields may appear in binary package control files, in which case
  1166. they provide a default value in case the <tt/Packages/ files are
  1167. missing the information. <prgn/dpkg/ and <prgn/dselect/ will only use
  1168. the value from a <tt/.deb/ file if they have no other information; a
  1169. value listed in a <tt/Packages/ file will always take precedence. By
  1170. default <prgn/dpkg-genchanges/ does not include the section and
  1171. priority in the control file of a binary package - use the <tt/-isp/,
  1172. <tt/-is/ or <tt/-ip/ options to achieve this effect.
  1173. <sect1 id="f-Binary"><tt/Binary/
  1174. <p>
  1175. This field is a list of binary packages.
  1176. <p>
  1177. When it appears in the <tt/.dsc/ file it is the list of binary
  1178. packages which a source package can produce. It does not necessarily
  1179. produce all of these binary packages for every architecture. The
  1180. source control file doesn't contain details of which architectures are
  1181. appropriate for which of the binary packages.
  1182. <p>
  1183. When it appears in a <tt/.changes/ file it lists the names of the
  1184. binary packages actually being uploaded.
  1185. <p>
  1186. The syntax is a list of binary packages separated by
  1187. commas.<footnote>A space after each comma is conventional.</footnote>
  1188. Currently the packages must be separated using only spaces in the
  1189. <tt/.changes/ file.
  1190. <sect1 id="f-Installed-Size"><tt/Installed-Size/
  1191. <p>
  1192. This field appears in the control files of binary packages, and in the
  1193. <tt/Packages/ files. It gives the total amount of disk space
  1194. required to install the named package.
  1195. <p>
  1196. The disk space is represented in kilobytes as a simple decimal number.
  1197. <sect1 id="f-Files"><tt/Files/
  1198. <p>
  1199. This field contains a list of files with information about each one.
  1200. The exact information and syntax varies with the context. In all
  1201. cases the the part of the field contents on the same line as the field
  1202. name is empty. The remainder of the field is one line per file, each
  1203. line being indented by one space and containing a number of sub-fields
  1204. separated by spaces.
  1205. <p>
  1206. In the <tt/.dsc/ (Debian source control) file each line contains the
  1207. MD5 checksum, size and filename of the tarfile and (if applicable)
  1208. diff file which make up the remainder of the source
  1209. package.<footnote>That is, the parts which are not the
  1210. <tt/.dsc/.</footnote> The exact forms of the filenames are described
  1211. in <ref id="sourcearchives">.
  1212. <p>
  1213. In the <tt/.changes/ file this contains one line per file being
  1214. uploaded. Each line contains the MD5 checksum, size, section and
  1215. priority and the filename. The section and priority are the values of
  1216. the corresponding fields in the main source control file - see <ref
  1217. id="f-classification">. If no section or priority is specified then
  1218. <tt/-/ should be used, though section and priority values must be
  1219. specified for new packages to be installed properly.
  1220. <p>
  1221. The special value <tt/byhand/ for the section in a <tt/.changes/ file
  1222. indicates that the file in question is not an ordinary package file
  1223. and must by installed by hand by the distribution maintainers. If the
  1224. section is <tt/byhand/ the priority should be <tt/-/.
  1225. <p>
  1226. If a new Debian revision of a package is being shipped and no new
  1227. original source archive is being distributed the <tt/.dsc/ must still
  1228. contain the <tt/Files/ field entry for the original source archive
  1229. <tt/<var/package/-<var/upstream-version/.orig.tar.gz/, but the
  1230. <tt/.changes/ file should leave it out. In this case the original
  1231. source archive on the distribution site must match exactly,
  1232. byte-for-byte, the original source archive which was used to generate
  1233. the <tt/.dsc/ file and diff which are being uploaded.
  1234. <sect1 id="f-Standards-Version"><tt/Standards-Version/
  1235. <p>
  1236. The most recent version of the standards (the <prgn/dpkg/ programmers'
  1237. and policy manuals and associated texts) with which the package
  1238. complies. This is updated manually when editing the source package to
  1239. conform to newer standards; it can sometimes be used to tell when a
  1240. package needs attention.
  1241. <p>
  1242. Its format is the same as that of a version number except that no
  1243. epoch or Debian revision is allowed - see <ref id="versions">.
  1244. <sect1 id="f-Distribution"><tt/Distribution/
  1245. <p>
  1246. In a <tt/.changes/ file or parsed changelog output this contains the
  1247. (space-separated) name(s) of the distribution(s) where this version of
  1248. the package should be or was installed. Distribution names follow the
  1249. rules for package names. (See <ref id="f-Package">).
  1250. <p>
  1251. Current distribution values are <tt/stable/, <tt/unstable/,
  1252. <tt/contrib/, <tt/non-free/ and <tt/experimental/.
  1253. <sect1 id="f-Urgency"><tt/Urgency/
  1254. <p>
  1255. This is a description of how important it is to upgrade to this
  1256. version from previous ones. It consists of a single keyword usually
  1257. taking one of the values <tt/LOW/, <tt/MEDIUM/ or <tt/HIGH/) followed
  1258. by an optional commentary (separated by a space) which is usually in
  1259. parentheses. For example:
  1260. <example>
  1261. Urgency: LOW (HIGH for diversions users)
  1262. </example>
  1263. <p>
  1264. This field appears in the <tt/.changes/ file and in parsed changelogs;
  1265. its value appears as the value of the <tt/urgency/ attribute in a
  1266. <prgn/dpkg/-style changelog (see <ref id="dpkgchangelog">).
  1267. <p>
  1268. Urgency keywords are not case-sensitive.
  1269. <sect1 id="f-Date"><tt/Date/
  1270. <p>
  1271. In <tt/.changes/ files and parsed changelogs, this gives the date the
  1272. package was built or last edited.
  1273. <sect1 id="f-Format"><tt/Format/
  1274. <p>
  1275. This field occurs in <tt/.changes/ files, and specifies a format
  1276. revision for the file. The format described here is version <tt/1.5/.
  1277. The syntax of the format value is the same as that of a package
  1278. version number except that no epoch or Debian revision is allowed -
  1279. see <ref id="versions">.
  1280. <sect1 id="f-Changes"><tt/Changes/
  1281. <p>
  1282. In a <tt/.changes/ file or parsed changelog this field contains the
  1283. human-readable changes data, describing the differences between the
  1284. last version and the current one.
  1285. <p>
  1286. There should be nothing in this field before the first newline; all
  1287. the subsequent lines must be indented by at least one space; blank
  1288. lines must be represented by a line consiting only of a space and a
  1289. full stop.
  1290. <p>
  1291. Each version's change information should be preceded by a `title' line
  1292. giving at least the version, distribution(s) and urgency, in a
  1293. human-readable way.
  1294. <p>
  1295. If data from several versions is being returned the entry for the most
  1296. recent version should be returned first, and entries should be
  1297. separated by the representation of a blank line (the `title' line may
  1298. also be followed by the representation of blank line).
  1299. <sect1 id="f-Filename"><tt/Filename/ and <tt/MSDOS-Filename/
  1300. <p>
  1301. These fields in <tt/Packages/ files give the filename(s) of (the parts
  1302. of) a package in the distribution directories, relative to the root of
  1303. the Debian hierarchy. If the package has been split into several
  1304. parts the parts are all listed in order, separated by spaces.
  1305. <sect1 id="f-Size"><tt/Size/ and <tt/MD5sum/
  1306. <p>
  1307. These fields in <tt/Packages/ files give the size (in bytes, expressed
  1308. in decimal) and MD5 checksum of the file(s) which make(s) up a binary
  1309. package in the distribution. If the package is split into several
  1310. parts the values for the parts are listed in order, separated by
  1311. spaces.
  1312. <sect1 id="f-Status"><tt/Status/
  1313. <p>
  1314. This field in <prgn/dpkg/'s status file records whether the user wants a
  1315. package installed, removed or left alone, whether it is broken
  1316. (requiring reinstallation) or not and what its current state on the
  1317. system is. Each of these pieces of information is a single word.
  1318. <sect1 id="f-Config-Version"><tt/Config-Version/
  1319. <p>
  1320. If a package is not installed or not configured, this field in
  1321. <prgn/dpkg/'s status file records the last version of the package which
  1322. was successfully configured.
  1323. <sect1 id="f-Conffiles"><tt/Conffiles/
  1324. <p>
  1325. This field in <prgn/dpkg/'s status file contains information about the
  1326. automatically-managed configuration files held by a package. This
  1327. field should <em/not/ appear anywhere in a package!
  1328. <sect1>Obsolete fields
  1329. <p>
  1330. These are still recognised by <prgn/dpkg/ but should not appear anywhere
  1331. any more.
  1332. <taglist compact>
  1333. <tag><tt/Revision/
  1334. <tag><tt/Package-Revision/
  1335. <tag><tt/Package_Revision/
  1336. <item>
  1337. The Debian revision part of the package version was at one point in a
  1338. separate control file field. This field went through several names.
  1339. <tag><tt/Recommended/
  1340. <item>Old name for <tt/Recommends/
  1341. <tag><tt/Optional/
  1342. <item>Old name for <tt/Suggests/.
  1343. <tag><tt/Class/
  1344. <item>Old name for <tt/Priority/.
  1345. </taglist>
  1346. <chapt id="versions">Version numbering
  1347. <p>
  1348. Every package has a version number, in its <tt/Version/ control file
  1349. field.
  1350. <p>
  1351. <prgn/dpkg/ imposes an ordering on version numbers, so that it can tell
  1352. whether packages are being up- or downgraded and so that <prgn/dselect/
  1353. can tell whether a package it finds available is newer than the one
  1354. installed on the system. The version number format has the most
  1355. significant parts (as far as comparison is concerned) at the
  1356. beginning.
  1357. <p>
  1358. The version number format is:
  1359. &lsqb<var/epoch/<tt/:/&rsqb;<var/upstream-version/&lsqb;<tt/-/<var/debian-revision/&rsqb;.
  1360. <p>
  1361. The three components here are:
  1362. <taglist>
  1363. <tag><var/epoch/
  1364. <item>
  1365. This is a single unsigned integer, which should usually be small. It
  1366. may be omitted, in which case zero is assumed. If it is omitted then
  1367. the <var/upstream-version/ may not contain any colons.
  1368. <p>
  1369. It is provided to allow mistakes in the version numbers of older
  1370. versions of a package, and also a package's previous version numbering
  1371. schemes, to be left behind.
  1372. <p>
  1373. <prgn/dpkg/ will not usually display the epoch unless it is essential
  1374. (non-zero, or if the <var/upstream-version/ contains a colon);
  1375. <prgn/dselect/ does not display epochs at all in the main part of the
  1376. package selection display.
  1377. <tag><var/upstream-version/
  1378. <item>
  1379. This is the main part of the version. It is usually version number of
  1380. the original (`upstream') package of which the <tt/.deb/ file has been
  1381. made, if this is applicable. Usually this will be in the same format
  1382. as that specified by the upstream author(s); however, it may need to
  1383. be reformatted to fit into <prgn/dpkg/'s format and comparison scheme.
  1384. <p>
  1385. The comparison behaviour of <prgn/dpkg/ with respect to the
  1386. <var/upstream-version/ is described below. The <var/upstream-version/
  1387. portion of the version number is mandatory.
  1388. <p>
  1389. The <var/upstream-version/ may contain only alphanumerics and the
  1390. characters <tt/+/ <tt/./ <tt/-/ <tt/:/ (full stop, plus, hyphen,
  1391. colon) and should start with a digit. If there is no
  1392. <var/debian-revision/ then hyphens are not allowed; if there is no
  1393. <var/epoch/ then colons are not allowed.
  1394. <tag><var/debian-revision/
  1395. <item>
  1396. This part of the version represents the version of the modifications
  1397. that were made to the package to make it a Debian binary package. It
  1398. is in the same format as the <var/upstream-version/ and <prgn/dpkg/
  1399. compares it in the same way.
  1400. <p>
  1401. It is optional; if it isn't present then the <var/upstream-version/
  1402. may not contain a hyphen. This format represents the case where a
  1403. piece of software was written specifically to be turned into a Debian
  1404. binary package, and so there is only one `debianization' of it and
  1405. therefore no revision indication is required.
  1406. <p>
  1407. It is conventional to restart the <var/debian-revision/ at <tt/1/ each
  1408. time the <var/upstream-version/ is increased.
  1409. <p>
  1410. <prgn/dpkg/ will break the <var/upstream-version/ and
  1411. <var/debian-revision/ apart at the last hyphen in the string. The
  1412. absence of a <var/debian-revision/ compares earlier than the presence
  1413. of one (but note that the <var/debian-revision/ is the least
  1414. significant part of the version number).
  1415. <p>
  1416. The <var/debian-revision/ may contain only alphanumerics and the
  1417. characters <tt/+/ and <tt/./ (plus and full stop).
  1418. </taglist>
  1419. The <var/upstream-version/ and <var/debian-revision/ parts are
  1420. compared by <prgn/dpkg/ using the same algorithm:
  1421. <p>
  1422. The strings are compared from left to right.
  1423. <p>
  1424. First the initial part of each string consisting entirely of non-digit
  1425. characters is determined. These two parts (one of which may be empty)
  1426. are compared lexically. If a difference is found it is returned. The
  1427. lexical comparison is a comparison of ASCII values modified so that
  1428. all the letters sort earlier than all the non-letters.
  1429. <p>
  1430. Then the initial part of the remainder of each string which consists
  1431. entirely of digit characters is determined. The numerical values of
  1432. these two parts are compared, and any difference found is returned as
  1433. the result of the comparison. For these purposes an empty string
  1434. (which can only occur at the end of one or both version strings being
  1435. compared) counts as zero.
  1436. <p>
  1437. These two steps are repeated (chopping initial non-digit strings and
  1438. initial digit strings off from the start) until a difference is found
  1439. or both strings are exhausted.
  1440. <p>
  1441. Note that the purpose of epochs is to allow us to leave behind
  1442. mistakes in version numbering, and to cope with situations where the
  1443. version numbering changes. It is <em/not/ there to cope with version
  1444. numbers containing strings of letters which <prgn/dpkg/ cannot interpret
  1445. (such as <tt/ALPHA/ or <tt/pre-/), or with silly orderings (the author
  1446. of this manual has heard of a package whose versions went <tt/1.1/,
  1447. <tt/1.2/, <tt/1.3/, <tt/1/, <tt/2.1/, <tt/2.2/, <tt/2/ and so forth).
  1448. <p>
  1449. If an upstream package has problematic version numbers they should be
  1450. converted to a sane form for use in the <tt/Version/ field.
  1451. <chapt id="maintainerscripts">Package maintainer scripts
  1452. and installation procedure
  1453. <sect>Introduction to package maintainer scripts
  1454. <p>
  1455. It is possible supply scripts as part of a package which <prgn/dpkg/
  1456. will run for you when your package is installed, upgraded or removed.
  1457. <p>
  1458. These scripts should be the files <tt/preinst/, <tt/postinst/,
  1459. <tt/prerm/ and <tt/postrm/ in the control area of the package. They
  1460. must be proper exectuable files; if they are scripts (which is
  1461. recommended) they must start with the usual <tt/#!/ convention. They
  1462. should be readable and executable to anyone, and not world-writeable.
  1463. <p>
  1464. <prgn/dpkg/ looks at the exit status from these scripts. It is
  1465. important that they exit with a non-zero status if there is an error,
  1466. so that <prgn/dpkg/ can stop its processing. For shell scripts this
  1467. means that you <em/almost always/ need to use <tt/set -e/ (this is
  1468. usually true when writing shell scripts, in fact). It is also
  1469. important, of course, that they don't exit with a non-zero status if
  1470. everything went well.
  1471. <p>
  1472. It is necessary for the error recovery procedures that the scripts be
  1473. idempotent: ie, invoking the same script several times in the same
  1474. situation should do no harm. If the first call failed, or aborted
  1475. half way through for some reason, the second call should merely do the
  1476. things that were left undone the first time, if any, and exit with a
  1477. success status.
  1478. <p>
  1479. When a package is upgraded a combination of the scripts from the old
  1480. and new packages is called in amongst the other steps of the upgrade
  1481. procedure. If your scripts are going to be at all complicated you
  1482. need to be aware of this, and may need to check the arguments to your
  1483. scripts.
  1484. <p>
  1485. Broadly speaking the <prgn/preinst/ is called before (a particular
  1486. version of) a package is installed, and the <prgn/postinst/ afterwards;
  1487. the <prgn/prerm/ before (a version of) a package is removed and the
  1488. <prgn/postrm/ afterwards.
  1489. <sect id="mscriptsinstact">Summary of ways maintainer scripts are called
  1490. <p>
  1491. <list compact>
  1492. <item><var/new-preinst/ <tt/install/
  1493. <item><var/new-preinst/ <tt/install/ <var/old-version/
  1494. <item><var/new-preinst/ <tt/upgrade/ <var/old-version/
  1495. <item><var/old-preinst/ <tt/abort-upgrade/ <var/new-version/
  1496. </list>
  1497. <p>
  1498. <list compact>
  1499. <item><var/postinst/ <tt/configure/ <var/most-recently-configured-version/
  1500. <item><var/old-postinst/ <tt/abort-upgrade/ <var/new version/
  1501. <item><var/conflictor's-postinst/ <tt/abort-remove/
  1502. <tt/in-favour/ <var/package/ <var/new-version/
  1503. <item><var/deconfigured's-postinst/ <tt/abort-deconfigure/
  1504. <tt/in-favour/ <var/failed-install-package/ <var/version/
  1505. <tt/removing/ <var/conflicting-package/ <var/version/
  1506. </list>
  1507. <p>
  1508. <list compact>
  1509. <item><var/prerm/ <tt/remove/
  1510. <item><var/old-prerm/ <tt/upgrade/ <var/new-version/
  1511. <item><var/new-prerm/ <tt/failed-upgrade/ <var/old-version/
  1512. <item><var/conflictor's-prerm/ <tt/remove/ <tt/in-favour/
  1513. <var/package/ <var/new-version/
  1514. <item><var/deconfigured's-prerm/ <tt/deconfigure/
  1515. <tt/in-favour/ <var/package-being-installed/ <var/version/
  1516. <tt/removing/ <var/conflicting-package/ <var/version/
  1517. </list>
  1518. <p>
  1519. <list compact>
  1520. <item><var/postrm/ <tt/remove/
  1521. <item><var/postrm/ <tt/purge/
  1522. <item><var/old-postrm/ <tt/upgrade/ <var/new-version/
  1523. <item><var/new-postrm/ <tt/failed-upgrade/ <var/old-version/
  1524. <item><var/new-postrm/ <tt/abort-install/
  1525. <item><var/new-postrm/ <tt/abort-install/ <var/old-version/
  1526. <item><var/new-postrm/ <tt/abort-upgrade/ <var/old-version/
  1527. <item><var/disappearer's-postrm/ <tt/disappear/ <var/overwriter/ <var/new-version/
  1528. </list>
  1529. <sect>Details of unpack phase of installation or upgrade
  1530. <p>
  1531. The procedure on installation/upgrade/overwrite/disappear (ie, when
  1532. running <tt/dpkg --unpack/, or the unpack stage of <tt/dpkg
  1533. --install/) is as follows. In each case if an error occurs the
  1534. actions in are general run backwards - this means that the maintainer
  1535. scripts are run with different arguments in reverse order. These are
  1536. the `error unwind' calls listed below.
  1537. <enumlist>
  1538. <item>
  1539. <enumlist>
  1540. <item>
  1541. If a version the package is already
  1542. installed, call
  1543. <example>
  1544. <var/old-prerm/ upgrade <var/new-version/
  1545. </example>
  1546. <item>
  1547. If this gives an error (ie, a non-zero exit status), dpkg will
  1548. attempt instead:
  1549. <example>
  1550. <var/new-prerm/ failed-upgrade <var/old-version/
  1551. </example>
  1552. Error unwind, for both the above cases:
  1553. <example>
  1554. <var/old-postinst/ abort-upgrade <var/new-version/
  1555. </example>
  1556. </enumlist>
  1557. <item>
  1558. If a `conflicting' package is being removed at the same time:
  1559. <enumlist>
  1560. <item>
  1561. If any packages depended on that conflicting package and
  1562. <tt/--auto-deconfigure/ is specified, call, for each such package:
  1563. <example>
  1564. <var/deconfigured's-prerm/ deconfigure \
  1565. in-favour <var/package-being-installed/ <var/version/ \
  1566. removing <var/conflicting-package/ <var/version/
  1567. </example>
  1568. Error unwind:
  1569. <example>
  1570. <var/deconfigured's-postinst/ abort-deconfigure \
  1571. in-favour <var/package-being-installed-but-failed/ <var/version/ \
  1572. removing <var/conflicting-package/ <var/version/
  1573. </example>
  1574. The deconfigured packages are marked as requiring configuration, so
  1575. that if <tt/--install/ is used they will be configured again if
  1576. possible.
  1577. <item>
  1578. To prepare for removal of the conflicting package, call:
  1579. <example>
  1580. <var/conflictor's-prerm/ remove in-favour <var/package/ <var/new-version/
  1581. </example>
  1582. Error unwind:
  1583. <example>
  1584. <var/conflictor's-postinst/ abort-remove \
  1585. in-favour <var/package/ <var/new-version/
  1586. </example>
  1587. </enumlist>
  1588. <item>
  1589. <enumlist>
  1590. <item>
  1591. If the package is being upgraded, call:
  1592. <example>
  1593. <var/new-preinst/ upgrade <var/old-version/
  1594. </example>
  1595. <item>
  1596. Otherwise, if the package had some configuration files from a previous
  1597. version installed (ie, it is in the `configuration files only' state):
  1598. <example>
  1599. <var/new-preinst/ install <var/old-version/
  1600. </example>
  1601. <item>
  1602. Otherwise (ie, the package was completely purged):
  1603. <example>
  1604. <var/new-preinst/ install
  1605. </example>
  1606. Error unwind versions, respectively:
  1607. <example>
  1608. <var/new-postrm/ abort-upgrade <var/old-version/
  1609. <var/new-postrm/ abort-install <var/old-version/
  1610. <var/new-postrm/ abort-install
  1611. </example>
  1612. </enumlist>
  1613. <item>
  1614. The new package's files are unpacked, overwriting any that may be on
  1615. the system already, for example any from the old version of the same
  1616. package or from another package (backups of the old files are left
  1617. around, and if anything goes wrong dpkg will attempt to put them back
  1618. as part of the error unwind).
  1619. <p>
  1620. It is an error for a package to contains files which are on the system
  1621. in another package, unless <tt/Replaces/ is used (see
  1622. <ref id="replaces">). Currently the <tt/--force-overwrite/ flag is
  1623. enabled, downgrading it to a warning, but this may not always be the
  1624. case.
  1625. <p>
  1626. It is a more serious error for a package to contain a plain file or
  1627. other kind of nondirectory where another package has a directory
  1628. (again, unless <tt/Replaces/ is used). This error can be overridden
  1629. if desired using <tt/--force-overwrite-dir/, but this is not -->
  1630. --advisable.
  1631. <p>
  1632. Packages which overwrite each other's files produce behaviour which
  1633. though deterministic is hard for the system administrator to
  1634. understand. It can easily lead to `missing' programs if, for example,
  1635. a package is installed which overwrites a file from another package,
  1636. and is then removed again.<footnote>Part of the problem is due to what
  1637. is arguably a bug in <prgn/dpkg/.</footnote>
  1638. <p>
  1639. A directory will never be replaced by a symbolic links to a directory
  1640. or vice versa; instead, the existing state (symlink or not) will be
  1641. left alone and <prgn/dpkg/ will follow the symlink if there is one.
  1642. <item>
  1643. <enumlist>
  1644. <item>
  1645. If the package is being upgraded, call
  1646. <example>
  1647. <var/old-postrm/ upgrade <var/new-version/
  1648. </example>
  1649. <item>
  1650. If this fails, <prgn/dpkg/ will attempt:
  1651. <example>
  1652. <var/new-postrm/ failed-upgrade <var/old-version/
  1653. </example>
  1654. Error unwind, for both cases:
  1655. <example>
  1656. <var/old-preinst/ abort-upgrade <var/new-version/
  1657. </example>
  1658. </enumlist>
  1659. This is the point of no return - if <prgn/dpkg/ gets this far, it won't
  1660. back off past this point if an error occurs. This will leave the
  1661. package in a fairly bad state, which will require a successful
  1662. reinstallation to clear up, but it's when <prgn/dpkg/ starts doing
  1663. things that are irreversible.
  1664. <item>
  1665. Any files which were in the old version of the package but not in the
  1666. new are removed.
  1667. <item>
  1668. The new file list replaces the old.
  1669. <item>
  1670. The new maintainer scripts replace the old.
  1671. <item>
  1672. Any packages all of whose files have been overwritten during the
  1673. installation, and which aren't required for dependencies, are considered
  1674. to have been removed. For each such package,
  1675. <enumlist>
  1676. <item>
  1677. <prgn/dpkg/ calls:
  1678. <example>
  1679. <var/disappearer's-postrm/ disappear \
  1680. <var/overwriter/ <var/overwriter-version/
  1681. </example>
  1682. <item>
  1683. The package's maintainer scripts are removed.
  1684. <item>
  1685. It is noted in the status database as being in a sane state, namely
  1686. not installed (any conffiles it may have are ignored, rather than
  1687. being removed by <prgn/dpkg/). Note that disappearing packages do not
  1688. have their prerm called, because <prgn/dpkg/ doesn't know in advance
  1689. that the package is going to vanish.
  1690. </enumlist>
  1691. <item>
  1692. Any files in the package we're unpacking that are also listed in the
  1693. file lists of other packages are removed from those lists. (This will
  1694. lobotomise the file list of the `conflicting' package if there is one.)
  1695. <item>
  1696. The backup files made during installation, above, are deleted.
  1697. <item>
  1698. The new package's status is now sane, and recorded as `unpacked'. Here
  1699. is another point of no return - if the conflicting package's removal
  1700. fails we do not unwind the rest of the installation; the conflicting
  1701. package is left in a half-removed limbo.
  1702. <item>
  1703. If there was a conflicting package we go and do the removal actions
  1704. (described below), starting with the removal of the conflicting
  1705. package's files (any that are also in the package being installed
  1706. have already been removed from the conflicting package's file list,
  1707. and so do not get removed now).
  1708. </enumlist>
  1709. <sect>Details of configuration
  1710. <p>
  1711. When we configure a package (this happens with <tt/dpkg --install/, or
  1712. with <tt/--configure/), we first update the conffiles and then call:
  1713. <example>
  1714. <var/postinst/ configure <var/most-recently-configured-version/
  1715. </example>
  1716. <p>
  1717. No attempt is made to unwind after errors during configuration.
  1718. <p>
  1719. If there is no most recently configured version <prgn/dpkg/ will pass a
  1720. null argument; older versions of dpkg may pass
  1721. <tt>&lt;unknown&gt;</tt> (including the angle brackets) in this case.
  1722. Even older ones do not pass a second argument at all, under any
  1723. circumstances.
  1724. <sect>Details of removal and/or configuration purging
  1725. <p>
  1726. <enumlist>
  1727. <item>
  1728. <example>
  1729. <var/prerm/ remove
  1730. </example>
  1731. <item>
  1732. The package's files are removed (except conffiles).
  1733. <item>
  1734. <example>
  1735. <var/postrm/ remove
  1736. </example>
  1737. <item>
  1738. All the maintainer scripts except the postrm are removed.
  1739. <p>
  1740. If we aren't purging the package we stop here. Note that packages
  1741. which have no postrm and no conffiles are automatically purged when
  1742. removed, as there is no difference except for the <prgn/dpkg/ status.
  1743. <item>
  1744. The conffiles and any backup files (<tt/~/-files, <tt/#*#/ files,
  1745. <tt/%/-files, <tt/.dpkg-{old,new,tmp}/, etc.) are removed.
  1746. <item>
  1747. <example>
  1748. <var/postrm/ purge
  1749. </example>
  1750. <item>
  1751. The package's file list is removed.
  1752. </enumlist>
  1753. No attempt is made to unwind after errors during removal.
  1754. <chapt id="descriptions">Descriptions of packages - the
  1755. <tt/Description/ field
  1756. <p>
  1757. The <tt/Description/ control file field is used by <prgn/dselect/ when
  1758. the user is selecting which packages to install and by <prgn/dpkg/
  1759. when it displays information about the status of packages and so
  1760. forth. It is included on the FTP site in the <prgn/Packages/ files,
  1761. and may also be used by the Debian WWW pages.
  1762. <p>
  1763. The description is intended to describe the program to a user who has
  1764. never met it before so that they know whether they want to install it.
  1765. It should also give information about the significant dependencies and
  1766. conflicts between this package and others, so that the user knows why
  1767. these dependencies and conflicts have been declared.
  1768. <p>
  1769. The field's format is as follows:
  1770. <example>
  1771. Description: <var/single line synopsis/
  1772. <var/extended description over several lines/
  1773. </example>
  1774. <p>
  1775. The synopsis is often printed in lists of packages and so forth, and
  1776. should be as informative as possible. Every package should also have
  1777. an extended description.
  1778. <p>
  1779. <sect>Types of formatting line in the extended description
  1780. <p>
  1781. <list>
  1782. <item>
  1783. Those starting with a single space are part of a paragraph.
  1784. Successive lines of this form will be word-wrapped when displayed.
  1785. The leading space will usually be stripped off.
  1786. <item>
  1787. Those starting with two or more spaces. These will be displayed
  1788. verbatim. If the display cannot be panned horizontally the
  1789. displaying program will linewrap them `hard' (ie, without taking
  1790. account of word breaks). If it can they will be allowed to trail
  1791. off to the right. None, one or two initial spaces may be deleted,
  1792. but the number of spaces deleted from each line will be the same
  1793. (so that you can have indenting work correctly, for example).
  1794. <item>
  1795. Those containing a single space followed by a single full stop
  1796. character. These are rendered as blank lines. This is the <em/only/
  1797. way to get a blank line - see below.
  1798. <item>
  1799. Those containing a space, a full stop and some more characters. These
  1800. are for future expansion. Do not use them.
  1801. </list>
  1802. <sect>Notes about writing descriptions
  1803. <p>
  1804. <em/Always/ start extended description lines with at least one
  1805. whitespace character. Fields in the control file and in the Packages
  1806. file are separated by field names starting in the first column, just
  1807. as message header fields are in RFC822. Forgetting the whitespace
  1808. will cause <prgn/dpkg-deb/<footnote>Version 0.93.23 or
  1809. later.</footnote> to produce a syntax error when trying to build the
  1810. package. If you force it to build anyway <prgn/dpkg/ will refuse to
  1811. install the resulting mess.
  1812. <p>
  1813. <em/Do not/ include any completely <em/empty/ lines. These separate
  1814. different records in the Packages file and different packages in the
  1815. <tt>debian/control</> file, and are forbidden in package control
  1816. files. See the previous paragraph for what happens if you get this
  1817. wrong.
  1818. <p>
  1819. The single line synopsis should be kept brief - certainly under 80
  1820. characters. <prgn/dselect/ displays between 25 and 49 characters
  1821. without panning if you're using an 80-column terminal, depending on
  1822. what display options are in effect.
  1823. <p>
  1824. Do not include the package name in the synopsis line. The display
  1825. software knows how to display this already, and you do not need to
  1826. state it. Remember that in many situations the user may only see
  1827. the synopsis line - make it as informative as you can.
  1828. <p>
  1829. The extended description should describe what the package does and
  1830. how it relates to the rest of the system (in terms of, for
  1831. example, which subsystem it is which part of).
  1832. <p>
  1833. The blurb that comes with a program in its announcements and/or
  1834. <prgn/README/ files is rarely suitable for use in a description. It
  1835. is usually aimed at people who are already in the community where the
  1836. package is used. The description field needs to make sense to anyone,
  1837. even people who have no idea about any of the
  1838. things the package deals with.
  1839. <p>
  1840. Put important information first, both in the synopis and extended
  1841. description. Sometimes only the first part of the synopsis or of
  1842. the description will be displayed. You can assume that there will
  1843. usually be a way to see the whole extended description.
  1844. <p>
  1845. You may include information about dependencies and so forth in the
  1846. extended description, if you wish.
  1847. <p>
  1848. Do not use tab characters. Their effect is not predictable.
  1849. <p>
  1850. Do not try to linewrap the summary (the part on the same line as the
  1851. field name <tt/Description/) into the extended description. This will
  1852. not work correctly when the full description is displayed, and makes
  1853. no sense where only the summary is available.
  1854. <sect>Example description in control file for Smail
  1855. <p>
  1856. <example>
  1857. Package: smail
  1858. Version: 3.1.29.1-13
  1859. Maintainer: Ian Jackson &lt;iwj10@cus.cam.ac.uk&gt;
  1860. Recommends: pine | mailx | elm | emacs | mail-user-agent
  1861. Suggests: metamail
  1862. Depends: cron, libc5
  1863. Conflicts: sendmail
  1864. Provides: mail-transport-agent
  1865. Description: Electronic mail transport system.
  1866. Smail is the recommended mail transport agent (MTA) for Debian.
  1867. .
  1868. An MTA is the innards of the mail system - it takes messages from
  1869. user-friendly mailer programs and arranges for them to be delivered
  1870. locally or passed on to other systems as required.
  1871. .
  1872. In order to make use of it you must have one or more user level
  1873. mailreader programs such as elm, pine, mailx or Emacs (which has Rmail
  1874. and VM as mailreaders) installed. If you wish to send messages other
  1875. than just to other users of your system you must also have appropriate
  1876. and VM as mailreaders) installed. If you wish to send messages other
  1877. than just to other users of your system you must also have appropriate
  1878. networking support, in the form of IP or UUCP.
  1879. </example>
  1880. <chapt id="relationships">Declaring relationships between packages
  1881. <p>
  1882. Packages can declare in their control file that they have certain
  1883. relationships to other packages - for example, that they may not be
  1884. installed at the same time as certain other packages, and/or that they
  1885. depend on the presence of others, or that they should overwrite files
  1886. in certain other packages if present.
  1887. <p>
  1888. This is done using the <tt/Depends/, <tt/Recommends/, <tt/Suggests/,
  1889. <tt/Conflicts/, <tt/Provides/ and <tt/Replaces/ control file fields.
  1890. <p>
  1891. <sect id="depsyntax">Syntax of relationship fields
  1892. <p>
  1893. These fields all have a uniform syntax. They are a list of package
  1894. names separated by commas.
  1895. <p>
  1896. In <tt/Depends/, <tt/Recommends/, <tt/Suggests/ and <tt/Pre-Depends/
  1897. (the fields which declare dependencies of the package in which they
  1898. occur on other packages) these package names may also be lists of
  1899. alternative package names, separated by vertical bar symbols <tt/|/
  1900. (pipe symbols).
  1901. <p>
  1902. All the fields except <tt/Provides/ may restrict their applicability
  1903. to particular versions of each named package. This is done in
  1904. parentheses after each individual package name; the parentheses should
  1905. contain a relation from the list below followed by a version number,
  1906. in the format described in <ref id="versions">.
  1907. <p>
  1908. The relations allowed are
  1909. <tt/&lt;&lt;/,
  1910. <tt/&lt;=/,
  1911. <tt/=/,
  1912. <tt/&gt;=/ and
  1913. <tt/&gt;&gt;/
  1914. for strictly earlier, earlier or equal, exactly equal, later or equal
  1915. and strictly later, respectively. The forms <tt/&lt;/ and <tt/&gt;/
  1916. were used to mean earlier/later or equal, rather than strictly
  1917. earlier/later, so they should not appear in new packages (though
  1918. <prgn/dpkg/ still supports them).
  1919. <p>
  1920. Whitespace may appear at any point in the version specification, and
  1921. must appear where it's necessary to disambiguate; it is not otherwise
  1922. significant. For consistency and in case of future changes to
  1923. <prgn/dpkg/ it is recommended that a single space be used after a
  1924. version relationship and before a version number; it is usual also to
  1925. put a single space after each comma, on either side of each vertical
  1926. bar, and before each open parenthesis.
  1927. <p>
  1928. For example:
  1929. <example>
  1930. Package: metamail
  1931. Version: 2.7-3
  1932. Depends: libc5 (>= 5.2.18-4), mime-support, csh | tcsh
  1933. </example>
  1934. <sect>Dependencies - <tt/Depends/, <tt/Recommends/, <tt/Suggests/, <tt/Pre-Depends/
  1935. <p>
  1936. These four fields are used to declare a dependency by one package on
  1937. another. They appear in the depending package's control file.
  1938. <p>
  1939. All but <tt/Pre-Depends/ (discussed below) take effect <em/only/ when
  1940. a package is to be configured. They do not prevent a package being on
  1941. the system in an unconfigured state while its dependencies are
  1942. unsatisfied, and it is possible to replace a package whose
  1943. dependencies are satisfied and which is properly installed with a
  1944. different version whose dependencies are not and cannot be satisfied;
  1945. when this is done the depending package will be left unconfigured
  1946. (since attempts to configure it will give errors) and will not
  1947. function properly.
  1948. <p>
  1949. For this reason packages in an installation run are usually all
  1950. unpacked first and all configured later; this gives later versions of
  1951. packages with dependencies on later versions of other packages the
  1952. opportunity to have their dependencies satisfied.
  1953. <p>
  1954. Thus <tt/Depends/ allows package maintainers to impose an order in
  1955. which packages should be configured.
  1956. <taglist>
  1957. <tag><tt/Depends/
  1958. <item>
  1959. This declares an absolute dependency.
  1960. <p>
  1961. <prgn/dpkg/ will not configure
  1962. packages whose dependencies aren't satisfied. If it is asked to make
  1963. an installation which would cause an installed package's dependencies
  1964. to become unsatisfied it will complain<footnote>Current versions
  1965. (1.2.4) of <prgn/dpkg/ have a bug in this area which will cause some of
  1966. these problems to be ignored.</footnote>, unless
  1967. <tt/--auto-deconfigure/ is specified, in which case those packages
  1968. will be deconfigured before the installation proceeds.
  1969. <p>
  1970. <prgn/dselect/ makes it hard for the user to select packages for
  1971. installation, removal or upgrade in a way that would mean that
  1972. packages' <prgn/Depends/ fields would be unsatisfied. The user can
  1973. override this if they wish, for example if they know that <prgn/dselect/
  1974. has an out-of-date view of the real package relationships.
  1975. <p>
  1976. The <tt/Depends/ field should be used if the depended-on package is
  1977. required for the depending package to provide a significant amount of
  1978. functionality.
  1979. <tag><tt/Recommends/
  1980. <item>
  1981. This declares a strong, but not absolute, dependency.
  1982. <p>
  1983. <tt/Recommends/ is ignored by <prgn/dpkg/, so that users using the
  1984. command-line (who are presumed to know what they're doing) will not be
  1985. impeded.
  1986. <p>
  1987. It is treated by <prgn/dselect/ exactly as <tt/Depends/ is; this makes
  1988. it hard for the user to select things so as to leave <tt/Recommends/
  1989. fields unsatisfied, but they are able to do so by being persistent.
  1990. <p>
  1991. The <tt/Recommends/ field should list packages that would be found
  1992. together with this one in all but unusual installations.
  1993. <tag><tt/Suggests/
  1994. <item>
  1995. This is used to declare that one package may be more useful with one
  1996. or more others. Using this field tells the packaging system and the
  1997. user that the listed packages are be related to this one and can
  1998. perhaps enhance its usefulness, but that installing this one without
  1999. them is perfectly reasonable.
  2000. <p>
  2001. <prgn/dselect/ will offer suggsted packages to the system administrator
  2002. when they select the suggesting package, but the default is not to
  2003. install the suggested package.
  2004. <tag><tt/Pre-Depends/
  2005. <item>
  2006. This field is like <tt/Depends/, except that it also forces <prgn/dpkg/
  2007. to complete installation of the packages named before even starting
  2008. the installation of the package which declares the predependency.
  2009. <p>
  2010. <prgn/dselect/ checks for predependencies when it is doing an
  2011. installation run, and will attempt to find the packages which are
  2012. required to be installed first and do so in the right order.
  2013. <p>
  2014. However, this process is slow (because it requires repeated
  2015. invocations of <prgn/dpkg/) and troublesome (because it requires
  2016. guessing where to find the appropriate files).
  2017. <p>
  2018. For these reasons, and because this field imposes restrictions on the
  2019. order in which packages may be unpacked (which can be difficult for
  2020. installations from multipart media, for example), <tt/Pre-Depends/
  2021. should be used sparingly, preferably only by packages whose premature
  2022. upgrade or installation would hamper the ability of the system to
  2023. continue with any upgrade that might be in progress.
  2024. <p>
  2025. When the package declaring it is being configured, a
  2026. <tt/Pre-Dependency/ will be considered satisfied only if the depending
  2027. package has been correctly configured, just as if an ordinary
  2028. <tt/Depends/ had been used.
  2029. <p>
  2030. However, when a package declaring a predependency is being unpacked
  2031. the predependency can be satisfied even if the depended-on package(s)
  2032. are only unpacked or half-configured, provided that they have been
  2033. configured correctly at some point in the past (and not removed or
  2034. partially removed since). In this case both the previously-configured
  2035. and currently unpacked or half-configured versions must satisfy any
  2036. version clause in the <tt/Pre-Depends/ field.
  2037. </taglist>
  2038. <sect1>Dependencies on shared libraries
  2039. <p>
  2040. The dependency fields listed above are used by packages which need
  2041. shared libraries to declare dependencies on the appropriate packages.
  2042. <p>
  2043. These dependencies are usually determined automatically using
  2044. <prgn/dpkg-shlibdeps/ and inserted in the package control file using
  2045. the control file substitution variables mechanism; see <ref
  2046. id="srcsubstvars"> and <ref id="sourcetools">.
  2047. <sect1>Deconfiguration due to removal during bulk installations
  2048. <p>
  2049. If <prgn/dpkg/ would like to remove a package due to a conflict, as
  2050. described above, but this would violate a dependency of some other
  2051. package on the system, <prgn/dpkg/ will usually not remove the
  2052. conflicting package and halt with an error.
  2053. <p>
  2054. However, if the <tt/--auto-deconfigure/ (<tt/-B/) option is used
  2055. <prgn/dpkg/ will automatically `deconfigure' the package with the
  2056. problematic dependency, so that the conflicting package can be removed
  2057. and the package we're trying to install can be installed. If
  2058. <prgn/dpkg/ is being asked to install packages (rather than just
  2059. unpacking them) it will try to reconfigure the package when it has
  2060. unpacked all its arguments, in the hope that one of the other packages
  2061. it is installing will satisfy the problematic dependency.
  2062. <p>
  2063. <prgn/dselect/ supplies this argument to <prgn/dpkg/ when it invokes it,
  2064. so that bulk installations proceed smoothly.
  2065. <sect id="conflicts">Alternative packages - <tt/Conflicts/ and <tt/Replaces/
  2066. <p>
  2067. When one package declares a conflict with another <prgn/dpkg/ will
  2068. refuse to allow them to be installed on the system at the same time.
  2069. <p>
  2070. If one package is to be installed, the other must be removed first -
  2071. if the package being installed is marked as replacing (<ref
  2072. id="replaces">) the one on the system, or the one on the system is
  2073. marked as deselected, or both packages are marked <tt/Essential/, then
  2074. <prgn/dpkg/ will automatically remove the package which is causing the
  2075. conflict, otherwise it will halt the installation of the new package
  2076. with an error.
  2077. <p>
  2078. <prgn/dselect/ makes it hard to select conflicting packages, though the
  2079. user can override this if they wish. If they do not override it then
  2080. <prgn/dselect/ will select one of the packages for removal, and the user
  2081. must make sure it is the right one. In the future <prgn/dselect/ will
  2082. look for the presence of a <tt/Replaces/ field to help decide which
  2083. package should be installed and which removed.
  2084. <p>
  2085. A package will not cause a conflict merely because its configuration
  2086. files are still installed; it must be at least half-installed.
  2087. <p>
  2088. A special exception is made for packages which declare a conflict with
  2089. their own package name, or with a virtual package which they provide
  2090. (see below): this does not prevent their installation, and allows a
  2091. package to conflict with others providing a replacement for it. You
  2092. use this feature when you want the package in question to be the only
  2093. package providing something.
  2094. <p>
  2095. A <tt/Conflicts/ entry should almost never have an `earlier than'
  2096. version clause. This would prevent <prgn/dpkg/ from upgrading or
  2097. installing the package which declared such a conflict until the
  2098. upgrade or removal of the conflicted-with package had been completed.
  2099. This aspect of installation ordering is not handled by <prgn/dselect/,
  2100. so that the use <tt/Conflicts/ in this way is likely to cause problems
  2101. for `bulk run' upgrades and installations.
  2102. <p>
  2103. <sect id="virtual">Virtual packages - <tt/Provides/
  2104. <p>
  2105. As well as the names of actual (`concrete') packages, the package
  2106. relationship fields <tt/Depends/, <tt/Recommends/, <tt/Suggests/ and
  2107. <tt/Conflicts/ may mention virtual packages.
  2108. <p>
  2109. A virtual package is one which appears in the <tt/Provides/ control
  2110. file field of another package. The effect is as if the package(s)
  2111. which provide a particular virtual package name had been listed by
  2112. name everywhere were the virtual package name appears.
  2113. <p>
  2114. If there are both a real and a virtual package of the same name then
  2115. the dependency may be satisfied (or the conflict caused) by either the
  2116. real package or any of the virtual packages which provide it. This is
  2117. so that, for example, supposing we have
  2118. <example>
  2119. Package: vm
  2120. Depends: emacs
  2121. </example>
  2122. and someone else releases an xemacs package they can say
  2123. <example>
  2124. Package: xemacs
  2125. Provides: emacs
  2126. </example>
  2127. and all will work in the interim (until a purely virtual package name
  2128. is decided on and the <tt/emacs/ and <tt/vm/ packages are changed to
  2129. use it).
  2130. <p>
  2131. If a dependency or a conflict has a version number attached then only
  2132. real packages will be considered to see whether the relationship is
  2133. satisfied (or the prohibition violated, for a conflict) - it is
  2134. assumed that a real package which provides virtual package is not of
  2135. the `right' version. So, a <tt/Provides/ field may not contain
  2136. version numbers, and the version number of the concrete package which
  2137. provides a particular virtual package will not be looked at when
  2138. considering a dependency on or conflict with the virtual package name.
  2139. <p>
  2140. If you want to specify which of a set of real packages should be the
  2141. default to satisfy a particular dependency on a virtual package, you
  2142. should list the real package as alternative before the virtual.
  2143. <p>
  2144. <sect id="replaces"><tt/Replaces/ - overwriting files and replacing packages
  2145. <p>
  2146. The <tt/Replaces/ control file field has two purposes, which come into
  2147. play in different situations.
  2148. <p>
  2149. Virtual packages (<ref id="virtual">) are not considered when looking
  2150. at a <tt/Replaces/ field - the packages declared as being replaced
  2151. must be mentioned by their real names.
  2152. <sect1>Overwriting files in other packages
  2153. <p>
  2154. Firstly, as mentioned before, it is usually an error for a package to
  2155. contains files which are on the system in another package, though
  2156. currently the <tt/--force-overwrite/ flag is enabled by default,
  2157. downgrading the error to a warning,
  2158. <p>
  2159. If the overwriting package declares that it replaces the one
  2160. containing the file being overwritten then <prgn/dpkg/ will proceed, and
  2161. replace the file from the old package with that from the new. The
  2162. file will no longer be listed as `owned' by the old package.
  2163. <p>
  2164. If a package is completely replaced in this way, so that <prgn/dpkg/
  2165. does not know of any files it still contains, it is considered to have
  2166. disappeared. It will be marked as not wanted on the system (selected
  2167. for removal) and not installed. Any conffiles details noted in the
  2168. package will be ignored, as they will have been taken over by the
  2169. replacing package(s). The package's <prgn/postrm/ script will be run to
  2170. allow the package to do any final cleanup required.
  2171. See <ref id="mscriptsinstact">.
  2172. <p>
  2173. In the future <prgn/dpkg/ will discard files which overwrite those from
  2174. another package which declares that it replaces the one being
  2175. installed (so that you can install an older version of a package
  2176. without problems).
  2177. <p>
  2178. This usage of <tt/Replaces/ only takes effect when both packages are
  2179. at least partially on the system at once, so that it can only happen
  2180. if they do not conflict or if the conflict has been overridden.
  2181. <sect1>Replacing whole packages, forcing their removal
  2182. <p>
  2183. Secondly, <tt/Replaces/ allows <prgn/dpkg/ and <prgn/dselect/ to resolve
  2184. which package should be removed when a conflict - see
  2185. <ref id="conflicts">. This usage only takes effect when the two
  2186. packages <em/do/ conflict, so that the two effects do not interfere
  2187. with each other.
  2188. <p>
  2189. <sect>Defaults for satisfying dependencies - ordering
  2190. <p>
  2191. Ordering is significant in dependency fields.
  2192. <p>
  2193. Usually dselect will suggest to the user that they select the package
  2194. with the most `fundamental' class (eg, it will prefer Base packages to
  2195. Optional ones), or the one that they `most wanted' to select in some
  2196. sense.
  2197. <p>
  2198. In the absence of other information <prgn/dselect/ will offer a
  2199. default selection of the first named package in a list of
  2200. alternatives.
  2201. <p>
  2202. However, there is no way to specify the `order' of several packages
  2203. which all provide the same thing, when that thing is listed as a
  2204. dependency.
  2205. <p>
  2206. Therefore a dependency on a virtual package should contain a concrete
  2207. package name as the first alternative, so that this is the default.
  2208. <p>
  2209. For example, consider the set of packages:
  2210. <example>
  2211. Package: glibcdoc
  2212. Recommends: info-browser
  2213. Package: info
  2214. Provides: info-browser
  2215. Package: emacs
  2216. Provides: info-browser
  2217. </example>
  2218. <p>
  2219. If <prgn/emacs/ and <prgn/info/ both have the same priority then
  2220. <prgn/dselect/'s choice is essentially random. Better would be
  2221. <example>
  2222. Package: glibcdoc
  2223. Recommends: info | info-browser
  2224. </example>
  2225. so that <prgn/dselect/ defaults to selecting the lightweight standalone
  2226. info browser.
  2227. <chapt id="conffiles">Configuration file handling
  2228. <p>
  2229. <prgn/dpkg/ can do a certain amount of automatic handling of package
  2230. configuration files.
  2231. <p>
  2232. Whether this mechanism is appropriate depends on a number of factors,
  2233. but basically there are two approaches to any particular configuration
  2234. file.
  2235. <p>
  2236. The easy method is to ship a best-effort configuration in the package,
  2237. and use <prgn/dpkg/'s conffile mechanism to handle updates. If the user
  2238. is unlikely to want to edit the file, but you need them to be able to
  2239. without losing their changes, and a new package with a changed version
  2240. of the file is only released infrequently, this is a good approach.
  2241. <p>
  2242. The hard method is to build the configuration file from scratch in the
  2243. <prgn/postinst/ script, and to take the responsibility for fixing any
  2244. mistakes made in earlier versions of the package automatically. This
  2245. will be appropriate if the file is likely to need to be different on
  2246. each system.
  2247. <sect>Automatic handling of configuration files by <prgn/dpkg/
  2248. <p>
  2249. A package may contain a control area file called <tt/conffiles/. This
  2250. file should be a list of filenames of configuration files needing
  2251. automatic handling, separated by newlines. The filenames should be
  2252. absolute pathnames, and the files referred to should actually exist in
  2253. the package.
  2254. <p>
  2255. When a package is upgraded <prgn/dpkg/ will process the configuration
  2256. files during the configuration stage, shortly before it runs the
  2257. package's <prgn/postinst/ script,
  2258. <p>
  2259. For each file it checks to see whether the version of the file
  2260. included in the package is the same as the one that was included in
  2261. the last version of the package (the one that is being upgraded
  2262. from); it also compares the version currently installed on the system
  2263. with the one shipped with the last version.
  2264. <p>
  2265. If neither the user nor the package maintainer has changed the file,
  2266. it is left alone. If one or the other has changed their version, then
  2267. the changed version is preferred - ie, if the user edits their file,
  2268. but the package maintainer doesn't ship a different version, the
  2269. user's changes will stay, silently, but if the maintainer ships a new
  2270. version and the user hasn't edited it the new version will be
  2271. installed (with an informative message). If both have changed their
  2272. version the user is prompted about the problem and must resolve the
  2273. differences themselves.
  2274. <p>
  2275. The comparisons are done by calculating the MD5 message digests of the
  2276. files, and storing the MD5 of the file as it was included in the most
  2277. recent version of the package.
  2278. <p>
  2279. When a package is installed for the first time <prgn/dpkg/ will install
  2280. the file that comes with it, unless that would mean overwriting a file
  2281. already on the filesystem.
  2282. <p>
  2283. However, note that <prgn/dpkg/ will <em/not/ replace a conffile that
  2284. was removed by the user (or by a script). This is necessary because
  2285. with some programs a missing file produces an effect hard or
  2286. impossible to achieve in another way, so that a missing file needs to
  2287. be kept that way if the user did it.
  2288. <p>
  2289. Note that a package should <em/not/ modify a <prgn/dpkg/-handled
  2290. conffile in its maintainer scripts. Doing this will lead to
  2291. <prgn/dpkg/ giving the user confusing and possibly dangerous options
  2292. for conffile update when the package is upgraded.
  2293. <sect>Fully-featured maintainer script configuration handling
  2294. <p>
  2295. For files which contain site-specific information such as the hostname
  2296. and networking details and so forth, it is better to create the file
  2297. in the package's <prgn/postinst/ script.
  2298. <p>
  2299. This will typically involve examining the state of the rest of the
  2300. system to determine values and other information, and may involve
  2301. prompting the user for some information which can't be obtained some
  2302. other way.
  2303. <p>
  2304. When using this method there are a couple of important issues which
  2305. should be considered:
  2306. <p>
  2307. If you discover a bug in the program which generates the configuration
  2308. file, or if the format of the file changes from one version to the
  2309. next, you will have to arrange for the postinst script to do something
  2310. sensible - usually this will mean editing the installed configuration
  2311. file to remove the problem or change the syntax. You will have to do
  2312. this very carefully, since the user may have changed the file, perhaps
  2313. to fix the very problem that your script is trying to deal with - you
  2314. will have to detect these situations and deal with them correctly.
  2315. <p>
  2316. If you do go down this route it's probably a good idea to make the
  2317. program that generates the configuration file(s) a separate program in
  2318. <tt>/usr/sbin</>, by convention called <tt/<var/package/config/ and
  2319. then run that if appropriate from the post-installation script. The
  2320. <tt/<var/package/config/ program should not unquestioningly overwrite
  2321. an existing configuration - if its mode of operation is geared towards
  2322. setting up a package for the first time (rather than any arbitrary
  2323. reconfiguration later) you should have it check whether the
  2324. configuration already exists, and require a <tt/--force/ flag to
  2325. overwrite it.
  2326. <chapt id="alternatives">Alternative versions of an interface -
  2327. <prgn/update-alternatives/
  2328. <p>
  2329. When several packages all provide different versions of the same
  2330. program or file it is useful to have the system select a default, but
  2331. to allow the system administrator to change it and have their
  2332. decisions respected.
  2333. <p>
  2334. For example, there are several versions of the <prgn/vi/ editor, and
  2335. there is no reason to prevent all of them from being installed at
  2336. once, each under their own name (<prgn/nvi/, <prgn/vim/ or whatever).
  2337. Nevertheless it is desirable to have the name <tt/vi/ refer to
  2338. something, at least by default.
  2339. <p>
  2340. If all the packages involved cooperate, this can be done with
  2341. <prgn/update-alternatives/.
  2342. <p>
  2343. Each package provides its own version under its own name, and calls
  2344. <prgn/update-alternatives/ in its postinst to register its version
  2345. (and again in its prerm to deregister it).
  2346. <p>
  2347. See the manpage <manref name=update-alternatives section=8> for
  2348. details.
  2349. <p>
  2350. If <prgn/update-alternatives/ does not seem appropriate you may wish
  2351. to consider using diversions instead.
  2352. <chapt id="diversions">Diversions - overriding a package's version of a file
  2353. <p>
  2354. It is possible to have <prgn/dpkg/ not overwrite a file when it
  2355. reinstalls the package it belongs to, and to have it put the file from
  2356. the package somewhere else instead.
  2357. <p>
  2358. This can be used locally to override a package's version of a file, or
  2359. by one package to override another's version (or provide a wrapper for
  2360. it).
  2361. <p>
  2362. Before deciding to use a diversion, read <ref id="alternatives"> to
  2363. see if you really want a diversion rather than several alternative
  2364. versions of a program.
  2365. <p>
  2366. There is a diversion list, which is read by <prgn/dpkg/, and updated
  2367. by a special program <prgn/dpkg-divert/. Please see <manref
  2368. name=dpkg-divert section=8> for full details of its operation.
  2369. <p>
  2370. When a package wishes to divert a file from another, it should call
  2371. <prgn/dpkg-divert/ in its preinst to add the diversion and rename the
  2372. existing file. For example, supposing that a <prgn/smailwrapper/
  2373. package wishes to install a wrapper around <tt>/usr/sbin/smail</>:
  2374. <example>
  2375. if [ install = "$1" ]; then
  2376. dpkg-divert --package smailwrapper --add --rename \
  2377. --divert /usr/sbin/smail.real /usr/sbin/smail
  2378. fi
  2379. </example>
  2380. Testing <tt/$1/ is necessary so that the script doesn't try to add the
  2381. diversion again when <prgn/smailwrapper/ is upgraded. The
  2382. <tt/--package smailwrapper/ ensures that <prgn/smailwrapper/'s copy of
  2383. <tt>/usr/sbin/smail</> can bypass the diversion and get installed as
  2384. the true version.
  2385. <p>
  2386. The postrm has to do the reverse:
  2387. <example>
  2388. if [ remove = "$1" ]; then
  2389. dpkg-divert --package smailwrapper --remove --rename \
  2390. --divert /usr/sbin/smail.real /usr/sbin/smail
  2391. fi
  2392. </example>
  2393. <p>
  2394. Do not attempt to divert a file which is vitally important for the
  2395. system's operation - when using <prgn/dpkg-divert/ there is a time,
  2396. after it has been diverted but before <prgn/dpkg/ has installed the
  2397. new version, when the file does not exist.
  2398. <chapt id="sharedlibs">Shared libraries
  2399. <p>
  2400. Packages containing shared libraries must be constructed with a little
  2401. care to make sure that the shared library is always available. This
  2402. is especially important for packages whose shared libraries are
  2403. vitally important, such as the libc.
  2404. <p>
  2405. Firstly, your package should install the shared libraries under their
  2406. normal names. For example, the <prgn/libgdbm1/ package should install
  2407. <tt/libgdbm.so.1.7.3/ as <tt>/usr/lib/libgdbm.so.1.7.3</tt>. The
  2408. files should not be renamed or relinked by any prerm or postrm
  2409. scripts; <prgn/dpkg/ will take care of renaming things safely without
  2410. affecting running programs, and attempts to interfere with this are
  2411. likely to lead to problems.
  2412. <p>
  2413. Secondly, your package should include the symlink that <prgn/ldconfig/
  2414. would create for the shared libraries. For example, the
  2415. <prgn/libgdbm1/ package should include a symlink from
  2416. <tt>/usr/lib/libgdbm.so.1</tt> to <tt/libgdbm.so.1.7.3/. This is
  2417. needed so that <prgn/ld.so/ can find the library in between the time
  2418. <prgn/dpkg/ installs it and <prgn/ldconfig/ is run in the
  2419. <prgn/postinst/ script. Futhermore, and <em/this is very important/,
  2420. the library must be placed before the symlink pointing to it in the
  2421. <tt/.deb/ file. This is so that by the time <prgn/dpkg/ comes to
  2422. install the symlink (overwriting the previous symlink pointing at an
  2423. older version of the library) the new shared library is already in
  2424. place. Currently the way to ensure the ordering is done properly is
  2425. to install the library in the appropriate <tt>debian/tmp/.../lib</>
  2426. directory before creating the symlink, by putting the commands in the
  2427. <tt>debian/rules</> in the appropriate order.
  2428. <p>
  2429. If you do the above your package does not need to call <prgn/ldconfig/
  2430. in its maintainer scripts. It is especially important not to call
  2431. <prgn/ldconfig/ in the postrm or preinst scripts in the case where the
  2432. package is being upgraded (see the programmer's manual), as
  2433. <prgn/ldconfig/ will see the temporary names that <prgn/dpkg/ uses for the
  2434. files while it is installing them and will make the shared library
  2435. links point to them, just before <prgn/dpkg/ continues the installation
  2436. and removes the links!
  2437. <chapt id="sysvinit">Configuration of <prgn/init/
  2438. <p>
  2439. <sect>Introduction to the <tt/init.d/ scheme
  2440. <p>
  2441. The <tt>/etc/init.d</> directory contains the scripts executed by
  2442. <prgn/init/ when init state (or `runlevel') is changed (see <manref
  2443. name=init section=8>).
  2444. <p>
  2445. These scripts are be referenced by symbolic links in the
  2446. <tt>/etc/rc<var/n/.d</> directories. When changing runlevels, init
  2447. looks in the directory <tt>/etc/rc<var/n/.d</> for the scripts it
  2448. should execute, where <var/n/ is the runlevel that is being changed
  2449. to.
  2450. <p>
  2451. The names of the links all have the form <tt/S<var/mm/<var/script// or
  2452. <tt/K<var/mm/<var/script// where <var/mm/ is a two-digit number and
  2453. <var/script/ is the name of the script (this should be the same as the
  2454. name of the actual script in <tt>/etc/init.d</>.
  2455. When <prgn/init/ changes runlevel first the targets of the links whose
  2456. names starting with a <tt/K/ are executed, each with the single
  2457. argument <tt/stop/, followed by the scripts prefixed with an <tt/S/,
  2458. each with the single argument <tt/start/. The <tt/K/ links are
  2459. responsible for killing services and the <tt/S/ link for starting
  2460. services upon entering the runlevel.
  2461. <p>
  2462. For example, if we are changing from runlevel 2 to runlevel 3, init
  2463. will first execute all of the <tt/K/ prefixed scripts it finds in
  2464. <tt>/etc/rc3.d</>, and then all of the <tt/S/ prefixed scripts. The
  2465. links starting with <tt/K/ will cause the referred-to file to be
  2466. executed with an argument of <tt/stop/, and the <tt/S/ links with an
  2467. argument of <tt/start/.
  2468. <p>
  2469. The two-digit number <var/mm/ is used to decide which order to start
  2470. and stop things in - low-numbered links have their scripts run first.
  2471. For example, the <tt/K20/ scripts will be executed before the <tt/K30/
  2472. scripts. This is used when a certain service must be started before
  2473. another. For example, the name server <prgn/bind/ might need to be
  2474. started before the news server <prgn/inn/ so that <prgn/inn/ can set
  2475. up its access lists. In this case, the script that starts <prgn/bind/
  2476. should have a lower number than the script that starts <prgn/inn/ so
  2477. that it runs first:
  2478. <example>
  2479. /etc/rc2.d/S17bind
  2480. /etc/rc2.d/S70inn
  2481. </example>
  2482. <sect>Writing <tt/init.d/ scripts
  2483. <p>
  2484. Packages can and should place scripts in <tt>/etc/init.d</> to start
  2485. or stop services at boot time or during a change of runlevel. These
  2486. scripts should be named <tt>/etc/init.d/<var/package/</>, and they
  2487. should accept one argument, saying what to do: <tt/start/, meaning to
  2488. starts the service, or <tt/stop/, to stop the service. Optionally
  2489. they can support <tt/reload/ which causes the configuration to be
  2490. reloaded.
  2491. <p>
  2492. The <tt/init.d/ scripts should ensure that they will behave sensibly
  2493. if invoked with <tt/start/ when the service is already running, or
  2494. with <tt/stop/ when it isn't, and that they don't kill
  2495. unfortunately-named user processes. The best way to achieve this is
  2496. usually to use <prgn/start-stop-daemon/.
  2497. <p>
  2498. These scripts should not fail obscurely when the configuration files
  2499. remain but the package has been removed, as the default in <prgn/dpkg/
  2500. is to leave configuration files on the system after the package has
  2501. been removed. Only when it is executed with the <tt/--purge/ option
  2502. will dpkg remove configuration files. Therefore, you should include a
  2503. <tt/test/ statement at the top of the script, like this:
  2504. <example>
  2505. test -f <var/program-executed-later-in-script/ || exit 0
  2506. </example>
  2507. <sect>Managing the <tt/rc<var/n/.d/ links - <prgn/update-rc.d/
  2508. <p>
  2509. A program is provided, <prgn/update-rc.d/, to make it easier for
  2510. package maintainers to arrange for the proper creation and removal of
  2511. <tt>/etc/rc<var/n/.d</> symbolic links from their postinst and postrm
  2512. scripts.
  2513. <p>
  2514. You should use this script to make changes to <tt>/etc/rc<var/n/.d</>
  2515. and <em/never/ include any <tt>/etc/rc<var/n/.d</> symbolic links in
  2516. the actual archive.
  2517. <p>
  2518. By default <prgn/update-rc.d/ will start services in each of the
  2519. multi-user state runlevels (2, 3, 4, and 5) and stop them in the halt
  2520. runlevel (0), the single-user runlevel (1) and the reboot runlevel
  2521. (6). The system administrator will have the opportunity to customize
  2522. runlevels by simply adding, moving, or removing the symbolic links in
  2523. <tt>/etc/rc<var/n/.d</>.
  2524. <p>
  2525. To get the default behaviour for your package, put in your postinst
  2526. script
  2527. <example>
  2528. update-rc.d <var/package/ default &gt;/dev/null
  2529. </example>
  2530. and in your postrm
  2531. <example>
  2532. if [ purge = "$1" ]; then
  2533. update-rc.d <var/package/ remove &gt;/dev/null
  2534. fi
  2535. </example>
  2536. <p>
  2537. This will use a default sequence number of 20. If it does not matter
  2538. when or in which order the script is run, use this default. If it
  2539. does, then you should talk to the maintainer of the <prgn/sysvinit/
  2540. package or post to <tt>debian-devel</>, and they will help you choose
  2541. a number.
  2542. <p>
  2543. For more information about using <tt/update-rc.d/, please consult its
  2544. manpage <manref name=update-rc.d section=8>.
  2545. <sect>Boot-time initialisation - <tt/rc.boot/
  2546. <p>
  2547. There is another directory, <tt>/etc/rc.boot</>, which contains
  2548. scripts which are run once per machine boot. This facility is
  2549. provided for initialisation of hardware devices, cleaning up of
  2550. leftover files, and so forth.
  2551. <p>
  2552. For example, the <prgn/kbd/ package provides a script here for
  2553. initialising the keyboard layout and console font and mode.
  2554. <p>
  2555. The files in <tt>/etc/rc.boot</> should <em/not/ be links into
  2556. <tt>/etc/init.d</> - they should be the scripts themselves.
  2557. <p>
  2558. <tt/rc.boot/ should <em/not/ be used for starting general-purpose
  2559. daemons and similar activities. This should be done using the
  2560. <tt/rc<var/n/.d/ scheme, above, so that the services can be started
  2561. and stopped cleanly when the runlevel changes or the machine is to be
  2562. shut down or rebooted.
  2563. <sect>Notes
  2564. <p>
  2565. <em/Do not/ include the <tt>/etc/rc<var/n/.d/*</> symbolic links in
  2566. the <tt/.deb/ filesystem archive! <em/This will cause problems!/
  2567. You should create them with <prgn/update-rc.d/, as above.
  2568. <p>
  2569. <em/Do not/ include the <tt>/etc/rc<var/n/.d/*</> symbolic links in
  2570. <prgn/dpkg/'s conffiles list! <em/This will cause problems!/
  2571. <em/Do/, however, include the <tt>/etc/init.d</> scripts in conffiles.
  2572. <sect>Example
  2573. <p>
  2574. The <prgn/bind/ DNS (nameserver) package wants to make sure that the
  2575. nameserver is running in multiuser runlevels, and is properly shut
  2576. down with the system. It puts a script in <tt>/etc/init.d</>, naming
  2577. the script appropriately <tt/bind/. As you can see, the script
  2578. interprets the argument <tt/reload/ to send the nameserver a <tt/HUP/
  2579. signal (causing it to reload its configuration); this way the user can
  2580. say <tt>/etc/init.d/bind reload</> to reload the nameserver.
  2581. <p>
  2582. <example>
  2583. #!/bin/sh
  2584. # Original version by Robert Leslie &lt;rob@mars.org&gt;, edited by iwj
  2585. test -x /usr/sbin/named || exit 0
  2586. case "$1" in
  2587. start)
  2588. test -f /etc/named.boot -a -f /var/named/boot.options || exit 0
  2589. start-stop-daemon --start --verbose --exec /usr/sbin/named
  2590. ;;
  2591. stop)
  2592. start-stop-daemon --stop --verbose \
  2593. --pidfile /var/run/named.pid --exec /usr/sbin/named
  2594. ;;
  2595. reload)
  2596. start-stop-daemon --stop --signal 1 --verbose \
  2597. --pidfile /var/run/named.pid --exec /usr/sbin/named
  2598. ;;
  2599. *)
  2600. echo "Usage: /etc/init.d/bind {start|stop|reload}" >&2
  2601. exit 1
  2602. ;;
  2603. esac
  2604. exit 0
  2605. </example>
  2606. <p>
  2607. Another example on which to base your <tt>/etc/init.d</> scripts is in
  2608. <tt>/etc/init.d/skeleton</>.
  2609. <p>
  2610. If this package is happy with the default setup from
  2611. <prgn/update-rc.d/, namely an ordering number of 20 and having named
  2612. running in all runlevels, it can say in its postinst:
  2613. <example>
  2614. update-rc.d bind default >/dev/null
  2615. </example>
  2616. And in its postrm, to remove the links when the package is purged:
  2617. <example>
  2618. if [ purge = "$1" ]; then
  2619. update-rc.d acct remove >/dev/null
  2620. fi
  2621. </example>
  2622. <chapt id="methif"><prgn/dselect/'s interface to its installation methods
  2623. <p>
  2624. <prgn/dselect/ calls scripts from its installation methods when it
  2625. needs to actually access data from the distribution. The core program
  2626. <prgn/dselect/ itself just calls these scripts and provides the
  2627. package and access method selection interfaces. The installation
  2628. methods are responsible for invoking <prgn/dpkg/ as appropriate.
  2629. <p>
  2630. Each installation method has three scripts:
  2631. <list compact>
  2632. <item>Setup installation parameters.
  2633. <item>Update list of available packages.
  2634. <item>Install.
  2635. </list>
  2636. <p>
  2637. <prgn/dselect/ searches for methods in <tt>/usr/lib/dpkg/methods</>
  2638. and <tt>/usr/local/lib/dpkg/methods</>.
  2639. <sect>Functions of the method scripts
  2640. <p>
  2641. The setup script is run just after the user has chosen an installation
  2642. method. It should prompt the user for parameters like the site to
  2643. NFS-mount or FTP from, the directory to use, or the directory or
  2644. filesystem where the <tt/.deb/ files can be found, or the tape or
  2645. floppy device to install from. It should store the responses under
  2646. <tt>/var/lib/dpkg/methods</> - see below. If no available
  2647. packages list is available it should perhaps offer to scan the
  2648. available packages.
  2649. <p>
  2650. The update script should obtain a list of available packages if
  2651. possible, and run <tt/dpkg --update-avail/, <tt/dpkg --merge-avail/
  2652. and/or <tt/dpkg --forget-old-unavail/ to load it into <prgn/dpkg/ and
  2653. <prgn/dselect/'s database of available packages. If no packages list
  2654. was available and the user was offered and accepted the option of
  2655. scanning the actual files available this scan should be done here,
  2656. using <tt/dpkg --record-avail/.
  2657. <p>
  2658. The install script should feed all the available <tt/.deb/ files to
  2659. <tt/dpkg --iGOEB/ (this is equivalent to <tt/dpkg --install
  2660. --refuse-downgrade --selected-only --skip-same-version
  2661. --auto-deconfigure/). The <tt/-R/ (<tt/--recursive/) option for
  2662. traversing subdirectories may also be useful here).
  2663. <p>
  2664. If any of these scripts needs to display a message for the user, it
  2665. should wait for the user to hit `return' before exiting so that
  2666. dselect doesn't immediately rewrite the screen.
  2667. <p>
  2668. If a method script succeeds (returns a zero exit status)
  2669. <prgn/dselect/ will return immediately to the main menu, with the
  2670. `next' option highlighted ready for the user to select it. If it
  2671. fails <prgn/dselect/ will display a message and wait for the user to
  2672. hit return.
  2673. <sect>Location and arguments of the method scripts
  2674. <p>
  2675. A set of scripts (henceforth known as a group) may provide several
  2676. methods on the `main menu' with different behaviour. For example,
  2677. there might be a generic get-packages-by-FTP group which might provide
  2678. methods in the main menu for installation directly from one of the
  2679. Debian mirror sites as well as for installation from a user-specified
  2680. site.
  2681. <p>
  2682. Each group of methods implemented by the same set of scripts should
  2683. have a subdirectory <tt>/usr/lib/dpkg/methods/<var/group/</> or
  2684. <tt>/usr/local/lib/dpkg/methods/<var/group/</>, containing:
  2685. <taglist compact>
  2686. <tag><tt/names/
  2687. <item>a list of user-visible methods provided by these scripts.
  2688. <tag><tt/setup/
  2689. <tag><tt/update/
  2690. <tag><tt/install/
  2691. <item>executable programs, the scripts themselves.
  2692. <tag><tt/desc.<var/option//
  2693. <item>description file.
  2694. </taglist>
  2695. <p>
  2696. <tt/names/ will be formatted as a list of lines, each containing:
  2697. <example>
  2698. <var/sequence/ <var/method/ <var/summary/
  2699. </example>
  2700. <p>
  2701. <var/sequence/ is a two-digit number that will be used much like
  2702. <tt/rc.d/ prefixes to control the order in the main menu. If in doubt
  2703. use 50.
  2704. <p>
  2705. <var/method/ is a name which is displayed by <prgn/dselect/ as the
  2706. name of the method, and which will be passed to <tt/setup/,
  2707. <tt/update/ and <tt/unpack/ as their first argument.
  2708. <p>
  2709. <var/summary/ is the brief description string for <prgn/dselect/'s menu.
  2710. <p>
  2711. Each of the three scripts gets the same three arguments: <var/vardir/,
  2712. <var/group/ and <var/method/. <var/vardir/ is the base directory for
  2713. storing <prgn/dpkg/ and <prgn/dselect/'s state, usually
  2714. <tt>/var/lib/dpkg</>; this is passed in so that the <tt/--admindir/
  2715. option to <prgn/dselect/ is honoured).
  2716. <p>
  2717. Each option may have an extended description in
  2718. <tt/desc.<var/option//. This should be formatted like the extended
  2719. description part of a <tt/Description/ field entry <em/shifted one
  2720. character to the left/.
  2721. <p>
  2722. <tt><var/vardir//methods</> will exist, and a method group may use a
  2723. <tt><var/vardir//methods/<var/group/</> directory to store its state.
  2724. <p>
  2725. The group name and method name must follow the rules for C identifiers.
  2726. </book>