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