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