maintainer-script-args.txt 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. Richard Kettlewell has asked me to document this, so here is a brief
  2. summary. More documentation will probably have to wait until someone
  3. has time ...
  4. ... hmm, it has turned out not to be so brief, and I've spent the last
  5. hour or so writing it. Perhaps someone can use it as the basis for a
  6. spec or a manpage or something.
  7. In all cases version numbers are <version>-<revision>, if the package
  8. has both, or just <version>. `upgrade' is used even when the new
  9. version number looks lower than the old.
  10. *** SUMMARY - listing of possible scripts with arguments:
  11. <new preinst> install
  12. <new preinst> install <old-version>
  13. <new preinst> upgrade <old-version>
  14. <old preinst> abort-upgrade <new-version>
  15. <postinst> configure
  16. <old postinst> abort-upgrade <new version>
  17. <conflictor's postinst> abort-remove in-favour <package> <new version>
  18. <deconfigured's postinst> abort-deconfigure \
  19. in-favour <package-being-installed-but-failed> <version>
  20. removing <conflicting-package> <version>
  21. <prerm> remove
  22. <old prerm> upgrade <new version>
  23. <new prerm> failed-upgrade <old-vppersion>
  24. <conflictor's prerm> remove in-favour <package> <new version>
  25. <deconfigured's prerm> deconfigure \
  26. in-favour <package-being-installed> <version> \
  27. removing <conflicting-package> <version>
  28. <postrm> remove
  29. <postrm> purge
  30. <old postrm> upgrade <new-version>
  31. <new postrm> failed-upgrade <old-version>
  32. <new postrm> abort-install
  33. <new postrm> abort-install <old-version>
  34. <new postrm> abort-upgrade <old-version>
  35. <disappearer's postrm> disappear <overwriter> <new version>
  36. *** INSTALLATION (unpack):
  37. The procedure on installation/upgrade/overwrite/disappear (ie, when
  38. running dpkg --unpack, or the unpack stage of dpkg --install) is as
  39. follows. In each case if an error occurs the actions in are general
  40. run backwards - this means that the maintainer scripts are run with
  41. different arguments in reverse order. These are the `error unwind'
  42. calls listed below.
  43. 1a. If a version the package is already installed, call
  44. <old prerm> upgrade <new version>
  45. 1b. If this gives an error (ie, a non-zero exit status), dpkg will
  46. attempt instead:
  47. <new prerm> failed-upgrade <old-version>
  48. ... error unwind, for both the above cases:
  49. <old postinst> abort-upgrade <new version>
  50. 2. If a `conflicting' package is being removed at the same time:
  51. 2a. If any packages depended on that conflicting package and
  52. --auto-deconfigure is specified, call, for each such package:
  53. <deconfigured's prerm> deconfigure \
  54. in-favour <package-being-installed> <version> \
  55. removing <conflicting-package> <version>
  56. ... error unwind:
  57. <deconfigured's postinst> abort-deconfigure \
  58. in-favour <package-being-installed-but-failed> <version>
  59. removing <conflicting-package> <version>
  60. The deconfigured packages are marked as requiring configuration, so
  61. that if --install is used they will be configured again if possible.
  62. 2b. To prepare for removal of the conflicting package, call:
  63. <conflictor's prerm> remove in-favour <package> <new version>
  64. ... error unwind:
  65. <conflictor's postinst> abort-remove in-favour <package> <new version>
  66. 3a. If the package is being upgraded, call
  67. <new preinst> upgrade <old-version>
  68. 3b. otherwise, if the package had some configuration files from a
  69. previous version installed (ie, it is in the conffiles-only state):
  70. <new preinst> install <old-version>
  71. 3c. otherwise (ie, the package was completely purged):
  72. <new preinst> install
  73. ... error unwind versions, respectively:
  74. <new postrm> abort-upgrade <old-version>
  75. <new postrm> abort-install <old-version>
  76. <new postrm> abort-install
  77. 4. The new package's files are unpacked, overwriting any that may be
  78. on the system already, for example any from the old package or from
  79. another package (backups of the old files are left around, and if
  80. anything goes wrong dpkg will attempt to put them back as part of the
  81. error unwind).
  82. 5a. If the package is being upgraded, call
  83. <old postrm> upgrade <new-version>
  84. 5b. If this fails, dpkg will attempt:
  85. <new postrm> failed-upgrade <old-version>
  86. ... error unwind, for both cases:
  87. <old preinst> abort-upgrade <new-version>
  88. This is the point of no return - if dpkg gets this far, it won't back
  89. off past this point if an error occurs. This will leave the package
  90. in a fairly bad state, which will require a successful reinstallation
  91. to clear up, but it's when dpkg starts doing things that are
  92. irreversible.
  93. 6. Any files which were in the old version of the package but not in
  94. the new are removed.
  95. 7. The new file list replaces the old.
  96. 8. The new maintainer scripts replace the old.
  97. 9. Any packages all of whose files have been overwritten during the
  98. installation, and which aren't required for dependencies, are
  99. considered to have been removed. For each such package,
  100. 9a. dpkg calls:
  101. <disappearer's postrm> disappear <overwriter> <new version>
  102. 9b. The package's maintainer scripts are removed.
  103. 9c. It is noted in the status database as being in a sane state,
  104. namely not installed (any conffiles it may have are ignored).
  105. Note that disappearing packages don't have their prerm called, because
  106. dpkg doesn't know in advance that the package is going to vanish.
  107. 10. Any files in the package we're unpacking that are also listed in
  108. the file lists of other packages are removed from those lists. (This
  109. will lobotomise the file list of the `conflicting' package if there is
  110. one.)
  111. 11. The backup files made at 4. are deleted.
  112. 12. The new package's status is now sane, and recorded as `unpacked'.
  113. Here is another point of no return - if the conflicting package's
  114. removal fails we don't unwind the rest of the installation; the
  115. conflicting package is left in a half-removed limbo.
  116. 13. If there was a conflicting package we go and do the removal
  117. actions, starting from point 2. of the removal, below.
  118. *** CONFIGURATION:
  119. When we configure a package (this happens with dpkg --install, or with
  120. --configure), we first update the conffiles and then call:
  121. <postinst> configure
  122. (I'm planning to make available as an argument the version of the most
  123. recent successfully-configured version of the package.)
  124. No attempt is made to unwind after errors during configuration.
  125. *** REMOVAL:
  126. 1. <prerm> remove
  127. 2. The package's files are removed (except conffiles).
  128. 3. <postrm> remove
  129. 4. All the maintainer scripts except the postrm are removed.
  130. If we aren't purging the package we stop here. Note that packages
  131. which have no postrm and no conffiles are automatically purged when
  132. removed, as there is no difference except for the dpkg status.
  133. 5. The conffiles and any backup files (~-files, #*# files, %-files,
  134. .dpkg-{old,new,tmp}, &c &c &c) are removed.
  135. 6. <postrm> purge
  136. 7. The package's file list is removed.
  137. No attempt is made to unwind after errors during removal.