dpkg-maintscript-helper.1 12 KB

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