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