1 .\" dpkg manual page - dpkg-maintscript-helper(1)
3 .\" Copyright © 2010-2012 Raphaël Hertzog <hertzog@debian.org>
4 .\" Copyright © 2011-2015 Guillem Jover <guillem@debian.org>
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.
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.
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/>.
19 .TH dpkg\-maintscript\-helper 1 "%RELEASE_DATE%" "%VERSION%" "dpkg suite"
22 dpkg\-maintscript\-helper \- works around known dpkg limitations in maintainer scripts
25 .B dpkg\-maintscript\-helper
26 .IR command " [" parameter "...] \fB\-\-\fP " maint-script-parameter ...
28 .SH COMMANDS AND PARAMETERS
30 \fBsupports\fP \fIcommand\fP
32 \fBrm_conffile\fP \fIconffile\fP [\fIprior-version\fP [\fIpackage\fP]]
34 \fBmv_conffile\fP \fIold-conffile\fP \fInew-conffile\fP [\fIprior-version\fP [\fIpackage\fP]]
36 \fBsymlink_to_dir\fP \fIpathname\fP \fIold-target\fP [\fIprior-version\fP [\fIpackage\fP]]
38 \fBdir_to_symlink\fP \fIpathname\fP \fInew-target\fP [\fIprior-version\fP [\fIpackage\fP]]
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.
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.
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).
63 If the conffile has not been shipped for several versions, and you are
64 now modifying the maintainer scripts to clean up the obsolete file,
65 \fIprior-version\fP should be based on the version of the package that
66 you are now preparing, not the first version of the package that lacked
67 the conffile. This applies to all other actions in the same way.
69 For example, for a conffile removed in version \fB2.0\-1\fP of a package,
70 \fIprior-version\fP should be set to \fB2.0\-1~\fP. This will cause the
71 conffile to be removed even if the user rebuilt the previous version
72 \fB1.0\-1\fP as \fB1.0\-1local1\fP. Or a package switching a path from
73 a symlink (shipped in version \fB1.0\-1\fP) to a directory (shipped in
74 version \fB2.0\-1\fP), but only performing the actual switch in the
75 maintainer scripts in version \fB3.0\-1\fP, should set \fIprior-version\fP
79 The package name. When the package is “Multi\-Arch: same” this parameter
80 must include the architecture qualifier, otherwise it should \fBnot\fP
81 usually include the architecture qualifier (as it would disallow
82 cross-grades, or switching from being architecture specific to
83 architecture \fBall\fP or vice versa).
84 If the parameter is empty or omitted, the \fBDPKG_MAINTSCRIPT_PACKAGE\fP
85 and \fBDPKG_MAINTSCRIPT_ARCH\fP environment variables (as set by \fBdpkg\fP)
86 will be used to generate an arch-qualified package name.
89 All the parameters of the maintainer scripts have to be forwarded to the
90 program after \fB\-\-\fP.
91 .SH CONFFILE RELATED TASKS
93 When upgrading a package, \fBdpkg\fP will not automatically remove a conffile
94 (a configuration file for which \fBdpkg\fP should preserve user changes) if
95 it is not present in the newer version. There are two principal reasons for
96 this; the first is that the conffile could've been dropped by accident and
97 the next version could restore it, users wouldn't want their changes
98 thrown away. The second is to allow packages to transition files from a
99 dpkg\-maintained conffile to a file maintained by the package's maintainer
100 scripts, usually with a tool like debconf or ucf.
102 This means that if a package is intended to rename or remove a conffile,
103 it must explicitly do so and \fBdpkg\-maintscript\-helper\fP can be used
104 to implement graceful deletion and moving of conffiles within maintainer
107 .SS Removing a conffile
109 If a conffile is completely removed, it should be removed from disk,
110 unless the user has modified it. If there are local modifications, they
111 should be preserved. If the package upgrades aborts, the newly obsolete
112 conffile should not disappear.
114 All of this is implemented by putting the following shell snippet in the
115 \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer scripts:
117 dpkg\-maintscript\-helper rm_conffile \\
118 \fIconffile\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
120 \fIconffile\fP is the filename of the conffile to remove.
122 Current implementation: in the \fBpreinst\fP, it checks if the conffile
123 was modified and renames it either to \fIconffile\fP\fB.dpkg\-remove\fP (if not
124 modified) or to \fIconffile\fP\fB.dpkg\-backup\fP (if modified). In the
125 \fBpostinst\fP, the latter file is renamed to \fIconffile\fP\fB.dpkg\-bak\fP
126 and kept for reference as it contains user modifications but the former will
127 be removed. If the package upgrade aborts, the \fBpostrm\fP reinstalls the
128 original conffile. During purge, the \fBpostrm\fP will also delete the
129 \fB.dpkg\-bak\fP file kept up to now.
131 .SS Renaming a conffile
133 If a conffile is moved from one location to another, you need to make sure
134 you move across any changes the user has made. This may seem a simple
135 change to the \fBpreinst\fP script at first, however that will result in
136 the user being prompted by \fBdpkg\fP to approve the conffile edits even
137 though they are not responsible of them.
139 Graceful renaming can be implemented by putting the following shell
140 snippet in the \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer
143 dpkg\-maintscript\-helper mv_conffile \\
144 \fIold-conffile\fP \fInew-conffile\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
146 \fIold-conffile\fP and \fInew-conffile\fP are the old and new name of the
149 Current implementation: the \fBpreinst\fP checks if the conffile has been
150 modified, if yes it's left on place otherwise it's renamed to
151 \fIold-conffile\fP\fB.dpkg\-remove\fP. On configuration, the \fBpostinst\fP
152 removes \fIold-conffile\fP\fB.dpkg\-remove\fP and renames \fIold-conffile\fP
153 to \fInew-conffile\fP if \fIold-conffile\fP is still available. On
154 abort\-upgrade/abort\-install, the \fBpostrm\fP renames
155 \fIold-conffile\fP\fB.dpkg\-remove\fP back to \fIold-conffile\fP if required.
157 .SH SYMLINK AND DIRECTORY SWITCHES
159 When upgrading a package, \fBdpkg\fP will not automatically switch a symlink
160 to a directory or vice-versa. Downgrades are not supported and the path
163 .SS Switching a symlink to directory
165 If a symlink is switched to a real directory, you need to make sure
166 before unpacking that the symlink is removed. This may seem a simple
167 change to the \fBpreinst\fP script at first, however that will result
168 in some problems in case of admin local customization of the symlink
169 or when downgrading the package.
171 Graceful renaming can be implemented by putting the following shell
172 snippet in the \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer
175 dpkg\-maintscript\-helper symlink_to_dir \\
176 \fIpathname\fP \fIold-target\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
178 \fIpathname\fP is the absolute name of the old symlink (the path will be a
179 directory at the end of the installation) and \fIold-target\fP is
180 the target name of the former symlink at \fIpathname\fP. It can either be
181 absolute or relative to the directory containing \fIpathname\fP.
183 Current implementation: the \fBpreinst\fP checks if the symlink exists
184 and points to \fIold-target\fP, if not then it's left in place, otherwise
185 it's renamed to \fIpathname\fP\fB.dpkg\-backup\fP. On configuration,
186 the \fBpostinst\fP removes \fIpathname\fP\fB.dpkg\-backup\fP if
187 \fIpathname\fP\fB.dpkg\-backup\fP is still a symlink. On
188 abort\-upgrade/abort\-install, the \fBpostrm\fP renames
189 \fIpathname\fP\fB.dpkg\-backup\fP back to \fIpathname\fP if required.
191 .SS Switching a directory to symlink
193 If a real directory is switched to a symlink, you need to make sure
194 before unpacking that the directory is removed. This may seem a simple
195 change to the \fBpreinst\fP script at first, however that will result
196 in some problems in case the directory contains conffiles, pathnames
197 owned by other packages, locally created pathnames, or when downgrading
200 Graceful switching can be implemented by putting the following shell
201 snippet in the \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer
204 dpkg\-maintscript\-helper dir_to_symlink \\
205 \fIpathname\fP \fInew-target\fP \fIprior-version\fP \fIpackage\fP \-\- "$@"
207 \fIpathname\fP is the absolute name of the old directory (the path
208 will be a symlink at the end of the installation) and \fInew-target\fP is
209 the target of the new symlink at \fIpathname\fP. It can either be absolute
210 or relative to the directory containing \fIpathname\fP.
212 Current implementation: the \fBpreinst\fP checks if the directory
213 exists, does not contain conffiles, pathnames owned by other packages,
214 or locally created pathnames, if not then it's left in place, otherwise
215 it's renamed to \fIpathname\fP\fB.dpkg\-backup\fP, and an empty staging
216 directory named \fIpathname\fP is created, marked with a file so that
217 dpkg can track it. On configuration, the \fBpostinst\fP finishes the
218 switch if \fIpathname\fP\fB.dpkg\-backup\fP is still a directory and
219 \fIpathname\fP is the staging directory; it removes the staging directory
220 mark file, moves the newly created files inside the staging directory
221 to the symlink target \fInew-target\fP/, replaces the now empty staging
222 directory \fIpathname\fP with a symlink to \fInew-target\fP, and
223 removes \fIpathname\fP\fB.dpkg\-backup\fP. On
224 abort\-upgrade/abort\-install, the \fBpostrm\fP renames
225 \fIpathname\fP\fB.dpkg\-backup\fP back to \fIpathname\fP if required.
227 .SH INTEGRATION IN PACKAGES
229 When using a packaging helper, please check if it has native
230 \fBdpkg-maintscript-helper\fP integration, which might make your life
231 easier. See for example \fBdh_installdeb\fP(1).
233 Given that \fBdpkg\-maintscript\-helper\fP is used in the \fBpreinst\fP,
234 using it unconditionally requires a pre-dependency to ensure that the
235 required version of \fBdpkg\fP has been unpacked before. The required version
236 depends on the command used, for \fBrm_conffile\fP and \fBmv_conffile\fP
237 it is 1.15.7.2, for \fBsymlink_to_dir\fP and \fBdir_to_symlink\fP
240 \fBPre\-Depends:\fP dpkg (>= 1.17.14)
242 But in many cases the operation done by the program is not critical for
243 the package, and instead of using a pre-dependency we can call the
244 program only if we know that the required command is supported by
245 the currently installed \fBdpkg\fP:
247 if dpkg\-maintscript\-helper supports \fIcommand\fP; then
248 dpkg\-maintscript\-helper \fIcommand\fP ...
251 The command \fBsupports\fP will return 0 on success, 1 otherwise. The
252 \fBsupports\fP command will check if the environment variables as set
253 by dpkg and required by the script are present, and will consider it a
254 failure in case the environment is not sufficient.
257 .BR dh_installdeb (1).