| 1 |
#!/usr/bin/perl |
| 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<--terse> |
| 43 |
|
| 44 |
Enables terse output mode. This affects only some frontends. |
| 45 |
|
| 46 |
=item B<--default-priority> |
| 47 |
|
| 48 |
Use whatever the default priority of question is, instead of forcing the |
| 49 |
priority to low. |
| 50 |
|
| 51 |
=item B<-u>, B<--unseen-only> |
| 52 |
|
| 53 |
By default, all questions are shown, even if they have already been |
| 54 |
answered. If this parameter is set though, only questions that have not yet |
| 55 |
been seen will be asked. |
| 56 |
|
| 57 |
=item B<--force> |
| 58 |
|
| 59 |
Force dpkg-reconfigure to reconfigure a package even if the package is in an |
| 60 |
inconsistent or broken state. Use with caution. |
| 61 |
|
| 62 |
=item B<--no-reload> |
| 63 |
|
| 64 |
Prevent dpkg-reconfigure from reloading templates. Use with caution; this |
| 65 |
will prevent dpkg-reconfigure from repairing broken templates databases. |
| 66 |
However, it may be useful in constrained environments where rewriting the |
| 67 |
templates database is expensive. |
| 68 |
|
| 69 |
=item B<-h>, B<--help> |
| 70 |
|
| 71 |
Display usage help. |
| 72 |
|
| 73 |
=back |
| 74 |
|
| 75 |
=cut |
| 76 |
|
| 77 |
=head1 SEE ALSO |
| 78 |
|
| 79 |
L<debconf(7)> |
| 80 |
|
| 81 |
=cut |
| 82 |
|
| 83 |
use warnings; |
| 84 |
use strict; |
| 85 |
|
| 86 |
if (exists $ENV{DEBCONF_USE_CDEBCONF} and $ENV{DEBCONF_USE_CDEBCONF} ne '') { |
| 87 |
exec "/usr/lib/cdebconf/dpkg-reconfigure", @ARGV; |
| 88 |
} |
| 89 |
|
| 90 |
use Cwd; |
| 91 |
use Debconf::Db; |
| 92 |
use Debconf::Gettext; |
| 93 |
use Debconf::Template; |
| 94 |
use Debconf::Config; |
| 95 |
use Debconf::AutoSelect qw(:all); |
| 96 |
use Debconf::Log qw(:all); |
| 97 |
|
| 98 |
# Use low priority unless an option below overrides. |
| 99 |
Debconf::Config->priority('low'); |
| 100 |
|
| 101 |
my $unseen_only=0; |
| 102 |
my $force=0; |
| 103 |
my $default_priority=0; |
| 104 |
my $reload=1; |
| 105 |
Debconf::Config->getopt( |
| 106 |
gettext(qq{Usage: dpkg-reconfigure [options] packages |
| 107 |
-u, --unseen-only Show only not yet seen questions. |
| 108 |
--default-priority Use default priority instead of low. |
| 109 |
--force Force reconfiguration of broken packages. |
| 110 |
--no-reload Do not reload templates. (Use with caution.)}), |
| 111 |
"unseen-only|u" => \$unseen_only, |
| 112 |
"default-priority" => \$default_priority, |
| 113 |
"force" => \$force, |
| 114 |
"reload!" => \$reload, |
| 115 |
); |
| 116 |
|
| 117 |
if ($> != 0) { |
| 118 |
print STDERR sprintf(gettext("%s must be run as root"), $0)."\n"; |
| 119 |
exit 1; |
| 120 |
} |
| 121 |
|
| 122 |
Debconf::Db->load; |
| 123 |
|
| 124 |
if ($default_priority) { |
| 125 |
Debconf::Config->priority(Debconf::Question->get('debconf/priority')->value); |
| 126 |
} |
| 127 |
|
| 128 |
# If the frontend is noninteractive, change it temporarily to dialog. |
| 129 |
if (lc Debconf::Config->frontend eq 'noninteractive' && |
| 130 |
! Debconf::Config->frontend_forced) { |
| 131 |
Debconf::Config->frontend('dialog'); |
| 132 |
} |
| 133 |
|
| 134 |
my $frontend=make_frontend(); |
| 135 |
|
| 136 |
unless ($unseen_only) { |
| 137 |
# Make the frontend show questions even if the user has already seen |
| 138 |
# them. Since this is a reconfigure program, they may want to change |
| 139 |
# their choices. |
| 140 |
Debconf::Config->reshow(1); |
| 141 |
} |
| 142 |
|
| 143 |
my @packages=@ARGV; |
| 144 |
if (! @packages) { |
| 145 |
print STDERR "$0: ".gettext("please specify a package to reconfigure")."\n"; |
| 146 |
exit 1; |
| 147 |
} |
| 148 |
|
| 149 |
# This is a hack to let postinsts know when they're being reconfigured. It |
| 150 |
# would of course be better to pass them "reconfigure", but we can't for |
| 151 |
# hysterical raisens. |
| 152 |
$ENV{DEBCONF_RECONFIGURE}=1; |
| 153 |
|
| 154 |
my %initial_triggers=map { $_ => 1 } triggers_pending(); |
| 155 |
|
| 156 |
my $original_cwd=getcwd(); |
| 157 |
|
| 158 |
foreach my $pkg (@packages) { |
| 159 |
# Set default title. |
| 160 |
$frontend->default_title($pkg); |
| 161 |
$frontend->info(undef); |
| 162 |
|
| 163 |
# Get the package version. Also check to make sure it is installed. |
| 164 |
$_=`dpkg --status $pkg`; |
| 165 |
my ($version)=m/Version: (.*)\n/; |
| 166 |
my ($status)=m/Status: (.*)\n/; |
| 167 |
my ($package)=m/Package: (.*)\n/; |
| 168 |
my ($arch)=m/Architecture: (.*)\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 |
my @control_paths=`dpkg-query --control-path $pkg`; |
| 181 |
map { my $line = $_; chomp $line; $line } @control_paths; |
| 182 |
my $control_path = sub { |
| 183 |
my $file = shift; |
| 184 |
my $path = (grep { /\.\Q$file\E$/ } @control_paths)[0]; |
| 185 |
chomp($path) if defined $path; |
| 186 |
return $path; |
| 187 |
}; |
| 188 |
|
| 189 |
if ($reload) { |
| 190 |
# Load up templates just in case they aren't already. |
| 191 |
my $templates=$control_path->('templates'); |
| 192 |
if ($templates and -e $templates) { |
| 193 |
Debconf::Template->load($templates, $pkg); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
# Simulation of reinstalling a package, without bothering with |
| 198 |
# removing the files and putting them back. Just like in a regular |
| 199 |
# reinstall, run config, and postinst scripts in sequence, with args. |
| 200 |
# Do not run postrm, because the postrm can depend on the package's |
| 201 |
# files actually being gone already. |
| 202 |
foreach my $info (['prerm', 'upgrade', $version], |
| 203 |
['preinst', 'upgrade', $version], |
| 204 |
['config', 'reconfigure', $version], |
| 205 |
['postinst', 'configure', $version]) { |
| 206 |
my $script=shift @$info; |
| 207 |
my $path_script=$control_path->($script); |
| 208 |
|
| 209 |
next unless $path_script and -x $path_script; |
| 210 |
|
| 211 |
my $is_confmodule=''; |
| 212 |
|
| 213 |
# Set environment variables expected by maintainer scripts |
| 214 |
$ENV{DPKG_MAINTSCRIPT_PACKAGE}=$package; |
| 215 |
$ENV{DPKG_MAINTSCRIPT_ARCH}=$arch; |
| 216 |
$ENV{DPKG_MAINTSCRIPT_NAME}=$script; |
| 217 |
|
| 218 |
if ($script ne 'config') { |
| 219 |
# Test to see if the script uses debconf. |
| 220 |
open (my $in, "<", $path_script); |
| 221 |
while (<$in>) { |
| 222 |
if (/confmodule/i) { |
| 223 |
$is_confmodule=1; |
| 224 |
last; |
| 225 |
} |
| 226 |
} |
| 227 |
close $in; |
| 228 |
} |
| 229 |
|
| 230 |
chdir('/'); |
| 231 |
if ($script eq 'config' || $is_confmodule) { |
| 232 |
# Start up the confmodule. |
| 233 |
my $confmodule=make_confmodule($path_script, @$info); |
| 234 |
|
| 235 |
# Make sure any questions the confmodule registers |
| 236 |
# are owned by this package. |
| 237 |
$confmodule->owner($pkg); |
| 238 |
|
| 239 |
# Talk to it until it is done. |
| 240 |
1 while ($confmodule->communicate); |
| 241 |
|
| 242 |
exit $confmodule->exitcode if $confmodule->exitcode > 0; |
| 243 |
} |
| 244 |
else { |
| 245 |
# Not a confmodule, so run it as a normal script. |
| 246 |
run_external($path_script, @$info); |
| 247 |
} |
| 248 |
chdir($original_cwd); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
# Maintainer scripts may have activated triggers. If so, try to process |
| 253 |
# them. |
| 254 |
my @new_triggers; |
| 255 |
do { |
| 256 |
@new_triggers=(); |
| 257 |
foreach my $trigpend (triggers_pending()) { |
| 258 |
push @new_triggers, $trigpend |
| 259 |
if not exists $initial_triggers{$trigpend}; |
| 260 |
} |
| 261 |
if (@new_triggers) { |
| 262 |
chdir('/'); |
| 263 |
run_external("dpkg", "--configure", @new_triggers); |
| 264 |
chdir($original_cwd); |
| 265 |
} |
| 266 |
} while (@new_triggers); |
| 267 |
|
| 268 |
$frontend->shutdown; |
| 269 |
|
| 270 |
Debconf::Db->save; |
| 271 |
|
| 272 |
# Run an external program that does not itself use debconf, but that may run |
| 273 |
# other programs that do use debconf. To do this safely, checkpoint the |
| 274 |
# current database state and re-initialize it when the program finishes. |
| 275 |
sub run_external { |
| 276 |
Debconf::Db->save; |
| 277 |
|
| 278 |
delete $ENV{DEBIAN_HAS_FRONTEND}; |
| 279 |
my $ret=system(@_); |
| 280 |
if (int($ret / 256) != 0) { |
| 281 |
exit int($ret / 256); |
| 282 |
} |
| 283 |
$ENV{DEBIAN_HAS_FRONTEND}=1; |
| 284 |
|
| 285 |
Debconf::Db->load; |
| 286 |
} |
| 287 |
|
| 288 |
# Returns a list of all packages with pending triggers. |
| 289 |
sub triggers_pending { |
| 290 |
my @ret; |
| 291 |
local $_; |
| 292 |
|
| 293 |
open (my $query, '-|', 'dpkg-query', '-W', |
| 294 |
'-f', '${Package} ${binary:Package}\t${Triggers-Pending}\n'); |
| 295 |
while (<$query>) { |
| 296 |
chomp; |
| 297 |
my ($pkgnames, $triggers) = split /\t/; |
| 298 |
if (length $triggers) { |
| 299 |
# Handle multiarch. |
| 300 |
my ($pkg, $binpkg) = split ' ', $pkgnames; |
| 301 |
push @ret, (length $binpkg ? $binpkg : $pkg); |
| 302 |
} |
| 303 |
} |
| 304 |
close $query; |
| 305 |
|
| 306 |
return @ret; |
| 307 |
} |
| 308 |
|
| 309 |
=head1 AUTHOR |
| 310 |
|
| 311 |
Joey Hess <[email protected]> |
| 312 |
|
| 313 |
=cut |