dpkg-maintscript-helper.1 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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-05-04" "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 [\fIprior-version\fP [\fIpackage\fP]]
  29. .P
  30. \fBmv_conffile\fP \fIold-conffile\fP \fInew-conffile\fP [\fIprior-version\fP [\fIpackage\fP]]
  31. .P
  32. \fBsymlink_to_dir\fP \fIpathname\fP \fIold-target\fP [\fIprior-version\fP [\fIpackage\fP]]
  33. .P
  34. \fBdir_to_symlink\fP \fIpathname\fP \fInew-target\fP [\fIprior-version\fP [\fIpackage\fP]]
  35. .
  36. .SH DESCRIPTION
  37. .P
  38. This program is designed to be run within maintainer scripts to achieve
  39. some tasks that \fBdpkg\fP can't (yet) handle natively either because of
  40. design decisions or due to current limitations.
  41. .P
  42. Many of those tasks require coordinated actions from several maintainer
  43. scripts (\fBpreinst\fP, \fBpostinst\fP, \fBprerm\fP, \fBpostrm\fP). To
  44. avoid mistakes the same call simply needs to be put in all scripts and the
  45. program will automatically adapt its behaviour based on the environment
  46. variable \fBDPKG_MAINTSCRIPT_NAME\fP and on the maintainer scripts arguments
  47. that you have to forward after a double hyphen.
  48. .
  49. .SH COMMON PARAMETERS
  50. .TP
  51. .I prior-version
  52. Defines the latest version of the package whose upgrade should trigger the
  53. operation. It is important to calculate \fIprior-version\fP correctly so
  54. that the operations are correctly performed even if the user rebuilt the
  55. package with a local version. If \fIprior-version\fP is empty or omitted,
  56. then the operation is tried on every upgrade (note: it's safer to give
  57. the version and have the operation tried only once).
  58. For example, for a conffile removed in version \fB2.0\-1\fP of a package,
  59. \fIprior-version\fP should be set to \fB2.0\-1~\fP. This will cause the
  60. conffile to be removed even if the user rebuilt the previous version
  61. \fB1.0\-1\fP as \fB1.0\-1local1\fP.
  62. If the conffile has not been shipped for several versions, and you are
  63. now modifying the maintainer scripts to clean up the obsolete file,
  64. \fIprior-version\fP should be based on the version of the package that
  65. you are now preparing, not the first version of the package that lacked
  66. the conffile.
  67. .TP
  68. .I package
  69. The package name. When the package is "Multi-Arch: same", this parameter
  70. must include the architecture qualifier. If empty or omitted, the
  71. \fBDPKG_MAINTSCRIPT_PACKAGE\fP environment variable (as set by
  72. \fBdpkg\fP) will be used.
  73. .TP
  74. .B \-\-
  75. All the parameters of the maintainer scripts have to be forwarded to the
  76. program after \fB\-\-\fP.
  77. .SH CONFFILE RELATED TASKS
  78. .P
  79. When upgrading a package, \fBdpkg\fP will not automatically remove a conffile
  80. (a configuration file for which \fBdpkg\fP should preserve user changes) if
  81. it is not present in the newer version. There are two principal reasons for
  82. this; the first is that the conffile could've been dropped by accident and
  83. the next version could restore it, users wouldn't want their changes
  84. thrown away. The second is to allow packages to transition files from a
  85. dpkg\-maintained conffile to a file maintained by the package's maintainer
  86. scripts, usually with a tool like debconf or ucf.
  87. .P
  88. This means that if a package is intended to rename or remove a conffile,
  89. it must explicitly do so and \fBdpkg\-maintscript\-helper\fP can be used
  90. to implement graceful deletion and moving of conffiles within maintainer
  91. scripts.
  92. .
  93. .SS Removing a conffile
  94. .P
  95. If a conffile is completely removed, it should be removed from disk,
  96. unless the user has modified it. If there are local modifications, they
  97. should be preserved. If the package upgrades aborts, the newly obsolete
  98. conffile should not disappear.
  99. .P
  100. All of this is implemented by putting the following shell snippet in the
  101. \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer scripts:
  102. .P
  103. dpkg\-maintscript\-helper rm_conffile \\
  104. \fIconffile\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
  105. .P
  106. \fIconffile\fP is the filename of the conffile to remove.
  107. .P
  108. Current implementation: in the \fBpreinst\fP, it checks if the conffile
  109. was modified and renames it either to \fIconffile\fP\fB.dpkg\-remove\fP (if not
  110. modified) or to \fIconffile\fP\fB.dpkg\-backup\fP (if modified). In the
  111. \fBpostinst\fP, the latter file is renamed to \fIconffile\fP\fB.dpkg\-bak\fP
  112. and kept for reference as it contains user modifications but the former will
  113. be removed. If the package upgrade aborts, the \fBpostrm\fP reinstalls the
  114. original conffile. During purge, the \fBpostrm\fP will also delete the
  115. \fB.dpkg\-bak\fP file kept up to now.
  116. .
  117. .SS Renaming a conffile
  118. .P
  119. If a conffile is moved from one location to another, you need to make sure
  120. you move across any changes the user has made. This may seem a simple
  121. change to the \fBpreinst\fP script at first, however that will result in
  122. the user being prompted by \fBdpkg\fP to approve the conffile edits even
  123. though they are not responsible of them.
  124. .P
  125. Graceful renaming can be implemented by putting the following shell
  126. snippet in the \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer
  127. scripts:
  128. .P
  129. dpkg\-maintscript\-helper mv_conffile \\
  130. \fIold-conffile\fP \fInew-conffile\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
  131. .P
  132. \fIold-conffile\fP and \fInew-conffile\fP are the old and new name of the
  133. conffile to rename.
  134. .P
  135. Current implementation: the \fBpreinst\fP checks if the conffile has been
  136. modified, if yes it's left on place otherwise it's renamed to
  137. \fIold-conffile\fP\fB.dpkg\-remove\fP. On configuration, the \fBpostinst\fP
  138. removes \fIold-conffile\fP\fB.dpkg\-remove\fP and renames \fIold-conffile\fP
  139. to \fInew-conffile\fP if \fIold-conffile\fP is still available. On
  140. abort\-upgrade/abort\-install, the \fBpostrm\fP renames
  141. \fIold-conffile\fP\fB.dpkg\-remove\fP back to \fIold-conffile\fP if required.
  142. .
  143. .SH SYMLINK AND DIRECTORY SWITCHES
  144. .
  145. When upgrading a package, \fBdpkg\fP will not automatically switch a symlink
  146. to a directory or vice-versa.
  147. .
  148. .SS Switching a symlink to directory
  149. .
  150. If a symlink is switched to a real directory, you need to make sure
  151. before unpacking that the symlink is removed. This may seem a simple
  152. change to the \fBpreinst\fP script at first, however that will result
  153. in some problems in case of admin local customization of the symlink
  154. or when downgrading the package.
  155. .P
  156. Graceful renaming can be implemented by putting the following shell
  157. snippet in the \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer
  158. scripts:
  159. .P
  160. dpkg\-maintscript\-helper symlink_to_dir \\
  161. \fIpathname\fP \fIold-target\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
  162. .P
  163. \fIpathname\fP is the name of the old symlink (the path will be a
  164. directory at the end of the installation) and \fIold-target\fP the
  165. target of the former symlink at \fIpathname\fP.
  166. .P
  167. Current implementation: the \fBpreinst\fP checks if the symlink exists
  168. and points to \fIold-target\fP, if not then it's left in place, otherwise
  169. it's renamed to \fIpathname\fP\fB.dpkg\-backup\fP. On configuration,
  170. the \fBpostinst\fP removes \fIpathname\fP\fB.dpkg\-backup\fP if
  171. \fIpathname\fP\fB.dpkg\-backup\fP is still a symlink. On
  172. abort\-upgrade/abort\-install, the \fBpostrm\fP renames
  173. \fIpathname\fP\fB.dpkg\-backup\fP back to \fIpathname\fP if required.
  174. .
  175. .SS Switching a directory to symlink
  176. .
  177. If a real directory is switched to a symlink, you need to make sure
  178. before unpacking that the directory is removed. This may seem a simple
  179. change to the \fBpreinst\fP script at first, however that will result
  180. in some problems in case the directory contains conffiles, pathnames
  181. owned by other packages, locally created pathnames, or when downgrading
  182. the package.
  183. .P
  184. Graceful switching can be implemented by putting the following shell
  185. snippet in the \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer
  186. scripts:
  187. .P
  188. dpkg\-maintscript\-helper dir_to_symlink \\
  189. \fIpathname\fP \fInew-target\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
  190. .P
  191. \fIpathname\fP is the name of the of the old directory (the path will be a
  192. symlink at the end of the installation) and \fInew-target\fP is the target
  193. of the new symlink at \fIpathname\fP.
  194. .P
  195. Current implementation: the \fBpreinst\fP checks if the directory
  196. exists, does not contain conffiles, pathnames owned by other packages,
  197. or locally created pathnames, if not then it's left in place, otherwise
  198. it's renamed to \fIpathname\fP\fB.dpkg\-backup\fP. On configuration,
  199. the \fBpostinst\fP removes \fIpathname\fP\fB.dpkg\-backup\fP if
  200. \fIpathname\fP\fB.dpkg\-backup\fP is still a directory. On
  201. abort\-upgrade/abort\-install, the \fBpostrm\fP renames
  202. \fIpathname\fP\fB.dpkg\-backup\fP back to \fIpathname\fP if required.
  203. .
  204. .SH INTEGRATION IN PACKAGES
  205. .P
  206. Given that \fBdpkg\-maintscript\-helper\fP is used in the \fBpreinst\fP,
  207. using it unconditionally requires a pre-dependency to ensure that the
  208. required version of \fBdpkg\fP has been unpacked before. The required version
  209. depends on the command used, for \fBrm_conffile\fP and \fBmv_conffile\fP
  210. it is 1.15.7.2, for \fBsymlink_to_dir\fP and \fBdir_to_symlink\fP
  211. it is 1.17.2:
  212. .P
  213. \fBPre\-Depends:\fP dpkg (>= 1.17.2)
  214. .P
  215. But in many cases the operation done by the program is not critical for
  216. the package, and instead of using a pre-dependency we can call the
  217. program only if we know that the required command is supported by
  218. the currently installed \fBdpkg\fP:
  219. .P
  220. if dpkg\-maintscript\-helper supports \fIcommand\fP; then
  221. dpkg\-maintscript\-helper \fIcommand\fP ...
  222. fi