1dpkg-maintscript-helper(1)        dpkg suite        dpkg-maintscript-helper(1)
2
3
4

NAME

6       dpkg-maintscript-helper - works around known dpkg limitations in
7       maintainer scripts
8

SYNOPSIS

10       dpkg-maintscript-helper command [parameter...] -- maint-script-
11       parameter...
12

COMMANDS AND PARAMETERS

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

DESCRIPTION

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

COMMON PARAMETERS

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       Note: The symlinks and directories created during these switches need
144       to be shipped in the new packages, or dpkg will not be able to remove
145       them on purge.
146
147   Switching a symlink to directory
148       If a symlink is switched to a real directory, you need to make sure
149       before unpacking that the symlink is removed. This may seem a simple
150       change to the preinst script at first, however that will result in some
151       problems in case of admin local customization of the symlink or when
152       downgrading the package.
153
154       Graceful renaming can be implemented by putting the following shell
155       snippet in the preinst, postinst and postrm maintainer scripts:
156
157
158            dpkg-maintscript-helper symlink_to_dir \
159               pathname old-target prior-version package -- "$@"
160
161       pathname is the absolute name of the old symlink (the path will be a
162       directory at the end of the installation) and old-target is the target
163       name of the former symlink at pathname. It can either be absolute or
164       relative to the directory containing pathname.
165
166       Current implementation: the preinst checks if the symlink exists and
167       points to old-target, if not then it's left in place, otherwise it's
168       renamed to pathname.dpkg-backup. On configuration, the postinst removes
169       pathname.dpkg-backup if pathname.dpkg-backup is still a symlink. On
170       abort-upgrade/abort-install, the postrm renames pathname.dpkg-backup
171       back to pathname if required.
172
173   Switching a directory to symlink
174       If a real directory is switched to a symlink, you need to make sure
175       before unpacking that the directory is removed. This may seem a simple
176       change to the preinst script at first, however that will result in some
177       problems in case the directory contains conffiles, pathnames owned by
178       other packages, locally created pathnames, or when downgrading the
179       package.
180
181       Graceful switching can be implemented by putting the following shell
182       snippet in the preinst, postinst and postrm maintainer scripts:
183
184
185            dpkg-maintscript-helper dir_to_symlink \
186               pathname new-target prior-version package -- "$@"
187
188       pathname is the absolute name of the old directory (the path will be a
189       symlink at the end of the installation) and new-target is the target of
190       the new symlink at pathname. It can either be absolute or relative to
191       the directory containing pathname.
192
193       Current implementation: the preinst checks if the directory exists,
194       does not contain conffiles, pathnames owned by other packages, or
195       locally created pathnames, if not then it's left in place, otherwise
196       it's renamed to pathname.dpkg-backup, and an empty staging directory
197       named pathname is created, marked with a file so that dpkg can track
198       it. On configuration, the postinst finishes the switch if
199       pathname.dpkg-backup is still a directory and pathname is the staging
200       directory; it removes the staging directory mark file, moves the newly
201       created files inside the staging directory to the symlink target new-
202       target/, replaces the now empty staging directory pathname with a
203       symlink to new-target, and removes pathname.dpkg-backup. On
204       abort-upgrade/abort-install, the postrm renames pathname.dpkg-backup
205       back to pathname if required.
206

INTEGRATION IN PACKAGES

208       When using a packaging helper, please check if it has native dpkg-
209       maintscript-helper integration, which might make your life easier. See
210       for example dh_installdeb(1).
211
212       Given that dpkg-maintscript-helper is used in the preinst, using it
213       unconditionally requires a pre-dependency to ensure that the required
214       version of dpkg has been unpacked before. The required version depends
215       on the command used, for rm_conffile and mv_conffile it is 1.15.7.2,
216       for symlink_to_dir and dir_to_symlink it is 1.17.14:
217
218        Pre-Depends: dpkg (>= 1.17.14)
219
220       But in many cases the operation done by the program is not critical for
221       the package, and instead of using a pre-dependency we can call the
222       program only if we know that the required command is supported by the
223       currently installed dpkg:
224
225
226            if dpkg-maintscript-helper supports command; then
227               dpkg-maintscript-helper command ...
228            fi
229
230       The command supports will return 0 on success, 1 otherwise. The
231       supports command will check if the environment variables as set by dpkg
232       and required by the script are present, and will consider it a failure
233       in case the environment is not sufficient.
234

ENVIRONMENT

236       DPKG_ROOT
237           If set, it will be used as the filesystem root directory.
238
239       DPKG_ADMINDIR
240           If set, it will be used as the dpkg data directory.
241
242       DPKG_COLORS
243           Sets the color mode (since dpkg 1.19.1).  The currently accepted
244           values are: auto (default), always and never.
245

SEE ALSO

247       dh_installdeb(1).
248
249
250
2511.21.21                           2023-02-25        dpkg-maintscript-helper(1)
Impressum