| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
frontend - runs a debconf frontend |
| 6 |
|
| 7 |
=head1 SYNOPSIS |
| 8 |
|
| 9 |
frontend confmodule [params] |
| 10 |
|
| 11 |
=head1 DESCRIPTION |
| 12 |
|
| 13 |
This is a helper program for confmodules. It expects to be passed |
| 14 |
the name of the confmodule script to run, and any parameters for it. |
| 15 |
|
| 16 |
This whole thing is really a hack; in an ideal world, dpkg would handle |
| 17 |
all this. |
| 18 |
|
| 19 |
=cut |
| 20 |
|
| 21 |
use warnings; |
| 22 |
use strict; |
| 23 |
use Debconf::Db; |
| 24 |
use Debconf::Template; |
| 25 |
use Debconf::AutoSelect qw(:all); |
| 26 |
use Debconf::Log qw(:all); |
| 27 |
|
| 28 |
Debconf::Db->load; |
| 29 |
|
| 30 |
debug developer => "frontend started"; |
| 31 |
|
| 32 |
my $frontend=make_frontend(); |
| 33 |
|
| 34 |
shift @ARGV if $ARGV[0] eq '--'; |
| 35 |
|
| 36 |
# Set the default title. |
| 37 |
my $package; |
| 38 |
my $no_title=0; |
| 39 |
my $root=$ENV{DPKG_ROOT} // ''; |
| 40 |
if ($ENV{DEBCONF_PACKAGE}) { |
| 41 |
$package=$ENV{DEBCONF_PACKAGE}; |
| 42 |
} |
| 43 |
elsif ($ARGV[0]=~m!^.*/(.*?)\.(?:postinst|postrm|prerm)$!) { |
| 44 |
$package=$1; |
| 45 |
my $action=$ARGV[1]; |
| 46 |
# Avoid spurious title updates with triggered actions: |
| 47 |
$no_title=1 if $action eq 'triggered'; |
| 48 |
} |
| 49 |
elsif (-e "$root/var/lib/dpkg/tmp.ci/control") { |
| 50 |
# The preinst is running, presumably. Now it gets really ugly, because |
| 51 |
# I have to parse the control file. |
| 52 |
open (my $control, "<", "$root/var/lib/dpkg/tmp.ci/control") |
| 53 |
|| die "Debconf: unable to open control file: $!"; |
| 54 |
while (<$control>) { |
| 55 |
if (/^Package: (.*)/) { |
| 56 |
$package=$1; |
| 57 |
last; |
| 58 |
} |
| 59 |
} |
| 60 |
close $control; |
| 61 |
if (! exists $ENV{PERL_DL_NONLAZY} || ! $ENV{PERL_DL_NONLAZY}) { |
| 62 |
warn "PERL_DL_NONLAZY is not set, if debconf is running from a preinst script, this is not safe"; |
| 63 |
} |
| 64 |
} |
| 65 |
else { |
| 66 |
# Being run some other way, not via a dpkg script. |
| 67 |
$package=''; |
| 68 |
|
| 69 |
debug developer => 'Trying to find a templates file..'; |
| 70 |
sub trytemplate { |
| 71 |
my $fn=shift; |
| 72 |
debug developer => "Trying $fn"; |
| 73 |
if (-e $fn) { |
| 74 |
debug developer => "I guess it is $fn"; |
| 75 |
Debconf::Template->load($fn, $package); |
| 76 |
return 1; |
| 77 |
} |
| 78 |
else { |
| 79 |
return; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
# See if there is a templates file in the same directory as the script, |
| 84 |
# with the same name except .templates is appended. |
| 85 |
unless (trytemplate("$ARGV[0].templates")) { |
| 86 |
# Next try removing "config" from the end of the script name, |
| 87 |
# and putting in "templates". |
| 88 |
unless ($ARGV[0]=~m/(.*)config$/ && trytemplate("${1}templates")) { |
| 89 |
# Finally, look in debconf lib directory for the base |
| 90 |
# filename with .templates appended. |
| 91 |
unless ($ARGV[0]=~m!^(?:.*/)?(.*)! && trytemplate("/usr/share/debconf/templates/${1}.templates")) { |
| 92 |
debug developer => "Couldn't find a templates file." |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
debug developer => "frontend running, package name is $package"; |
| 98 |
$frontend->default_title($package) if length $package and not $no_title; |
| 99 |
$frontend->info(undef); |
| 100 |
|
| 101 |
# Load any associated templates if we're being run from a package maintainer |
| 102 |
# script. |
| 103 |
if ($ARGV[0] =~/^(.*[.\/])(?:preinst|postinst|prerm|postrm)$/) { |
| 104 |
my $base=$1; |
| 105 |
my $templates=$base."templates"; |
| 106 |
Debconf::Template->load($templates, $package) |
| 107 |
if -e $templates; |
| 108 |
} |
| 109 |
|
| 110 |
# See if the preinst or postinst of the package is being run, and if there |
| 111 |
# is a config script associated with this package. If so, run it first as a |
| 112 |
# confmodule (also loading the templates). This is a bit of a nasty hack, that |
| 113 |
# lets you dpkg -i somepackage.deb and have its config script be run first. |
| 114 |
# |
| 115 |
# If it is the preinst, everything is in this weird directory deep in |
| 116 |
# /var/lib/dpkg. |
| 117 |
if ($ARGV[0] =~/^(.*[.\/])(?:postinst|preinst)$/) { |
| 118 |
my $base=$1; |
| 119 |
|
| 120 |
# Run config script, if any. |
| 121 |
my $config=$base."config"; |
| 122 |
if (-e $config) { |
| 123 |
# I assume that the third argument passed to this |
| 124 |
# program (which should be the second argument passed to the |
| 125 |
# preinst or postinst that ran it), is the package version. |
| 126 |
my $version=$ARGV[2]; |
| 127 |
if (! defined($version)) { |
| 128 |
$version=''; |
| 129 |
} |
| 130 |
my $confmodule=make_confmodule($config, |
| 131 |
"configure", $version); |
| 132 |
|
| 133 |
# Make sure any questions the confmodule generates |
| 134 |
# are owned by this package. |
| 135 |
$confmodule->owner($package); |
| 136 |
|
| 137 |
# Talk to it until it is done. |
| 138 |
1 while ($confmodule->communicate); |
| 139 |
|
| 140 |
exit $confmodule->exitcode if $confmodule->exitcode > 0; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
# Start up the confmodule we were asked to run. |
| 145 |
my $confmodule=make_confmodule(@ARGV); |
| 146 |
|
| 147 |
# Make sure any questions the confmodule generates are owned by this package. |
| 148 |
$confmodule->owner($package); |
| 149 |
|
| 150 |
# Talk to it until it is done. |
| 151 |
1 while ($confmodule->communicate); |
| 152 |
|
| 153 |
$frontend->shutdown; |
| 154 |
|
| 155 |
# Save state. |
| 156 |
Debconf::Db->save; |
| 157 |
|
| 158 |
exit $confmodule->exitcode; |
| 159 |
|
| 160 |
=head1 AUTHOR |
| 161 |
|
| 162 |
Joey Hess <[email protected]> |
| 163 |
|
| 164 |
=cut |