~vcs-imports/debconf/svn

« back to all changes in this revision

Viewing changes to src/debconf/dpkg-reconfigure

  • Committer: joeyh
  • Date: 2011-02-02 00:33:44 UTC
  • Revision ID: svn-v4:a4a2c43b-8ac3-0310-8836-e0e880c912e2:trunk:2516
moved to git

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/perl -w
2
 
 
3
 
=head1 NAME
4
 
 
5
 
dpkg-reconfigure - reconfigure an already installed package
6
 
 
7
 
=head1 SYNOPSIS
8
 
 
9
 
 dpkg-reconfigure [options] packages
10
 
 
11
 
=head1 DESCRIPTION
12
 
 
13
 
B<dpkg-reconfigure> reconfigures packages after they have already been
14
 
installed. Pass it the names of a package or packages to reconfigure. It
15
 
will ask configuration questions, much like when the package was first
16
 
installed.
17
 
 
18
 
If you just want to see the current configuration of a package, see
19
 
L<debconf-show(1)> instead.
20
 
 
21
 
=head1 OPTIONS
22
 
 
23
 
=over 4
24
 
 
25
 
=item B<-f>I<type>, B<--frontend=>I<type>
26
 
 
27
 
Select the frontend to use. The default frontend can be permanently changed
28
 
by:
29
 
 
30
 
 dpkg-reconfigure debconf
31
 
 
32
 
Note that if you normally have debconf set to use the noninteractive
33
 
frontend, dpkg-reconfigure will use the dialog frontend instead, so you
34
 
actually get to reconfigure the package.
35
 
 
36
 
=item B<-p>I<value>, B<--priority=>I<value>
37
 
 
38
 
Specify the minimum priority of question that will be displayed.
39
 
dpkg-reconfigure normally shows low priority questions no matter what your
40
 
default priority is. See L<debconf(7)> for a list.
41
 
 
42
 
=item B<--default-priority>
43
 
 
44
 
Use whatever the default priority of question is, instead of forcing the
45
 
priority to low.
46
 
 
47
 
=item B<-a>, B<--all>
48
 
 
49
 
Reconfigure all installed packages that use debconf. Warning: this may take
50
 
a long time.
51
 
 
52
 
=item B<-u>, B<--unseen-only>
53
 
 
54
 
By default, all questions are shown, even if they have already been
55
 
answered. If this parameter is set though, only questions that have not yet
56
 
been seen will be asked.
57
 
 
58
 
=item B<--force>
59
 
 
60
 
Force dpkg-reconfigure to reconfigure a package even if the package is in an
61
 
inconsistent or broken state. Use with caution.
62
 
 
63
 
=item B<--no-reload>
64
 
 
65
 
Prevent dpkg-reconfigure from reloading templates. Use with caution; this
66
 
will prevent dpkg-reconfigure from repairing broken templates databases.
67
 
However, it may be useful in constrained environments where rewriting the
68
 
templates database is expensive.
69
 
 
70
 
=item B<-h>, B<--help>
71
 
 
72
 
Display usage help.
73
 
 
74
 
=back
75
 
 
76
 
=cut
77
 
 
78
 
=head1 SEE ALSO
79
 
 
80
 
L<debconf(7)>
81
 
 
82
 
=cut
83
 
 
84
 
my $infodir="/var/lib/dpkg/info";
85
 
 
86
 
use strict;
87
 
use Debconf::Db;
88
 
use Debconf::Gettext;
89
 
use Debconf::Template;
90
 
use Debconf::Config;
91
 
use Debconf::AutoSelect qw(:all);
92
 
use Debconf::Log qw(:all);
93
 
 
94
 
# Use low priority unless an option below overrides.
95
 
Debconf::Config->priority('low');
96
 
 
97
 
my $unseen_only=0;
98
 
my $all=0;
99
 
my $force=0;
100
 
my $default_priority=0;
101
 
my $reload=1;
102
 
Debconf::Config->getopt(
103
 
gettext(qq{Usage: dpkg-reconfigure [options] packages
104
 
  -a,  --all                    Reconfigure all packages.
105
 
  -u,  --unseen-only            Show only not yet seen questions.
106
 
       --default-priority       Use default priority instead of low.
107
 
       --force                  Force reconfiguration of broken packages.
108
 
       --no-reload              Do not reload templates. (Use with caution.)}),
109
 
        "all|a"                 => \$all,
110
 
        "unseen-only|u"         => \$unseen_only,
111
 
        "default-priority"      => \$default_priority,
112
 
        "force"                 => \$force,
113
 
        "reload!"               => \$reload,
114
 
);
115
 
 
116
 
if ($> != 0) {
117
 
        print STDERR sprintf(gettext("%s must be run as root"), $0)."\n";
118
 
        exit 1;
119
 
}
120
 
 
121
 
Debconf::Db->load;
122
 
 
123
 
if ($default_priority) {
124
 
        Debconf::Config->priority(Debconf::Question->get('debconf/priority')->value);
125
 
}
126
 
 
127
 
# If the frontend is noninteractive, change it temporarily to dialog.
128
 
if (lc Debconf::Config->frontend eq 'noninteractive' &&
129
 
    ! Debconf::Config->frontend_forced) {
130
 
        Debconf::Config->frontend('dialog');
131
 
}
132
 
 
133
 
my $frontend=make_frontend();
134
 
 
135
 
unless ($unseen_only) {
136
 
        # Make the frontend show questions even if the user has already seen
137
 
        # them. Since this is a reconfigure program, they may want to change
138
 
        # their choices.
139
 
        Debconf::Config->reshow(1);
140
 
}
141
 
 
142
 
my @packages;
143
 
if ($all) {
144
 
        @packages=allpackages();
145
 
        exit unless @packages;
146
 
}
147
 
else {
148
 
        @packages=@ARGV;
149
 
        if (! @packages) {
150
 
                print STDERR "$0: ".gettext("please specify a package to reconfigure")."\n";
151
 
                exit 1;
152
 
        }
153
 
}
154
 
 
155
 
# This is a hack to let postinsts know when they're being reconfigured. It
156
 
# would of course be better to pass them "reconfigure", but we can't for
157
 
# hysterical raisens.
158
 
$ENV{DEBCONF_RECONFIGURE}=1;
159
 
 
160
 
foreach my $pkg (@packages) {
161
 
        # Set default title.
162
 
        $frontend->default_title($pkg);
163
 
        $frontend->info(undef);
164
 
 
165
 
        # Get the package version. Also check to make sure it is installed.
166
 
        $_=`dpkg --status $pkg`;
167
 
        my ($version)=m/Version: (.*)\n/;
168
 
        my ($status)=m/Status: (.*)\n/;
169
 
        if (! $force) {
170
 
                if (! defined $status || $status =~ m/not-installed$/) {
171
 
                        print STDERR "$0: ".sprintf(gettext("%s is not installed"), $pkg)."\n";
172
 
                        exit 1;
173
 
                }
174
 
                if ($status !~ m/ ok installed$/) {
175
 
                        print STDERR "$0: ".sprintf(gettext("%s is broken or not fully installed"), $pkg)."\n";
176
 
                        exit 1;
177
 
                }
178
 
        }
179
 
        
180
 
        if ($reload) {
181
 
                # Load up templates just in case they aren't already.
182
 
                Debconf::Template->load("$infodir/$pkg.templates", $pkg)
183
 
                        if -e "$infodir/$pkg.templates";
184
 
        }
185
 
 
186
 
        # Simulation of reinstalling a package, without bothering with
187
 
        # removing the files and putting them back. Just like in a regular
188
 
        # reinstall, run config, and postinst scripts in sequence, with args.
189
 
        # Do not run postrm, because the postrm can depend on the package's
190
 
        # files actually being gone already.
191
 
        foreach my $info (['prerm',    'upgrade',     $version],
192
 
                          ['config',   'reconfigure', $version],
193
 
                          ['postinst', 'configure',   $version]) {
194
 
                my $script=shift @$info;
195
 
                next unless -x "$infodir/$pkg.$script";
196
 
 
197
 
                my $is_confmodule='';
198
 
 
199
 
                if ($script ne 'config') {
200
 
                        # Test to see if the script uses debconf.
201
 
                        open (IN, "<$infodir/$pkg.$script");
202
 
                        while (<IN>) {
203
 
                                if (/confmodule/i) {
204
 
                                        $is_confmodule=1;
205
 
                                        last;
206
 
                                }
207
 
                        }
208
 
                        close IN;
209
 
                }
210
 
                
211
 
                if ($script eq 'config' || $is_confmodule) {
212
 
                        # Start up the confmodule.
213
 
                        my $confmodule=make_confmodule(
214
 
                                "$infodir/$pkg.$script", @$info);
215
 
        
216
 
                        # Make sure any questions the confmodule registers
217
 
                        # are owned by this package.
218
 
                        $confmodule->owner($pkg);
219
 
                
220
 
                        # Talk to it until it is done.
221
 
                        1 while ($confmodule->communicate);
222
 
        
223
 
                        exit $confmodule->exitcode if $confmodule->exitcode > 0;
224
 
                }
225
 
                else {
226
 
                        # Not a confmodule, so run it as a normal script.
227
 
                        # Since it might run other programs that do use
228
 
                        # debconf, checkpoint the current database state
229
 
                        # and re-initialize it when the script finishes.
230
 
                        Debconf::Db->save;
231
 
                        
232
 
                        delete $ENV{DEBIAN_HAS_FRONTEND};
233
 
                        my $ret=system("$infodir/$pkg.$script", @$info);
234
 
                        if (int($ret / 256) != 0) {
235
 
                                exit int($ret / 256);
236
 
                        }
237
 
                        $ENV{DEBIAN_HAS_FRONTEND}=1;
238
 
                        
239
 
                        Debconf::Db->load;
240
 
                }
241
 
        }
242
 
}
243
 
 
244
 
$frontend->shutdown;
245
 
 
246
 
Debconf::Db->save;
247
 
 
248
 
# Returns a list of all installed packages.
249
 
sub allpackages {
250
 
        my @ret;
251
 
        local $/="\n\n";
252
 
        
253
 
        open (STATUS, "</var/lib/dpkg/status")
254
 
                || die sprintf(gettext("Cannot read status file: %s"), $!);
255
 
        while (<STATUS>) {
256
 
                push @ret, $1
257
 
                        if m/Status:\s*.*\sinstalled\n/ && m/Package:\s*(.*)\n/;
258
 
        }
259
 
        close STATUS;
260
 
 
261
 
        return sort @ret;
262
 
}
263
 
 
264
 
=head1 AUTHOR
265
 
 
266
 
Joey Hess <joeyh@debian.org>
267
 
 
268
 
=cut