dpkg-maintscript-helper.1 11 KB

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