summaryrefslogtreecommitdiff
path: root/debian/exim4-base.postinst
blob: 79cfa2fce39d307a82db0018d0ec92d65391e88b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/sh

set -e
. /usr/share/debconf/confmodule

if [ -n "$EX4DEBUG" ]; then
  echo "now debugging $0 $@"
  set -x
fi

db_version 2.0

case "$1" in
  configure)

	if ! getent passwd Debian-exim > /dev/null ; then
	  echo 'Adding system-user for exim (v4)' 1>&2
	  adduser --system --group --quiet --home /var/spool/exim4 \
	    --no-create-home --disabled-login --force-badname Debian-exim
	fi
	# Create directories for log etc
	# install also fixes permissions.
	install -d -oDebian-exim -gadm -m2750 /var/log/exim4
	install -d -oDebian-exim -gDebian-exim -m750 /var/run/exim4
	install -d -oDebian-exim -gDebian-exim -m750 /var/spool/exim4
	install -d -oDebian-exim -gDebian-exim -m750 /var/spool/exim4/db \
		/var/spool/exim4/input /var/spool/exim4/msglog

	# Make sure that db files are owned by Debian-exim:Debian-exim
	find /var/spool/exim4/db/ -type f -print0 |\
		xargs -0 -r chown Debian-exim:Debian-exim
	# fix permissions on upgrades
	if dpkg --compare-versions "$2" le "4.30-1" ; then
		find /var/log/exim4 /var/spool/exim4 -group mail \
			\( -type f -or -type d \) -print0 | \
			xargs -0r chgrp Debian-exim
		find /var/log/exim4 /var/spool/exim4 -user mail \
			\( -type f -or -type d \) -print0 | \
			xargs -0r chown Debian-exim
	fi
	# zap gnutls-params if old-format binary file is found or
	# file(1) is not installed. Since exim had its RSA_EXPORT
	# capability removed, it cannot read the binary file any more.
	GNUTLS_PARAMS="/var/spool/exim4/gnutls-params"

        if [ -e "$GNUTLS_PARAMS" ] && \
	   command -v file >/dev/null && \
	   [ -x "$(command -v file)" ]; then
                if [ "$(file --brief --mime $GNUTLS_PARAMS)" != \
		     "text/plain; charset=us-ascii" ]; then
                        # old format gnutls-params
                        rm -f $GNUTLS_PARAMS
                fi
        else
                # no file(1) in path, zap gnutls-params just to be sure
                rm -f $GNUTLS_PARAMS
        fi

	# Paranoia check: On upgrades from db3-versions throw away hints
	# databases.
	if dpkg --compare-versions "$2" '<=' "4.61-1" ; then
		rm -f /var/spool/exim4/db/misc-* /var/spool/exim4/db/wait-* \
			/var/spool/exim4/db/callout* \
			/var/spool/exim4/db/retry* \
			/var/spool/exim4/db/__db.retry \
			/var/spool/exim4/db/__db.misc \
			/var/spool/exim4/db/__db.callout \
			/var/spool/exim4/db/__db.wait*
	fi
	# Check that db files are readable by this Exim's db library
	dbfiles=""
	for f in /var/spool/exim4/db/misc-* /var/spool/exim4/db/wait-* \
	         /var/spool/exim4/db/callout* /var/spool/exim4/db/retry*; do
	    if [ -f "$f" ]; then
		if echo $f | grep \.lockfile\$ >/dev/null 2>&1; then
		    : # ignore lock files
		else
		    dbfiles="$dbfiles `basename $f`"
		fi
	    fi
	done
	for dbfile in $dbfiles; do
	    if exim_dumpdb /var/spool/exim4 $dbfile >/dev/null 2>&1; then
		: # File OK
	    else
		echo "Resetting invalid $dbfile hints db"
		rm -f /var/spool/exim4/db/$dbfile /var/spool/exim4/db/$dbfile.*
	    fi
	done

       if [ -x "/etc/init.d/exim4" ]; then
           update-rc.d exim4 defaults >/dev/null
       fi
	if [ -d /var/spool/exim/input ] ; then
		# With "head -n 1" this shouldn't be expensive.
		oldmails=`find /var/spool/exim/input/ -type f -print | head -n 1`
	fi
	if [ "x${oldmails}" != "x" ] ; then
		RET=""
		db_get exim4/move_exim3_spool
		dc_move_exim3_spool="$RET"
		if [ "x${dc_move_exim3_spool}" = "xtrue" ] ; then
			find /var/spool/exim/input/ -type f -print0 |\
				xargs -0r mv --target-directory=/var/spool/exim4/input
			find /var/spool/exim4/input -type f -print0 |\
				xargs -0r chown Debian-exim:Debian-exim
		fi
	fi

	# honor dpkg-statoverride settings for files not managed with dpkg
	for pat in /var/\*/exim4 /var/\*/exim4/\*; do
		[ $EX4DEBUG ] && eval echo "evaluate statoverride $pat"
		eval dpkg-statoverride --list $pat | while read USER GROUP MODE FILE; do
			[ $EX4DEBUG ] && echo "statoverride $USER $GROUP $MODE $FILE"
			chown ${USER}:${GROUP} $FILE
			chmod $MODE $FILE
		done
	done

	;;
esac

#DEBHELPER#