5
dpkg-preconfigure - let packages ask questions prior to their installation
9
dpkg-preconfigure [options] package.deb
11
dpkg-preconfigure --apt
15
B<dpkg-preconfigure> lets packages ask questions before they are installed.
16
It operates on a set of debian packages, and all packages that use debconf
17
will have their config script run so they can examine the system and ask
24
=item B<-f>I<type>, B<--frontend=>I<type>
26
Select the frontend to use.
28
=item B<-p>I<value>, B<--priority=>I<value>
30
Set the lowest priority of questions you are interested in. Any questions
31
with a priority below the selected priority will be ignored and their
32
default answers will be used.
36
Enables terse output mode. This affects only some frontends.
40
Run in apt mode. It will expect to read a set of package filenames from
41
stdin, rather than getting them as parameters. Typically this is used to
42
make apt run dpkg-preconfigure on all packages before they are installed.
43
To do this, add something like this to /etc/apt/apt.conf:
45
// Pre-configure all packages before
46
// they are installed.
47
DPkg::Pre-Install-Pkgs {
48
"dpkg-preconfigure --apt --priority=low";
51
=item B<-h>, B<--help>
65
# This program may be running from apt. If so, if it fails, apt is going to
66
# fail as well, which will make it hard for people to fix whatever the failure
67
# was. One thing someone encountered was perl failing to install. Apt then
68
# was re-run with perl unpacked and not configured, and modules weren't
69
# able to be loaded. As a sanity check, detect that case. If found, exit with
70
# an error message, but a return code of 0 so apt continues.
75
use Debconf::Log qw(:all);
77
use Debconf::Template;
79
use Debconf::AutoSelect qw(:all);
83
# Don't use gettext() on this because it may have failed to
85
print STDERR "debconf: Perl may be unconfigured ($@) -- aborting\n";
93
Debconf::Config->getopt(
94
qq{Usage: dpkg-preconfigure [options] [debs]
99
# In apt mode, need unbuffered output. Let's just enable it.
107
# If running from apt, read package filenames on stdin.
111
push @debs, $_ if length $_;
116
# We have now reached the end of the first file on stdin.
117
# Future reads from stdin should get input from the user, so re-open.
118
$have_tty=0 unless open (STDIN, "/dev/tty");
121
print STDERR sprintf("dpkg-preconfigure: ".gettext("must specify some debs to preconfigure")), "\n";
125
if (! -x "/usr/bin/apt-extracttemplates") {
126
warn gettext("delaying package configuration, since apt-utils is not installed");
130
my $frontend=make_frontend();
132
if (! $have_tty && $frontend->need_tty) {
133
print STDERR sprintf("dpkg-preconfigure: ".gettext("unable to re-open stdin: %s"), $!)."\n";
137
# Use the external package scanner for speed. It takes a list of debs
138
# and outputs to stdout a table with these fields separated by spaces:
139
my ($package, $version, $template, $config);
140
# Note that it also handles making sure the current version of debconf can
141
# deal with the package, because apt-extracttemplates skips over any
142
# package that depends on a version of debconf newer than what is
144
unless (open(INFO, "-|")) {
145
# The kernel can accept command lines up to 20k worth of
146
# characters. It has happened that the list of packages to
147
# configure is more than that, which requires splitting it up into
148
# multiple apt-extracttemplates runs.
149
my $command_max=20000; # LINUX SPECIFIC!!
150
# I could use POSIX::ARG_MAX, but that would be slow.
151
my $static_len=length("apt-extracttemplates");
154
if ($apt && @debs > 30) {
155
STDERR->autoflush(1);
157
foreach my $deb (@debs) {
158
$len += length($deb) + 1;
159
if ($len < $command_max && @collect < 30) {
163
if (system("apt-extracttemplates", @collect) != 0) {
164
print STDERR sprintf("debconf: ".gettext("apt-extracttemplates failed: %s")."\n",$!);
166
if ($apt && @debs > 30) {
167
$progress += @collect;
168
printf STDERR "\r".gettext("Extracting templates from packages: %d%%"), $progress * 100 / @debs;
172
$len=$static_len + length($deb) + 1;
175
if (system("apt-extracttemplates", @collect) != 0) {
176
print STDERR sprintf("debconf: ".gettext("apt-extracttemplates failed: %s")."\n",$!);
178
if ($apt && @debs > 30) {
179
$progress += @collect;
180
printf STDERR "\r".gettext("Extracting templates from packages: %d%%")."\n", $progress * 100 / @debs;
184
# Why buffer here? Well, suppose 300 packages are being installed, and
185
# only the first and last use debconf. The first is preconfigured. Then
186
# the user watches their UI lock up until it scans all the way to the last..
187
# Blowing a bit of memory on a buffer seems like a saner approach.
189
if ($apt && @buffer) {
190
print gettext("Preconfiguring packages ...\n");
192
foreach my $line (@buffer) {
193
($package, $version, $template, $config)=split /\s/, $line;
195
# Load templates if any.
196
if (defined $template && length $template) {
198
Debconf::Template->load($template, $package)
202
print STDERR "$package ".sprintf(gettext("template parse error: %s"), $@)."\n";
209
foreach my $line (@buffer) {
210
($package, $version, $template, $config)=split /\s/, $line;
212
# Run config script if any.
213
if (defined $config && length $config && -e $config) {
214
debug user => sprintf("preconfiguring %s (%s)",$package,$version);
215
chmod(0755, $config) or
216
die sprintf(gettext("debconf: can't chmod: %s"), $!);
217
$frontend->default_title($package);
218
$frontend->info(undef);
219
my $confmodule=make_confmodule($config, 'configure', $version);
220
# Make sure any questions created are owned by the correct package.
221
$confmodule->owner($package);
222
1 while ($confmodule->communicate);
223
# I could just exit, but it's good to be robust so
224
# other packages can still be configured and installed.
225
if ($confmodule->exitcode > 0) {
226
print STDERR sprintf(
227
gettext("%s failed to preconfigure, with exit status %s"),
228
$package, $confmodule->exitcode)."\n";
241
Joey Hess <joeyh@debian.org>