diff options
Diffstat (limited to 'debian/exim4-config.postinst')
-rw-r--r-- | debian/exim4-config.postinst | 295 |
1 files changed, 295 insertions, 0 deletions
diff --git a/debian/exim4-config.postinst b/debian/exim4-config.postinst new file mode 100644 index 0000000..d87bc10 --- /dev/null +++ b/debian/exim4-config.postinst @@ -0,0 +1,295 @@ +#!/bin/sh + +set -e +. /usr/share/debconf/confmodule + +[ -n "$EX4DEBUG" ] && set -x + +db_version 2.0 + +get_value() { + db_get $1 + code="$?" + if [ "$code" -eq "0" ]; then + : + else + echo "Error getting debconf answer $1: debconf code=$code" >&2 + exit $code + fi +} + +write_header() { + cat <<EOF > /etc/exim4/update-exim4.conf.conf +# /etc/exim4/update-exim4.conf.conf +# +# Edit this file and /etc/mailname by hand and execute update-exim4.conf +# yourself or use 'dpkg-reconfigure exim4-config' + +EOF +} + +addrootalias() { +# remove leading and ending whitespace, shrink multiple whitespace, separate +# entries with commas +poma=`echo "$1" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/[[:space:]][[:space:]]*/,/g'` +if [ "xnone" != "x$poma" ] && [ "x" != "x$poma" ]; then + echo "root: ${poma}" >> /etc/aliases +fi +} + +#initialize /etc/aliases +writealiases() { +echo '# /etc/aliases' > /etc/aliases.tmp +echo 'mailer-daemon: postmaster' >> /etc/aliases.tmp +for i in postmaster nobody hostmaster usenet news webmaster www ftp abuse noc security ; do + echo "${i}: root" +done >> /etc/aliases.tmp +mv /etc/aliases.tmp /etc/aliases +} + +alias stripwhitespace="sed -e 's/^[[:blank:]]*//' -e 's/[[:blank:]]*$//'" + +# return success if md5sum matches file +unmodified() { + [ "$#" -eq 1 ] || return 1 + [ -f "$1" ] || return 1 + # first line, without the leading '# '. + checksum_current=`sed -n -e '1s/^# //' -e '1p;1q' "$1"` + + # md5sum over the rest of the file. + # some versions of md5sum produce + # '68b329da9893e34099c7d8ad5cb9c940 -' others don't add the dash. + # '68b329da9893e34099c7d8ad5cb9c940' + checksum_new=`sed -n '2,$p' "$1" | md5sum | cut -d\ -f1` + + if [ "${checksum_current}" = "${checksum_new}" ] ; then + return 0 + else + return 1 + fi +} + +convert_to_long () +{ + case "$1" in + internet) + echo -n "internet site; mail is sent and received directly using SMTP" + ;; + smarthost) + echo -n "mail sent by smarthost; received via SMTP or fetchmail" + ;; + satellite) + echo -n "mail sent by smarthost; no local mail" + ;; + local) + echo -n "local delivery only; not on a network" + ;; + exim3manual) + echo -n "manually convert from handcrafted Exim v3 configuration" + ;; + none) + echo -n "no configuration at this time" + ;; + esac +} +convert_to_short () +{ + case "$1" in + "internet site; mail is sent and received directly using SMTP") + echo -n "internet" + ;; + "mail sent by smarthost; received via SMTP or fetchmail") + echo -n "smarthost" + ;; + "mail sent by smarthost; no local mail") + echo -n "satellite" + ;; + "local delivery only; not on a network") + echo -n "local" + ;; + "manually convert from handcrafted Exim v3 configuration") + echo -n "exim3manual" + ;; + "no configuration at this time") + echo -n "none" + ;; + esac +} + +# remove orphaned autogenerated conffile if unmodified. 4.20-2. +if [ "$1" = "configure" ] && \ + dpkg --compare-versions "$2" le-nl "4.20-1" ; then + + for i in /etc/exim4/conf.d/rewrite/30_exim4-config_email-addresses \ + /etc/exim4/conf.d/rewrite/35_exim4-config_masquerade ; do + if unmodified "$i"; then + echo "Removing orphaned unmodified configfile $i" 1>&2 + rm "$i" + fi + done + +fi +if [ "$1" = "configure" ] && \ + dpkg --compare-versions "$2" le-nl "4.20-2" ; then + if unmodified "/etc/exim4/conf.d/main/03_exim4-config_neverusers"; then + echo "Removing orphaned unmodified configfile /etc/exim4/conf.d/main/03_exim4-config_neverusers" 1>&2 + rm "/etc/exim4/conf.d/main/03_exim4-config_neverusers" + fi +fi + +# Disable orphaned inetd-entries from exim (v3) caused by bugs #202670 +# and #182206. +if [ "$1" = "configure" ] &&\ + [ -x /usr/sbin/update-inetd ] && [ ! -x /usr/sbin/exim ] && \ + egrep -q '^smtp[[:space:]]*stream[[:space:]]*tcp[[:space:]]*nowait[[:space:]]*mail[[:space:]]*/usr/sbin/+exim exim -bs' /etc/inetd.conf +then + update-inetd --comment-chars \#disabled\# \ + --pattern '/usr/sbin/exim exim -bs' --disable smtp +fi + +if [ "$1" = "configure" ] &&\ + ! getent passwd Debian-exim > /dev/null ; then + echo 'Adding system-user for exim (v4)' 1>&2 + adduser --system --group --home /var/spool/exim4 --no-create-home \ + --disabled-login --force-badname Debian-exim > /dev/null +fi + +# fix permissions of /etc/exim4/passwd.client +if [ "$1" = "configure" ] ; then + if ! dpkg-statoverride --list /etc/exim4/passwd.client > /dev/null 2>&1 + then + dpkg-statoverride --update --add root Debian-exim 0640 \ + /etc/exim4/passwd.client + fi + + find /etc/exim4 -user mail \( -type f -or -type d \) -print |\ + while read i ; + do + if ! dpkg-statoverride --list "$i" > /dev/null ; then + chown Debian-exim "$i" + fi + done + find /etc/exim4 -group mail \( -type f -or -type d \) -print |\ + while read i ; + do + if ! dpkg-statoverride --list "$i" > /dev/null ; then + chgrp Debian-exim "$i" + fi + done +fi + +case "$1" in + configure) + # Configure Exim############################## + ############################################## + # valid config directives + dc_directives="dc_eximconfig_configtype dc_other_hostnames dc_local_interfaces dc_readhost dc_relay_domains dc_minimaldns dc_relay_nets dc_smarthost CFILEMODE dc_use_split_config" + # Generate config-file if it does not yet exist + if [ ! -e /etc/exim4/update-exim4.conf.conf ] ; then + write_header + for variable in ${dc_directives} ; do + echo "${variable}=" + done >> /etc/exim4/update-exim4.conf.conf + fi + + # If this is a fresh installation generate dummy files, which + # will be overwritten by update-exim4.conf + # if we add stuff later, we have to compare versions: + # if [ -z "$2" -o "$2" = "<unknown>" ] || dpkg --compare-versions "$2" lt "4.14-0.4" ; then + # for file in /etc/exim4/conf.d/main/03_exim4-config_neverusers ;do + # if [ ! -f "$file" ] ; then + # echo "# d41d8cd98f00b204e9800998ecf8427e" > "$file" + # chmod 644 "$file" + # fi + # done + #fi + + # generate defaultfile + update-exim4defaults --init + + # source /etc/exim4/update-exim4.conf.conf - needed for not + # debconf-managed values in there. + . /etc/exim4/update-exim4.conf.conf + + # Substitute values from debconf db + db_get exim4/dc_eximconfig_configtype || true + dc_eximconfig_configtype=`convert_to_short "$RET"` + db_get exim4/dc_local_interfaces || true + dc_local_interfaces=`echo "$RET" | stripwhitespace` + db_get exim4/dc_other_hostnames || true + dc_other_hostnames=`echo "$RET" | stripwhitespace` + db_get exim4/dc_readhost || true + dc_readhost=`echo "$RET" | stripwhitespace` + db_get exim4/dc_relay_domains || true + dc_relay_domains=`echo "$RET" | stripwhitespace` + db_get exim4/dc_relay_nets || true + dc_relay_nets=`echo "$RET" | stripwhitespace` + db_get exim4/dc_smarthost || true + dc_smarthost=`echo "$RET" | stripwhitespace` + db_get exim4/dc_minimaldns || true + dc_minimaldns=`echo "$RET" | stripwhitespace` + db_get exim4/mailname || true + mailname=`echo "$RET" | stripwhitespace` + db_get exim4/use_split_config || true + dc_use_split_config=`echo "$RET" | stripwhitespace` + + [ "x${CFILEMODE}" = "x" ] && CFILEMODE=644 + + db_get exim4/dc_postmaster + dc_postmaster=`echo "$RET" | stripwhitespace` + + if [ ! -e /etc/aliases ] ; then + writealiases + fi + if ! grep -q '^root:[[:space:]]*[[:alnum:]]' /etc/aliases && \ + [ "x${dc_postmaster}" != "xnone" ]; then + addrootalias "${dc_postmaster}" + fi + + ### write configuration to files # + # add missing items + for variable in ${dc_directives} ; do + if ! egrep -q "^[[:space:]]*${variable}=" /etc/exim4/update-exim4.conf.conf ; then + echo "${variable}=''" >> /etc/exim4/update-exim4.conf.conf + fi + done + # insert new values, remove outdated ones. + sed -e "sÄ^[[:space:]]*dc_eximconfig_configtype=.*Ädc_eximconfig_configtype='${dc_eximconfig_configtype}'Ä" \ + -e "sÄ^[[:space:]]*dc_local_interfaces=.*Ädc_local_interfaces='${dc_local_interfaces}'Ä" \ + -e "sÄ^[[:space:]]*dc_other_hostnames=.*Ädc_other_hostnames='${dc_other_hostnames}'Ä" \ + -e "sÄ^[[:space:]]*dc_readhost=.*Ädc_readhost='${dc_readhost}'Ä" \ + -e "sÄ^[[:space:]]*dc_relay_domains=.*Ädc_relay_domains='${dc_relay_domains}'Ä" \ + -e "sÄ^[[:space:]]*dc_relay_nets=.*Ädc_relay_nets='${dc_relay_nets}'Ä" \ + -e "sÄ^[[:space:]]*dc_smarthost=.*Ädc_smarthost='${dc_smarthost}'Ä" \ + -e "sÄ^[[:space:]]*dc_minimaldns=.*Ädc_minimaldns='${dc_minimaldns}'Ä" \ + -e "sÄ^[[:space:]]*CFILEMODE=.*ÄCFILEMODE='${CFILEMODE}'Ä" \ + -e "sÄ^[[:space:]]*dc_never_users=.*ÄÄ" \ + -e "sÄ^[[:space:]]*dc_use_split_config=.*Ädc_use_split_config='${dc_use_split_config}'Ä" \ + < /etc/exim4/update-exim4.conf.conf \ + > /etc/exim4/update-exim4.conf.conf.tmp + mv /etc/exim4/update-exim4.conf.conf.tmp /etc/exim4/update-exim4.conf.conf + + echo $mailname > /etc/mailname + ### configuration files written ## + + + if [ "${dc_eximconfig_configtype}" != "none" ] &&\ + [ "${dc_eximconfig_configtype}" != "exim3manual" ]; then + update-exim4.conf + fi + + ;; +esac + +# remove orphaned conffile if unmodified. 4.20-2. +if [ "$1" = "configure" ] && \ + dpkg --compare-versions "$2" le-nl "4.20-1" && \ + [ -e /etc/exim4/email-addresses ] && \ + [ `md5sum /etc/exim4/email-addresses | cut -d\ -f1` = "6bea09fbb18e4676012105fa5fc726c6" ] +then + echo "Removing orphaned unmodified configfile /etc/exim4/email-addresses" 1>&2 + rm /etc/exim4/email-addresses +fi + + +#DEBHELPER# |