dpkg-maintscript-helper.1 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 <https://www.gnu.org/licenses/>.
  17. .
  18. .TH dpkg\-maintscript\-helper 1 "2014-04-01" "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. If the conffile has not been shipped for several versions, and you are
  59. now modifying the maintainer scripts to clean up the obsolete file,
  60. \fIprior-version\fP should be based on the version of the package that
  61. you are now preparing, not the first version of the package that lacked
  62. the conffile. This applies to all other actions in the same way.
  63. For example, for a conffile removed in version \fB2.0\-1\fP of a package,
  64. \fIprior-version\fP should be set to \fB2.0\-1~\fP. This will cause the
  65. conffile to be removed even if the user rebuilt the previous version
  66. \fB1.0\-1\fP as \fB1.0\-1local1\fP. Or a package switching a path from
  67. a symlink (shipped in version \fB1.0\-1\fP) to a directory (shipped in
  68. version \fB2.0\-1\fP), but only performing the actual switch in the
  69. maintainer scripts in version \fB3.0\-1\fP, should set \fIprior-version\fP
  70. to \fB3.0\-1~\fP.
  71. .TP
  72. .I package
  73. The package name. When the package is "Multi-Arch: same", this parameter
  74. must include the architecture qualifier. If empty or omitted, the
  75. \fBDPKG_MAINTSCRIPT_PACKAGE\fP environment variable (as set by
  76. \fBdpkg\fP) will be used.
  77. .TP
  78. .B \-\-
  79. All the parameters of the maintainer scripts have to be forwarded to the
  80. program after \fB\-\-\fP.
  81. .SH CONFFILE RELATED TASKS
  82. .P
  83. When upgrading a package, \fBdpkg\fP will not automatically remove a conffile
  84. (a configuration file for which \fBdpkg\fP should preserve user changes) if
  85. it is not present in the newer version. There are two principal reasons for
  86. this; the first is that the conffile could've been dropped by accident and
  87. the next version could restore it, users wouldn't want their changes
  88. thrown away. The second is to allow packages to transition files from a
  89. dpkg\-maintained conffile to a file maintained by the package's maintainer
  90. scripts, usually with a tool like debconf or ucf.
  91. .P
  92. This means that if a package is intended to rename or remove a conffile,
  93. it must explicitly do so and \fBdpkg\-maintscript\-helper\fP can be used
  94. to implement graceful deletion and moving of conffiles within maintainer
  95. scripts.
  96. .
  97. .SS Removing a conffile
  98. .P
  99. If a conffile is completely removed, it should be removed from disk,
  100. unless the user has modified it. If there are local modifications, they
  101. should be preserved. If the package upgrades aborts, the newly obsolete
  102. conffile should not disappear.
  103. .P
  104. All of this is implemented by putting the following shell snippet in the
  105. \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer scripts:
  106. .P
  107. dpkg\-maintscript\-helper rm_conffile \\
  108. \fIconffile\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
  109. .P
  110. \fIconffile\fP is the filename of the conffile to remove.
  111. .P
  112. Current implementation: in the \fBpreinst\fP, it checks if the conffile
  113. was modified and renames it either to \fIconffile\fP\fB.dpkg\-remove\fP (if not
  114. modified) or to \fIconffile\fP\fB.dpkg\-backup\fP (if modified). In the
  115. \fBpostinst\fP, the latter file is renamed to \fIconffile\fP\fB.dpkg\-bak\fP
  116. and kept for reference as it contains user modifications but the former will
  117. be removed. If the package upgrade aborts, the \fBpostrm\fP reinstalls the
  118. original conffile. During purge, the \fBpostrm\fP will also delete the
  119. \fB.dpkg\-bak\fP file kept up to now.
  120. .
  121. .SS Renaming a conffile
  122. .P
  123. If a conffile is moved from one location to another, you need to make sure
  124. you move across any changes the user has made. This may seem a simple
  125. change to the \fBpreinst\fP script at first, however that will result in
  126. the user being prompted by \fBdpkg\fP to approve the conffile edits even
  127. though they are not responsible of them.
  128. .P
  129. Graceful renaming can be implemented by putting the following shell
  130. snippet in the \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer
  131. scripts:
  132. .P
  133. dpkg\-maintscript\-helper mv_conffile \\
  134. \fIold-conffile\fP \fInew-conffile\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
  135. .P
  136. \fIold-conffile\fP and \fInew-conffile\fP are the old and new name of the
  137. conffile to rename.
  138. .P
  139. Current implementation: the \fBpreinst\fP checks if the conffile has been
  140. modified, if yes it's left on place otherwise it's renamed to
  141. \fIold-conffile\fP\fB.dpkg\-remove\fP. On configuration, the \fBpostinst\fP
  142. removes \fIold-conffile\fP\fB.dpkg\-remove\fP and renames \fIold-conffile\fP
  143. to \fInew-conffile\fP if \fIold-conffile\fP is still available. On
  144. abort\-upgrade/abort\-install, the \fBpostrm\fP renames
  145. \fIold-conffile\fP\fB.dpkg\-remove\fP back to \fIold-conffile\fP if required.
  146. .
  147. .SH SYMLINK AND DIRECTORY SWITCHES
  148. .
  149. When upgrading a package, \fBdpkg\fP will not automatically switch a symlink
  150. to a directory or vice-versa. Downgrades are not suppoerted and the path
  151. will be left as is.
  152. .
  153. .SS Switching a symlink to directory
  154. .
  155. If a symlink is switched to a real directory, you need to make sure
  156. before unpacking that the symlink is removed. This may seem a simple
  157. change to the \fBpreinst\fP script at first, however that will result
  158. in some problems in case of admin local customization of the symlink
  159. or when downgrading the package.
  160. .P
  161. Graceful renaming can be implemented by putting the following shell
  162. snippet in the \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer
  163. scripts:
  164. .P
  165. dpkg\-maintscript\-helper symlink_to_dir \\
  166. \fIpathname\fP \fIold-target\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
  167. .P
  168. \fIpathname\fP is the name of the old symlink (the path will be a
  169. directory at the end of the installation) and \fIold-target\fP the
  170. target of the former symlink at \fIpathname\fP.
  171. .P
  172. Current implementation: the \fBpreinst\fP checks if the symlink exists
  173. and points to \fIold-target\fP, if not then it's left in place, otherwise
  174. it's renamed to \fIpathname\fP\fB.dpkg\-backup\fP. On configuration,
  175. the \fBpostinst\fP removes \fIpathname\fP\fB.dpkg\-backup\fP if
  176. \fIpathname\fP\fB.dpkg\-backup\fP is still a symlink. On
  177. abort\-upgrade/abort\-install, the \fBpostrm\fP renames
  178. \fIpathname\fP\fB.dpkg\-backup\fP back to \fIpathname\fP if required.
  179. .
  180. .SS Switching a directory to symlink
  181. .
  182. If a real directory is switched to a symlink, you need to make sure
  183. before unpacking that the directory is removed. This may seem a simple
  184. change to the \fBpreinst\fP script at first, however that will result
  185. in some problems in case the directory contains conffiles, pathnames
  186. owned by other packages, locally created pathnames, or when downgrading
  187. the package.
  188. .P
  189. Graceful switching can be implemented by putting the following shell
  190. snippet in the \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer
  191. scripts:
  192. .P
  193. dpkg\-maintscript\-helper dir_to_symlink \\
  194. \fIpathname\fP \fInew-target\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
  195. .P
  196. \fIpathname\fP is the name of the of the old directory (the path will be a
  197. symlink at the end of the installation) and \fInew-target\fP is the target
  198. of the new symlink at \fIpathname\fP.
  199. .P
  200. Current implementation: the \fBpreinst\fP checks if the directory
  201. exists, does not contain conffiles, pathnames owned by other packages,
  202. or locally created pathnames, if not then it's left in place, otherwise
  203. it's renamed to \fIpathname\fP\fB.dpkg\-backup\fP, and an empty staging
  204. directory named \fIpathname\fP is created, marked with a file so that
  205. dpkg can track it. On configuration, the \fBpostinst\fP finishes the
  206. switch if \fIpathname\fP\fB.dpkg\-backup\fP is still a directory and
  207. \fIpathname\fP is the staging directory; it removes the staging directory
  208. mark file, moves the newly created files inside the staging directory
  209. to the symlink target \fInew-target\fP/, replaces the now empty staging
  210. directory \fIpathname\fP with a symlink to \fInew-target\fP, and
  211. removes \fIpathname\fP\fB.dpkg\-backup\fP. On
  212. abort\-upgrade/abort\-install, the \fBpostrm\fP renames
  213. \fIpathname\fP\fB.dpkg\-backup\fP back to \fIpathname\fP if required.
  214. .
  215. .SH INTEGRATION IN PACKAGES
  216. .P
  217. Given that \fBdpkg\-maintscript\-helper\fP is used in the \fBpreinst\fP,
  218. using it unconditionally requires a pre-dependency to ensure that the
  219. required version of \fBdpkg\fP has been unpacked before. The required version
  220. depends on the command used, for \fBrm_conffile\fP and \fBmv_conffile\fP
  221. it is 1.15.7.2, for \fBsymlink_to_dir\fP and \fBdir_to_symlink\fP
  222. it is 1.17.5:
  223. .P
  224. \fBPre\-Depends:\fP dpkg (>= 1.17.5)
  225. .P
  226. But in many cases the operation done by the program is not critical for
  227. the package, and instead of using a pre-dependency we can call the
  228. program only if we know that the required command is supported by
  229. the currently installed \fBdpkg\fP:
  230. .P
  231. if dpkg\-maintscript\-helper supports \fIcommand\fP; then
  232. dpkg\-maintscript\-helper \fIcommand\fP ...
  233. fi