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
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

DESCRIPTION

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

COMMON PARAMETERS

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 owning the pathname(s).  When  the  package  is
64              “Multi-Arch:  same” this parameter must include the architecture
65              qualifier,  otherwise  it  should  not   usually   include   the
66              architecture  qualifier  (as  it would disallow cross-grades, or
67              switching from being architecture specific to  architecture  all
68              or  vice  versa).   If  the  parameter  is empty or omitted, the
69              DPKG_MAINTSCRIPT_PACKAGE and  DPKG_MAINTSCRIPT_ARCH  environment
70              variables  (as  set by dpkg when running the maintainer scripts)
71              will be used to generate an arch-qualified package name.
72
73       --     All  the  parameters  of  the  maintainer  scripts  have  to  be
74              forwarded to the program after --.
75
77       When upgrading a package, dpkg will not automatically remove a conffile
78       (a configuration file for which dpkg should preserve user  changes)  if
79       it is not present in the newer version. There are two principal reasons
80       for this; the first is that  the  conffile  could've  been  dropped  by
81       accident  and  the  next  version could restore it, users wouldn't want
82       their  changes  thrown  away.  The  second  is  to  allow  packages  to
83       transition  files  from a dpkg-maintained conffile to a file maintained
84       by the package's maintainer scripts, usually with a tool  like  debconf
85       or ucf.
86
87       This  means  that  if  a  package  is  intended  to  rename or remove a
88       conffile, it must explicitly do so and dpkg-maintscript-helper  can  be
89       used  to  implement  graceful  deletion  and moving of conffiles within
90       maintainer scripts.
91
92   Removing a conffile
93       If a conffile is completely removed, it should be  removed  from  disk,
94       unless the user has modified it. If there are local modifications, they
95       should be preserved. If the package upgrades aborts, the newly obsolete
96       conffile should not disappear.
97
98       All  of  this  is implemented by putting the following shell snippet in
99       the preinst, postinst and postrm maintainer scripts:
100
101           dpkg-maintscript-helper rm_conffile \
102               conffile prior-version package -- "$@"
103
104       conffile is the filename of the conffile to remove.
105
106       Current implementation: in the preinst, it checks if the  conffile  was
107       modified   and  renames  it  either  to  conffile.dpkg-remove  (if  not
108       modified) or to conffile.dpkg-backup (if modified).  In  the  postinst,
109       the  latter file is renamed to conffile.dpkg-bak and kept for reference
110       as it contains user modifications but the former will  be  removed.  If
111       the   package  upgrade  aborts,  the  postrm  reinstalls  the  original
112       conffile. During purge, the postrm will also delete the .dpkg-bak  file
113       kept up to now.
114
115   Renaming a conffile
116       If  a  conffile is moved from one location to another, you need to make
117       sure you move across any changes the user has made.  This  may  seem  a
118       simple  change to the preinst script at first, however that will result
119       in the user being prompted by dpkg to approve the conffile  edits  even
120       though they are not responsible of them.
121
122       Graceful  renaming  can  be  implemented by putting the following shell
123       snippet in the preinst, postinst and postrm maintainer scripts:
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           dpkg-maintscript-helper symlink_to_dir \
154               pathname old-target prior-version package -- "$@"
155
156       pathname  is  the  absolute name of the old symlink (the path will be a
157       directory at the end of the installation) and old-target is the  target
158       name  of  the  former symlink at pathname. It can either be absolute or
159       relative to the directory containing pathname.
160
161       Current implementation: the preinst checks if the  symlink  exists  and
162       points  to  old-target,  if not then it's left in place, otherwise it's
163       renamed to pathname.dpkg-backup. On configuration, the postinst removes
164       pathname.dpkg-backup  if  pathname.dpkg-backup  is  still a symlink. On
165       abort-upgrade/abort-install, the  postrm  renames  pathname.dpkg-backup
166       back to pathname if required.
167
168   Switching a directory to symlink
169       If  a  real  directory  is switched to a symlink, you need to make sure
170       before unpacking that the directory is removed. This may seem a  simple
171       change to the preinst script at first, however that will result in some
172       problems in case the directory contains conffiles, pathnames  owned  by
173       other  packages,  locally  created  pathnames,  or when downgrading the
174       package.
175
176       Graceful switching can be implemented by putting  the  following  shell
177       snippet in the preinst, postinst and postrm maintainer scripts:
178
179           dpkg-maintscript-helper dir_to_symlink \
180               pathname new-target prior-version package -- "$@"
181
182       pathname  is the absolute name of the old directory (the path will be a
183       symlink at the end of the installation) and new-target is the target of
184       the  new  symlink at pathname. It can either be absolute or relative to
185       the directory containing pathname.
186
187       Current implementation: the preinst checks  if  the  directory  exists,
188       does  not  contain  conffiles,  pathnames  owned  by other packages, or
189       locally created pathnames, if not then it's left  in  place,  otherwise
190       it's  renamed  to  pathname.dpkg-backup, and an empty staging directory
191       named pathname is created, marked with a file so that  dpkg  can  track
192       it.   On   configuration,   the   postinst   finishes   the  switch  if
193       pathname.dpkg-backup is still a directory and pathname is  the  staging
194       directory;  it removes the staging directory mark file, moves the newly
195       created files inside the staging directory to the symlink  target  new-
196       target/,  replaces  the  now  empty  staging  directory pathname with a
197       symlink   to   new-target,   and   removes   pathname.dpkg-backup.   On
198       abort-upgrade/abort-install,  the  postrm  renames pathname.dpkg-backup
199       back to pathname if required.
200

INTEGRATION IN PACKAGES

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

ENVIRONMENT

229       DPKG_COLORS
230              Sets the color mode (since dpkg 1.19.1).  The currently accepted
231              values are: auto (default), always and never.
232

SEE ALSO

234       dh_installdeb(1).
235
236
237
2381.19.7                            2019-06-03        dpkg-maintscript-helper(1)
Impressum