dpkg-maintscript-helper.1 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. .\" dpkg manual page - dpkg-maintscript-helper(1)
  2. .\"
  3. .\" Copyright © 2010-2012 Raphaël Hertzog <hertzog@debian.org>
  4. .\"
  5. .\" This is free software; you can redistribute it and/or modify
  6. .\" it under the terms of the GNU General Public License as published by
  7. .\" the Free Software Foundation; either version 2 of the License, or
  8. .\" (at your option) any later version.
  9. .\"
  10. .\" This is distributed in the hope that it will be useful,
  11. .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. .\" GNU General Public License for more details.
  14. .\"
  15. .\" You should have received a copy of the GNU General Public License
  16. .\" along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. .
  18. .TH dpkg\-maintscript\-helper 1 "2012-02-08" "Debian Project" "dpkg suite"
  19. .SH NAME
  20. dpkg\-maintscript\-helper \- works around known dpkg limitations in maintainer scripts
  21. .
  22. .SH SYNOPSIS
  23. .B dpkg\-maintscript\-helper
  24. .IR command " [" parameter "...] \fB\-\-\fP " maint-script-parameter ...
  25. .
  26. .SH COMMANDS AND PARAMETERS
  27. .P
  28. \fBrm_conffile\fP \fIconffile\fP [\fIpriorversion\fP [\fIpackage\fP]]
  29. .P
  30. \fBmv_conffile\fP \fIoldconffile\fP \fInewconffile\fP [\fIpriorversion\fP [\fIpackage\fP]]
  31. .
  32. .SH DESCRIPTION
  33. .P
  34. This program is designed to be run within maintainer scripts to achieve
  35. some tasks that dpkg can't (yet) handle natively either because of design
  36. decisions or due to current limitations.
  37. .P
  38. Many of those tasks require coordinated actions from several maintainer
  39. scripts (\fBpreinst\fP, \fBpostinst\fP, \fBprerm\fP, \fBpostrm\fP). To
  40. avoid mistakes the same call simply needs to be put in all scripts and the
  41. program will automatically adapt its behaviour based on the environment
  42. variable \fBDPKG_MAINTSCRIPT_NAME\fP and on the maintainer scripts arguments
  43. that you have to forward after a double dash.
  44. .
  45. .SH CONFFILE RELATED TASKS
  46. .P
  47. When upgrading a package, dpkg will not automatically remove a conffile (a
  48. configuration file for which dpkg should preserve user changes) if it is
  49. not present in the newer version. There are two principal reasons for
  50. this; the first is that the conffile could've been dropped by accident and
  51. the next version could restore it, users wouldn't want their changes
  52. thrown away. The second is to allow packages to transition files from a
  53. dpkg\-maintained conffile to a file maintained by the package's maintainer
  54. scripts, usually with a tool like debconf or ucf.
  55. .P
  56. This means that if a package is intended to rename or remove a conffile,
  57. it must explicitly do so and \fBdpkg\-maintscript\-helper\fP can be used
  58. to implement graceful deletion and moving of conffiles within maintainer
  59. scripts.
  60. .
  61. .SS REMOVING A CONFFILE
  62. .P
  63. If a conffile is completely removed, it should be removed from disk,
  64. unless the user has modified it. If there are local modifications, they
  65. should be preserved. If the package upgrades aborts, the newly obsolete
  66. conffile should not disappear.
  67. .P
  68. All of this is implemented by putting the following shell snippet in the
  69. \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer scripts:
  70. .P
  71. dpkg\-maintscript\-helper rm_conffile \\
  72. \fIconffile\fP \fIpriorversion\fP \fIpackage\fP \-\- "$@"
  73. .P
  74. \fIconffile\fP is the filename of the conffile to remove.
  75. .P
  76. \fIpriorversion\fP defines the latest version of the package whose
  77. upgrade should trigger the removal. It is important to calculate
  78. \fIpriorversion\fP correctly so that conffiles are correctly removed even
  79. if the user rebuilt the package with a local version. For example, for a
  80. conffile removed in version \fB2.0\-1\fP of a package, \fIpriorversion\fP
  81. should be set to \fB2.0\-1~\fP. This will cause the conffile to be removed
  82. even if the user rebuilt the previous version \fB1.0\-1\fP as
  83. \fB1.0\-1local1\fP.
  84. .P
  85. If the conffile has not been shipped for several versions, and you are now
  86. modifying the maintainer scripts to clean up the obsolete file,
  87. \fIpriorversion\fP should be based on the version of the package that you are
  88. now preparing, not the first version of the package that lacked the
  89. conffile.
  90. .P
  91. \fIpackage\fP is the package name. If empty or omitted, the
  92. DPKG_MAINTSCRIPT_PACKAGE environment variable (as set by dpkg) will be used.
  93. .P
  94. All the parameters of the maintainer scripts have to be forwarded to the
  95. program after "\-\-".
  96. .P
  97. Current implementation: in the \fBpreinst\fP, it checks if the conffile
  98. was modified and renames it either to \fIconffile\fP\fB.dpkg\-remove\fP (if not
  99. modified) or to \fIconffile\fP\fB.dpkg\-backup\fP (if modified). In the
  100. \fBpostinst\fP, the latter file is renamed to \fIconffile\fP\fB.dpkg\-bak\fP
  101. and kept for reference as it contains user modifications but the former will
  102. be removed. If the package upgrade aborts, the \fBpostrm\fP reinstalls the
  103. original conffile. During purge, the \fBpostrm\fP will also delete the
  104. \fB.dpkg\-bak\fP file kept up to now.
  105. .
  106. .SS RENAMING A CONFFILE
  107. .P
  108. If a conffile is moved from one location to another, you need to make sure
  109. you move across any changes the user has made. This may seem a simple
  110. change to the \fBpreinst\fP script at first, however that will result in
  111. the user being prompted by dpkg to approve the conffile edits even though
  112. they are not responsible of them.
  113. .P
  114. Graceful renaming can be implemented by putting the following shell
  115. snippet in the \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer
  116. scripts:
  117. .P
  118. dpkg\-maintscript\-helper mv_conffile \\
  119. \fIoldconffile\fP \fInewconffile\fP \fIpriorversion\fP \fIpackage\fP \-\- "$@"
  120. .P
  121. \fIoldconffile\fP and \fInewconffile\fP are the old and new name of the
  122. conffile to rename.
  123. .P
  124. \fIpriorversion\fP defines the latest version of the package whose upgrade
  125. should trigger the rename of the conffile (see the notes for
  126. \fBrm_conffile\fR above concerning the correct value). If \fIpriorversion\fP is
  127. empty or omitted, then the operation is tried on every upgrade (note: it's
  128. safer to give the version and have the operation tried only once).
  129. .P
  130. \fIpackage\fP is the package name. If empty or omitted, the
  131. DPKG_MAINTSCRIPT_PACKAGE environment variable (as set by dpkg) will be used.
  132. .P
  133. All the parameters of the maintainer scripts have to be forwarded to the
  134. program after "\-\-".
  135. .P
  136. Current implementation: the \fBpreinst\fP checks if the conffile has been
  137. modified, if yes it's left on place otherwise it's renamed to
  138. \fIoldconffile\fP\fB.dpkg\-remove\fP. On configuration, the \fBpostinst\fP
  139. removes \fIoldconffile\fP\fB.dpkg\-remove\fP and renames \fIoldconffile\fP
  140. to \fInewconffile\fP if \fIoldconffile\fP is still available. On
  141. abort\-upgrade/abort\-install, the \fBpostrm\fP renames
  142. \fIoldconffile\fP\fB.dpkg\-remove\fP back to \fIoldconffile\fP if required.
  143. .
  144. .SH INTEGRATION IN PACKAGES
  145. .P
  146. Given that \fBdpkg\-maintscript\-helper\fP is used in the \fBpreinst\fP,
  147. using it unconditionally requires a pre-dependency to ensure that the
  148. required version of dpkg has been unpacked before. The required version
  149. depends on the command used, for \fBrm_conffile\fP and \fBmv_conffile\fP
  150. it is 1.15.7.2:
  151. .P
  152. \fBPre\-Depends:\fP dpkg (>= 1.15.7.2)
  153. .P
  154. But in many cases the operation done by the program is not critical for
  155. the package, and instead of using a pre-dependency we can call the
  156. program only if we know that the required command is supported by
  157. the currently installed dpkg:
  158. .P
  159. if dpkg\-maintscript\-helper supports \fIcommand\fP; then
  160. dpkg\-maintscript\-helper \fIcommand\fP ...
  161. fi