summaryrefslogtreecommitdiff
path: root/debian/debconf.gamla/exim4-base.config
diff options
context:
space:
mode:
Diffstat (limited to 'debian/debconf.gamla/exim4-base.config')
-rw-r--r--debian/debconf.gamla/exim4-base.config260
1 files changed, 260 insertions, 0 deletions
diff --git a/debian/debconf.gamla/exim4-base.config b/debian/debconf.gamla/exim4-base.config
new file mode 100644
index 0000000..8c17115
--- /dev/null
+++ b/debian/debconf.gamla/exim4-base.config
@@ -0,0 +1,260 @@
+#!/usr/bin/perl -w
+
+require 5;
+use strict;
+use Debconf::Client::ConfModule ':all';
+use Carp;
+use vars qw($reconfiguring $exim3conf $capb $default_configtype);
+
+sub get_value($) {
+ my $key = shift;
+ my($code,$text) = get($key);
+ return $text if ($code == 0);
+ croak("Unable to fetch value for \"$key\" (debconf code $code)");
+}
+
+sub enqueue_question($$) {
+ my $priority = shift;
+ my $template = shift;
+ my($code,$text) = input($priority, $template);
+ if ($code && $code != 30) {
+ croak("Error asking question \"$template\" (debconf code $code)");
+ }
+}
+
+sub set_default($$) {
+ my $key = shift;
+ my $defaultvalue = shift;
+ my($code, $text) = get($key);
+ if ($code == 0) {
+ if ($text eq '') {
+ ($code,$text) = set($key, $defaultvalue);
+ # Check $code...
+ }
+ }
+ else {
+ croak("Unable to fetch value for \"$key\" (debconf code $code)");
+ }
+}
+
+sub fetch_default($$) {
+ my $key = shift;
+ my $defaultcb = shift;
+ my($code, $text) = get($key);
+ if ($code == 0) {
+ if ($text eq '') {
+ my $defaultvalue = &$defaultcb;
+ if (defined($defaultvalue)) {
+ ($code, $text) = set($key, $defaultvalue);
+ # Check $code...
+ }
+ }
+ }
+ else {
+ croak("Unable to fetch value for \"$key\" (debconf code $code)");
+ }
+}
+
+sub debug {
+ if ($ENV{EXIMCONF_DEBUG}) {
+ print STDERR "$0: @_\n";
+ }
+}
+
+sub exim3_readconfig {
+ my $filename = shift || "/etc/exim/exim.conf";
+
+ if (open(EXIMCONF, $filename)) {
+
+ my $config;
+
+ my $keyword;
+
+ scanmain:
+ while (<EXIMCONF>) {
+ chomp;
+ if (/^end\b/) {
+ last scanmain;
+ }
+ elsif (/^\s*([a-zA-z0-9_]+)\s*=\s*(.*)/) {
+ $keyword = $1;
+ my $value = $2;
+ while ($value =~ s/\\$//) {
+ my $nextline = <EXIMCONF>;
+ $value .= $nextline;
+ }
+ $config->{main}->{$keyword} = $value;
+ }
+ elsif (/^\s*no_([a-zA-Z0-9_]+)\s*$/) {
+ $config->{main}->{$keyword} = '';
+ }
+ }
+
+ for my $section (qw|transports directors routers|) {
+ scansection:
+ while (<EXIMCONF>) {
+ chomp;
+
+ if (/^end\b/) {
+ last scansection;
+ }
+ elsif (/^([a-zA-Z0-9_]+):\s*/) {
+ my $objname = $1;
+ objectline:
+ while (<EXIMCONF>) {
+ next if (/^\s*\#/ || !/\S/);
+ if (/^\s*([a-zA-Z0-9_]+)\s*=\s*(.*)/) {
+ my $propname = $1;
+ my $value = $2;
+ while ($value =~ s/\\$//) {
+ my $nextline = <EXIMCONF>;
+ $value .= $nextline;
+ }
+ $config->{$section}->{$objname}->{$propname} = $value;
+ }
+ else {
+ redo scansection;
+ }
+ }
+ }
+ }
+ }
+
+ close(EXIMCONF);
+ debug("Read Exim 3 config file $filename");
+ return $config;
+ }
+ else {
+ debug("Unable to read $filename: $!");
+ }
+
+ return undef;
+}
+
+version('2.0');
+$capb = capb(''); # FIXME: Support backup
+
+######################################################################
+
+$reconfiguring = 1 if ($ARGV[0] eq 'reconfigure');
+
+if (-f "/etc/exim4/exim4.conf" && !$reconfiguring) {
+ exit(0); # exit if exim4.conf already built and we are not explicitly reconfiguring
+}
+
+######################################################################
+# Look for old Exim3 config file
+
+if (-f "/etc/exim/exim.conf") {
+ enqueue_question("high", "exim/configconvert/question");
+ go();
+ my $convertresponse = get_value("exim/configconvert/question");
+ if ($convertresponse eq 'convert') {
+ enqueue_question("high", "exim/configconvert/convertnotice");
+ go();
+ system("/etc/init.d/exim4", "stop") if ($reconfiguring);
+ exit(0);
+ }
+ elsif ($convertresponse eq 'none') {
+ enqueue_question("high", "exim/configconvert/breakagenotice");
+ go();
+ exit(0);
+ }
+ elsif ($convertresponse eq 'createnew') {
+ # Do not read exim3 config file for defaults if exim4.conf has been created already
+ # The defaults should have been seen once by the user and stored in debconf anyway.
+ $exim3conf = exim3_readconfig() unless (-f "/etc/exim4/exim4.conf");
+ }
+ else {
+ die "exim/configconvert/question has an unrecognised answer: (\"$convertresponse\")\n";
+ }
+}
+
+######################################################################
+# Ask eximconfig questions
+
+# Grab the configtype from the old exim3 config file
+# TRANSPORT(remote_smtp) does not exist ==> local
+# ROUTER(lookuphost) exists ==> internet
+# DIRECTOR(smart) exists ==> satellite
+# DEFAULT ==> smarthost
+fetch_default("exim/eximconfig/configtype", sub {
+ return "local" if (!defined($exim3conf->{transports}->{remote_smtp}));
+ return "internet" if (defined($exim3conf->{routers}->{lookuphost}));
+ return "satellite" if (defined($exim3conf->{directors}->{smart}));
+ return "smarthost"; });
+
+enqueue_question("high", "exim/eximconfig/configtype");
+go();
+
+my $configtype = get_value("exim/eximconfig/configtype");
+if ($configtype eq 'none') {
+ exit(0);
+}
+
+my $syshostname = $exim3conf->{main}->{primary_hostname} || $exim3conf->{main}->{qualify_domain} || `hostname --fqdn` || `hostname`;
+
+my $visiblename;
+
+if ($configtype eq 'satellite') {
+ set_default("exim/eximconfig/satellite_hostname", $syshostname);
+ enqueue_question("medium", "exim/eximconfig/satellite_hostname");
+ go();
+ $visiblename = get_value("exim/eximconfig/satellite_hostname");
+}
+else {
+ set_default("exim/eximconfig/visible_hostname", $syshostname);
+ enqueue_question("medium", "exim/eximconfig/visible_hostname");
+ go();
+ $visiblename = get_value("exim/eximconfig/visible_hostname");
+}
+
+if ($configtype eq 'internet' || $configtype eq 'smarthost') {
+ subst("exim/eximconfig/other_hostnames", "visiblename", $visiblename);
+
+ enqueue_question("high", "exim/eximconfig/other_hostnames");
+ # Downgrade these to medium since having them empty is likely to be reasonable?
+ enqueue_question("high", "exim/eximconfig/relay_domains");
+ enqueue_question("high", "exim/eximconfig/relay_nets");
+}
+
+my $ourdomain = $syshostname;
+$ourdomain =~ s/^[^.][^.]*\.//;
+
+if ($configtype eq 'satellite') {
+ # Exim 3 satellite configuration?
+ # Look for director called "smart"
+ # .. and new_address setting of "${local_part}@SOME_DOMAIN"
+ if ($exim3conf->{directors}->{smart} && $exim3conf->{directors}->{smart}->{new_address} =~ /^\${local_part}\@(.+)/) {
+ set_default("exim/eximconfig/readhost", $1);
+ }
+ else {
+ set_default("exim/eximconfig/readhost", $ourdomain);
+ }
+ # This is high priority even though it has a default, since $ourdomain
+ # is not necessarily "reasonable".. mail.$ourdomain would be equally "reasonable"
+ enqueue_question("high", "exim/eximconfig/readhost");
+ go();
+ my $readhost = get_value("exim/eximconfig/readhost");
+ set_default("exim/eximconfig/smarthost", $readhost);
+ enqueue_question("medium", "exim/eximconfig/smarthost");
+}
+elsif ($configtype eq 'smarthost') {
+ set_default("exim/eximconfig/smarthost", $ourdomain);
+ enqueue_question("high", "exim/eximconfig/smarthost");
+}
+
+enqueue_question("medium", "exim/eximconfig/overwrite_aliases");
+enqueue_question("medium", "exim/daemon/permissions");
+
+go();
+
+if ($reconfiguring) {
+ system("/etc/init.d/exim4", "stop");
+ if (-f "/etc/exim4/exim4.conf") {
+ unlink("/etc/exim4/exim4.conf-reconfigure");
+ rename("/etc/exim4/exim4.conf", "/etc/exim4/exim4.conf-reconfigure");
+ }
+}
+
+exit(0);