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/>.
23 dpkg-maintscript-helper - works around known dpkg limitations in maintainer scripts
27 B<dpkg-maintscript-helper>
28 I<command> [I<parameter>...] B<--> I<maint-script-parameter>...
30 =head1 COMMANDS AND PARAMETERS
34 =item B<supports> I<command>
36 =item B<rm_conffile> I<conffile> [I<prior-version> [I<package>]]
38 =item B<mv_conffile> I<old-conffile> I<new-conffile> [I<prior-version> [I<package>]]
40 =item B<symlink_to_dir> I<pathname> I<old-target> [I<prior-version> [I<package>]]
42 =item B<dir_to_symlink> I<pathname> I<new-target> [I<prior-version> [I<package>]]
48 This program is designed to be run within maintainer scripts to achieve
49 some tasks that B<dpkg> can't (yet) handle natively either because of
50 design decisions or due to current limitations.
52 Many of those tasks require coordinated actions from several maintainer
53 scripts (B<preinst>, B<postinst>, B<prerm>, B<postrm>).
55 avoid mistakes the same call simply needs to be put in all scripts and the
56 program will automatically adapt its behavior based on the environment
57 variable B<DPKG_MAINTSCRIPT_NAME> and on the maintainer scripts arguments
58 that you have to forward after a double hyphen.
60 This program was introduced in dpkg 1.15.7.
62 =head1 COMMON PARAMETERS
66 =item I<prior-version>
68 Defines the latest version of the package whose upgrade should trigger the
70 It is important to calculate I<prior-version> correctly so
71 that the operations are correctly performed even if the user rebuilt the
72 package with a local version.
73 If I<prior-version> is empty or omitted,
74 then the operation is tried on every upgrade (note: it's safer to give
75 the version and have the operation tried only once).
77 If the conffile has not been shipped for several versions, and you are
78 now modifying the maintainer scripts to clean up the obsolete file,
79 I<prior-version> should be based on the version of the package that
80 you are now preparing, not the first version of the package that lacked
82 This applies to all other actions in the same way.
84 For example, for a conffile removed in version B<2.0-1> of a package,
85 I<prior-version> should be set to B<2.0-1~>.
87 conffile to be removed even if the user rebuilt the previous version
88 B<1.0-1> as B<1.0-1local1>.
89 Or a package switching a path from
90 a symlink (shipped in version B<1.0-1>) to a directory (shipped in
91 version B<2.0-1>), but only performing the actual switch in the
92 maintainer scripts in version B<3.0-1>, should set I<prior-version>
97 The package name owning the pathname(s).
98 When the package is “Multi-Arch: same” this parameter
99 must include the architecture qualifier, otherwise it should B<not>
100 usually include the architecture qualifier (as it would disallow
101 cross-grades, or switching from being architecture specific to
102 architecture B<all> or vice versa).
103 If the parameter is empty or omitted, the B<DPKG_MAINTSCRIPT_PACKAGE>
104 and B<DPKG_MAINTSCRIPT_ARCH> environment variables (as set by B<dpkg>
105 when running the maintainer scripts) will be used to generate an
106 arch-qualified package name.
110 All the parameters of the maintainer scripts have to be forwarded to the
115 =head1 CONFFILE RELATED TASKS
117 When upgrading a package, B<dpkg> will not automatically remove a conffile
118 (a configuration file for which B<dpkg> should preserve user changes) if
119 it is not present in the newer version.
120 There are two principal reasons for
121 this; the first is that the conffile could've been dropped by accident and
122 the next version could restore it, users wouldn't want their changes
124 The second is to allow packages to transition files from a
125 dpkg-maintained conffile to a file maintained by the package's maintainer
126 scripts, usually with a tool like debconf or ucf.
128 This means that if a package is intended to rename or remove a conffile,
129 it must explicitly do so and B<dpkg-maintscript-helper> can be used
130 to implement graceful deletion and moving of conffiles within maintainer
133 =head2 Removing a conffile
135 B<Note>: This can be replaced in most cases by the C<remove-on-upgrade>
136 flag in F<DEBIAN/conffiles> (since dpkg 1.20.6), see L<deb-conffiles(5)>.
138 If a conffile is completely removed, it should be removed from disk,
139 unless the user has modified it.
140 If there are local modifications, they should be preserved.
141 If the package upgrade aborts, the newly obsolete
142 conffile should not disappear.
144 All of this is implemented by putting the following shell snippet in the
145 B<preinst>, B<postinst> and B<postrm> maintainer scripts:
150 dpkg-maintscript-helper rm_conffile \
151 I<conffile> I<prior-version> I<package> -- "$@"
155 I<conffile> is the filename of the conffile to remove.
157 Current implementation: in the B<preinst>, it checks if the conffile
158 was modified and renames it either to I<conffile>B<.dpkg-remove> (if not
159 modified) or to I<conffile>B<.dpkg-backup> (if modified).
161 B<postinst>, the latter file is renamed to I<conffile>B<.dpkg-bak>
162 and kept for reference as it contains user modifications but the former will
164 If the package upgrade aborts, the B<postrm> reinstalls the original conffile.
165 During purge, the B<postrm> will also delete the
166 B<.dpkg-bak> file kept up to now.
168 =head2 Renaming a conffile
170 If a conffile is moved from one location to another, you need to make sure
171 you move across any changes the user has made.
172 This may seem a simple
173 change to the B<preinst> script at first, however that will result in
174 the user being prompted by B<dpkg> to approve the conffile edits even
175 though they are not responsible of them.
177 Graceful renaming can be implemented by putting the following shell
178 snippet in the B<preinst>, B<postinst> and B<postrm> maintainer
184 dpkg-maintscript-helper mv_conffile \
185 I<old-conffile> I<new-conffile> I<prior-version> I<package> -- "$@"
189 I<old-conffile> and I<new-conffile> are the old and new name of the
192 Current implementation: the B<preinst> checks if the conffile has been
193 modified, if yes it's left on place otherwise it's renamed to
194 I<old-conffile>B<.dpkg-remove>.
195 On configuration, the B<postinst>
196 removes I<old-conffile>B<.dpkg-remove> and renames I<old-conffile>
197 to I<new-conffile> if I<old-conffile> is still available.
199 abort-upgrade/abort-install, the B<postrm> renames
200 I<old-conffile>B<.dpkg-remove> back to I<old-conffile> if required.
202 =head1 SYMLINK AND DIRECTORY SWITCHES
204 When upgrading a package, B<dpkg> will not automatically switch a symlink
205 to a directory or vice-versa.
206 Downgrades are not supported and the path
209 B<Note>: The symlinks and directories created during these switches need to
210 be shipped in the new packages, or B<dpkg> will not be able to remove them
213 =head2 Switching a symlink to directory
215 If a symlink is switched to a real directory, you need to make sure
216 before unpacking that the symlink is removed.
217 This may seem a simple
218 change to the B<preinst> script at first, however that will result
219 in some problems in case of admin local customization of the symlink
220 or when downgrading the package.
222 Graceful renaming can be implemented by putting the following shell
223 snippet in the B<preinst>, B<postinst> and B<postrm> maintainer
229 dpkg-maintscript-helper symlink_to_dir \
230 I<pathname> I<old-target> I<prior-version> I<package> -- "$@"
234 I<pathname> is the absolute name of the old symlink (the path will be a
235 directory at the end of the installation) and I<old-target> is
236 the target name of the former symlink at I<pathname>.
238 absolute or relative to the directory containing I<pathname>.
240 Current implementation: the B<preinst> checks if the symlink exists
241 and points to I<old-target>, if not then it's left in place, otherwise
242 it's renamed to I<pathname>B<.dpkg-backup>.
244 the B<postinst> removes I<pathname>B<.dpkg-backup> if
245 I<pathname>B<.dpkg-backup> is still a symlink.
247 abort-upgrade/abort-install, the B<postrm> renames
248 I<pathname>B<.dpkg-backup> back to I<pathname> if required.
250 =head2 Switching a directory to symlink
252 If a real directory is switched to a symlink, you need to make sure
253 before unpacking that the directory is removed.
254 This may seem a simple
255 change to the B<preinst> script at first, however that will result
256 in some problems in case the directory contains conffiles, pathnames
257 owned by other packages, locally created pathnames, or when downgrading
260 Graceful switching can be implemented by putting the following shell
261 snippet in the B<preinst>, B<postinst> and B<postrm> maintainer
267 dpkg-maintscript-helper dir_to_symlink \
268 I<pathname> I<new-target> I<prior-version> I<package> -- "$@"
272 I<pathname> is the absolute name of the old directory (the path
273 will be a symlink at the end of the installation) and I<new-target> is
274 the target of the new symlink at I<pathname>.
275 It can either be absolute
276 or relative to the directory containing I<pathname>.
278 Current implementation: the B<preinst> checks if the directory
279 exists, does not contain conffiles, pathnames owned by other packages,
280 or locally created pathnames, if not then it's left in place, otherwise
281 it's renamed to I<pathname>B<.dpkg-backup>, and an empty staging
282 directory named I<pathname> is created, marked with a file so that
284 On configuration, the B<postinst> finishes the
285 switch if I<pathname>B<.dpkg-backup> is still a directory and
286 I<pathname> is the staging directory; it removes the staging directory
287 mark file, moves the newly created files inside the staging directory
288 to the symlink target I<new-target>/, replaces the now empty staging
289 directory I<pathname> with a symlink to I<new-target>, and
290 removes I<pathname>B<.dpkg-backup>.
292 abort-upgrade/abort-install, the B<postrm> renames
293 I<pathname>B<.dpkg-backup> back to I<pathname> if required.
295 =head1 INTEGRATION IN PACKAGES
297 When using a packaging helper, please check if it has native
298 B<dpkg-maintscript-helper> integration, which might make your life
300 See for example L<dh_installdeb(1)>.
302 Given that B<dpkg-maintscript-helper> is used in the B<preinst>,
303 using it unconditionally requires a pre-dependency to ensure that the
304 required version of B<dpkg> has been unpacked before.
306 depends on the command used, for B<rm_conffile> and B<mv_conffile>
307 it is 1.15.7.2, for B<symlink_to_dir> and B<dir_to_symlink>
312 Pre-Depends: dpkg (>= 1.17.14)
316 But in many cases the operation done by the program is not critical for
317 the package, and instead of using a pre-dependency we can call the
318 program only if we know that the required command is supported by
319 the currently installed B<dpkg>:
324 if dpkg-maintscript-helper supports I<command>; then
325 dpkg-maintscript-helper I<command> ...
330 The command B<supports> will return 0 on success, 1 otherwise.
332 B<supports> command will check if the environment variables as set
333 by dpkg and required by the script are present, and will consider it a
334 failure in case the environment is not sufficient.
342 If set, it will be used as the filesystem root directory.
344 =item B<DPKG_ADMINDIR>
346 If set, it will be used as the B<dpkg> data directory.
350 Sets the color mode (since dpkg 1.19.1).
351 The currently accepted values are: B<auto> (default), B<always> and