1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
.\" dpkg manual page - dpkg-maintscript-helper(1)
.\"
.\" Copyright © 2010-2012 Raphaël Hertzog <hertzog@debian.org>
.\"
.\" This is free software; you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation; either version 2 of the License, or
.\" (at your option) any later version.
.\"
.\" This is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program. If not, see <http://www.gnu.org/licenses/>.
.
.TH dpkg\-maintscript\-helper 1 "2012-02-08" "Debian Project" "dpkg suite"
.SH NAME
dpkg\-maintscript\-helper \- works around known dpkg limitations in maintainer scripts
.
.SH SYNOPSIS
.B dpkg\-maintscript\-helper
.IR command " [" parameter "...] \fB\-\-\fP " maint-script-parameter ...
.
.SH COMMANDS AND PARAMETERS
.P
\fBrm_conffile\fP \fIconffile\fP [\fIpriorversion\fP [\fIpackage\fP]]
.P
\fBmv_conffile\fP \fIoldconffile\fP \fInewconffile\fP [\fIpriorversion\fP [\fIpackage\fP]]
.
.SH DESCRIPTION
.P
This program is designed to be run within maintainer scripts to achieve
some tasks that dpkg can't (yet) handle natively either because of design
decisions or due to current limitations.
.P
Many of those tasks require coordinated actions from several maintainer
scripts (\fBpreinst\fP, \fBpostinst\fP, \fBprerm\fP, \fBpostrm\fP). To
avoid mistakes the same call simply needs to be put in all scripts and the
program will automatically adapt its behaviour based on the environment
variable \fBDPKG_MAINTSCRIPT_NAME\fP and on the maintainer scripts arguments
that you have to forward after a double dash.
.
.SH CONFFILE RELATED TASKS
.P
When upgrading a package, dpkg will not automatically remove a conffile (a
configuration file for which dpkg should preserve user changes) if it is
not present in the newer version. There are two principal reasons for
this; the first is that the conffile could've been dropped by accident and
the next version could restore it, users wouldn't want their changes
thrown away. The second is to allow packages to transition files from a
dpkg\-maintained conffile to a file maintained by the package's maintainer
scripts, usually with a tool like debconf or ucf.
.P
This means that if a package is intended to rename or remove a conffile,
it must explicitly do so and \fBdpkg\-maintscript\-helper\fP can be used
to implement graceful deletion and moving of conffiles within maintainer
scripts.
.
.SS REMOVING A CONFFILE
.P
If a conffile is completely removed, it should be removed from disk,
unless the user has modified it. If there are local modifications, they
should be preserved. If the package upgrades aborts, the newly obsolete
conffile should not disappear.
.P
All of this is implemented by putting the following shell snippet in the
\fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer scripts:
.P
dpkg\-maintscript\-helper rm_conffile \\
\fIconffile\fP \fIpriorversion\fP \fIpackage\fP \-\- "$@"
.P
\fIconffile\fP is the filename of the conffile to remove.
.P
\fIpriorversion\fP defines the latest version of the package whose
upgrade should trigger the removal. It is important to calculate
\fIpriorversion\fP correctly so that conffiles are correctly removed even
if the user rebuilt the package with a local version. For example, for a
conffile removed in version \fB2.0\-1\fP of a package, \fIpriorversion\fP
should be set to \fB2.0\-1~\fP. This will cause the conffile to be removed
even if the user rebuilt the previous version \fB1.0\-1\fP as
\fB1.0\-1local1\fP.
.P
If the conffile has not been shipped for several versions, and you are now
modifying the maintainer scripts to clean up the obsolete file,
\fIpriorversion\fP should be based on the version of the package that you are
now preparing, not the first version of the package that lacked the
conffile.
.P
\fIpackage\fP is the package name. If empty or omitted, the
DPKG_MAINTSCRIPT_PACKAGE environment variable (as set by dpkg) will be used.
.P
All the parameters of the maintainer scripts have to be forwarded to the
program after "\-\-".
.P
Current implementation: in the \fBpreinst\fP, it checks if the conffile
was modified and renames it either to \fIconffile\fP\fB.dpkg\-remove\fP (if not
modified) or to \fIconffile\fP\fB.dpkg\-backup\fP (if modified). In the
\fBpostinst\fP, the latter file is renamed to \fIconffile\fP\fB.dpkg\-bak\fP
and kept for reference as it contains user modifications but the former will
be removed. If the package upgrade aborts, the \fBpostrm\fP reinstalls the
original conffile. During purge, the \fBpostrm\fP will also delete the
\fB.dpkg\-bak\fP file kept up to now.
.
.SS RENAMING A CONFFILE
.P
If a conffile is moved from one location to another, you need to make sure
you move across any changes the user has made. This may seem a simple
change to the \fBpreinst\fP script at first, however that will result in
the user being prompted by dpkg to approve the conffile edits even though
they are not responsible of them.
.P
Graceful renaming can be implemented by putting the following shell
snippet in the \fBpreinst\fP, \fBpostinst\fP and \fBpostrm\fP maintainer
scripts:
.P
dpkg\-maintscript\-helper mv_conffile \\
\fIoldconffile\fP \fInewconffile\fP \fIpriorversion\fP \fIpackage\fP \-\- "$@"
.P
\fIoldconffile\fP and \fInewconffile\fP are the old and new name of the
conffile to rename.
.P
\fIpriorversion\fP defines the latest version of the package whose upgrade
should trigger the rename of the conffile (see the notes for
\fBrm_conffile\fR above concerning the correct value). If \fIpriorversion\fP is
empty or omitted, then the operation is tried on every upgrade (note: it's
safer to give the version and have the operation tried only once).
.P
\fIpackage\fP is the package name. If empty or omitted, the
DPKG_MAINTSCRIPT_PACKAGE environment variable (as set by dpkg) will be used.
.P
All the parameters of the maintainer scripts have to be forwarded to the
program after "\-\-".
.P
Current implementation: the \fBpreinst\fP checks if the conffile has been
modified, if yes it's left on place otherwise it's renamed to
\fIoldconffile\fP\fB.dpkg\-remove\fP. On configuration, the \fBpostinst\fP
removes \fIoldconffile\fP\fB.dpkg\-remove\fP and renames \fIoldconffile\fP
to \fInewconffile\fP if \fIoldconffile\fP is still available. On
abort\-upgrade/abort\-install, the \fBpostrm\fP renames
\fIoldconffile\fP\fB.dpkg\-remove\fP back to \fIoldconffile\fP if required.
.
.SH INTEGRATION IN PACKAGES
.P
Given that \fBdpkg\-maintscript\-helper\fP is used in the \fBpreinst\fP,
using it unconditionally requires a pre-dependency to ensure that the
required version of dpkg has been unpacked before. The required version
depends on the command used, for \fBrm_conffile\fP and \fBmv_conffile\fP
it is 1.15.7.2:
.P
\fBPre\-Depends:\fP dpkg (>= 1.15.7.2)
.P
But in many cases the operation done by the program is not critical for
the package, and instead of using a pre-dependency we can call the
program only if we know that the required command is supported by
the currently installed dpkg:
.P
if dpkg\-maintscript\-helper supports \fIcommand\fP; then
dpkg\-maintscript\-helper \fIcommand\fP ...
fi
|