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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
#!/bin/sh -e
CONFIG=/etc/dbmail/dbmail.conf
CONFIG_EX=/usr/share/doc/dbmail/examples/dbmail.conf
DEBIAN_CONFIG=/etc/default/dbmail
DEBIAN_CONFIG_EX=/usr/share/dbmail/default.dbmail
test $DEBIAN_SCRIPT_DEBUG && set -v -x
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see /usr/doc/packaging-manual/
#
# quoting from the policy:
# Any necessary prompting should almost always be confined to the
# post-installation script, and should be protected with a conditional
# so that unnecessary prompting doesn't happen if a package's
# installation fails and the `postinst' is called with `abort-upgrade',
# `abort-remove' or `abort-deconfigure'.
create_user() {
# creating dbmail group if he isn't already there
getent group dbmail >/dev/null 2>&1 || \
addgroup --system dbmail >/dev/null 2>&1 || true
# creating dbmail user if he isn't already there
getent passwd dbmail >/dev/null 2>&1 || \
adduser \
--system \
--ingroup dbmail \
--home /dev/null \
--gecos "Dbmail SQL mailserver" \
--shell /bin/false \
dbmail >/dev/null 2>&1 || true
}
case "$1" in
install|upgrade)
create_user
;;
configure)
. /usr/share/debconf/confmodule
db_get dbmail/do_debconf || true; DO_DEBCONF=$RET
db_get dbmail/dbmail/authdriver || true; AUTHDRIVER=$RET
if [ "$DO_DEBCONF" = "true" ]; then
# fetch debconf values
db_get dbmail/dbmail/host || true; DB_HOST=$RET
db_get dbmail/dbmail/db || true; DB_DATABASE=$RET
db_get dbmail/dbmail/user || true; DB_USER=$RET
db_get dbmail/dbmail/pass || true; DB_PASS=$RET
db_get dbmail/dbmail/postmaster || true; POSTMASTER=$RET
db_get dbmail/start_imapd || true; START_IMAPD=$RET
db_get dbmail/start_lmtpd || true; START_LMTPD=$RET
db_get dbmail/start_pop3d || true; START_POP3D=$RET
db_get dbmail/sieve/start_sieve || true; START_SIEVE=$RET
if [ "$AUTHDRIVER" = "ldap" ]; then
db_get dbmail/ldap/HOSTNAME || true; LDAP_HOST=$RET
db_get dbmail/ldap/PORT || true; LDAP_PORT=$RET
db_get dbmail/ldap/BASE_DN || true; LDAP_BASE_DN=$RET
db_get dbmail/ldap/BIND_DN || true; LDAP_BIND_DN=$RET
db_get dbmail/ldap/BIND_PW || true; LDAP_BIND_PW=$RET
db_get dbmail/ldap/bind_anonymous || true; LDAP_BIND_ANONYMOUS=$RET
db_get dbmail/ldap/FIELD_UID || true; LDAP_UID=$RET
db_get dbmail/ldap/FIELD_CID || true; LDAP_CID=$RET
if [ -z "$LDAP_BASE_DN" ]; then
# For the domain really.argh.org we create the basedn
# dc=really,dc=argh,dc=org with the dc entry dc: really
db_get slapd/domain && SLAPD_DOMAIN=$RET
if [ -n "$SLAPD_DOMAIN" ]; then
LDAP_BASE_DN="dc=`echo $SLAPD_DOMAIN|sed 's/\./,dc=/g'`"
fi
fi
if [ -n "$LDAP_BASE_DN" ] && [ -z "$LDAP_BIND_DN" ] && [ "$LDAP_BIND_ANONYMOUS" = "false" ]; then
LDAP_BIND_DN="cn=dbmail,$LDAP_BASE_DN";
db_set dbmail/ldap/BIND_DN "$LDAP_BIND_DN"
if [ -x /usr/bin/pwgen ]; then
LDAP_BIND_PW=`pwgen -n`
db_set dbmail/ldap/BIND_PW "$LDAP_BIND_PW"
fi
fi
if [ -z $LDAP_UID ]; then
LDAP_UID="uid"
fi
if [ -z $LDAP_CID ]; then
LDAP_CID="gidNumber"
fi
fi
fi
# protect the config-file
oldmask=`umask`
umask 026
gunzip ${CONFIG_EX}.gz 2>/dev/null || true
gunzip ${DEBIAN_CONFIG_EX}.gz 2>/dev/null || true
ucf --debconf-ok $CONFIG_EX $CONFIG
ucf --debconf-ok $DEBIAN_CONFIG_EX $DEBIAN_CONFIG
# activate the sqlite driver by default
sed -i 's/\(^driver\W*=\)\(\W*$\)/\1 sqlite/' $CONFIG
if [ "$DO_DEBCONF" = "true" ] && [ -e "$CONFIG" ] && [ -e "$DEBIAN_CONFIG" ]; then
# edit the configs
sed -i -e "s,\(^host\W*=\)\(.*\$\),\1 $DB_HOST,i" \
-e "s,\(^user\W*=\)\(.*\$\),\1 $DB_USER,i" \
-e "s/\(^pass\W*=\)\(.*\$\)/\1 $DB_PASS/i" \
-e "s,\(^db\W*=\)\(.*\$\),\1 $DB_DATABASE,i" \
-e "s,\(^#postmaster\W*=\)\(.*\$\),\1 $POSTMASTER,i" \
-e "s,\(^postmaster\W*=\)\(.*\$\),\1 $POSTMASTER,i" \
-e "s,\(^EFFECTIVE_USER\W*=\)\(.*\$\),\1 dbmail,i" \
-e "s,\(^EFFECTIVE_GROUP\W*=\)\(.*\$\),\1 dbmail,i" \
$CONFIG
if [ "$AUTHDRIVER" = "ldap" ]; then
sed -i -e "s/\(^BASE_DN\W*=\)\(.*\$\)/\1 $LDAP_BASE_DN/i" \
-e "s/\(^HOSTNAME\W*=\)\(.*\$\)/\1 $LDAP_HOST/i" \
-e "s/\(^BIND_PW\W*=\)\(.*\$\)/\1 $LDAP_BIND_PW/i" \
-e "s/\(^BIND_DN\W*=\)\(.*\$\)/\1 $LDAP_BIND_DN/i" \
-e "s/\(^FIELD_UID\W*=\)\(.*\$\)/\1 $LDAP_UID/i" \
-e "s/\(^FIELD_CID\W*=\)\(.*\$\)/\1 $LDAP_CID/i" \
-e "s/\(^authdriver\W*=\)\(.*\$\)/\1 ldap/" \
$CONFIG
else
sed -i -re "s/\(^authdriver\W*=\)\(.*\$\)/\1 sql/" \
$CONFIG
fi
umask $oldmask
if [ "$START_IMAPD" = "true" ]; then
sed -i -re 's/^.*START_IMAPD=.*/START_IMAPD=true/i' $DEBIAN_CONFIG
else
sed -i -re 's/^.*START_IMAPD=.*/#START_IMAPD=true/i' $DEBIAN_CONFIG
fi
if [ "$START_LMTPD" = "true" ]; then
sed -i -re 's/^.*START_LMTPD=.*/START_LMTPD=true/i' $DEBIAN_CONFIG
else
sed -i -re 's/^.*START_LMTPD=.*/#START_LMTPD=true/i' $DEBIAN_CONFIG
fi
if [ "$START_POP3D" = "true" ]; then
sed -i -re 's/^.*START_POP3D=.*/START_POP3D=true/i' $DEBIAN_CONFIG
else
sed -i -re 's/^.*START_POP3D=.*/#START_POP3D=true/i' $DEBIAN_CONFIG
fi
if [ "$START_SIEVE" = "true" ]; then
sed -i -re 's/^.*START_SIEVE=.*/START_SIEVE=true/i' $DEBIAN_CONFIG
else
sed -i -re 's/^.*START_SIEVE=.*/#START_SIEVE=true/i' $DEBIAN_CONFIG
fi
fi
db_stop
chown dbmail:dbmail $CONFIG /usr/sbin/dbmail-smtp
chmod 0600 $CONFIG
chmod 4755 /usr/sbin/dbmail-smtp
;;
abort-upgrade)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 0
;;
esac
#DEBHELPER#
exit 0
|