postinst is in xmail 1.27-1.2.
This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.
The actual contents of the file can be viewed below.
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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | #! /bin/bash -e
# postinst script for xmail
# Use debconf.
. /usr/share/debconf/confmodule
case "$1" in
configure)
#this is used to see if the user is running dpkg-reconfigure
CUR_VER=`cat /var/lib/xmail/curr_ver`
#these configuration changes don't require xmail to run.
if [ -z "$2" ]; then
#we are installing for the first time
cp /usr/share/xmail/sample/*.tab /etc/xmail
cp /usr/share/xmail/sample/dnsroots /etc/xmail
#make links to xmail config files
ln -s /etc/xmail/*.tab /var/lib/xmail/
ln -s /etc/xmail/dnsroots /var/lib/xmail
chmod 711 /var/lib/xmail
chmod 711 /var/spool/xmail
chmod 711 /var/spool/xmail/spool
chmod 770 /var/spool/xmail/spool/local
chown root:mail /var/spool/xmail/spool/local
chmod 770 /var/spool/xmail/spool/temp
chown root:mail /var/spool/xmail/spool/temp
chmod 700 /var/cache/xmail
else if dpkg --compare-versions "$2" lt "1.21" ; then
echo "E: Backporting from 1.21 is not longer supported. Please purge the old version and reinstall."
fi
fi
SSL_CERT="/var/lib/xmail/server.cert"
SSL_KEY="/var/lib/xmail/server.key"
if [ ! -f "$SSL_CERT" ] && [ ! -f "$SSL_KEY" ];then
echo "I: Creating generic self-signed certificates."
echo "I: (replace with hand-crafted or authorized one if needed)."
cd /etc/ssl/certs
PATH=$PATH:/usr/bin/ssl
HOSTNAME=`hostname -s`
FQDN=`hostname -f`
MAILNAME=`cat /etc/mailname 2> /dev/null || hostname -f`
(openssl req -new -x509 -days 365 -nodes -out $SSL_CERT -keyout $SSL_KEY > /dev/null 2>&1 <<+
.
.
.
XMail mail server
$HOSTNAME.$DOMAINNAME
$FQDN
root@$MAILNAME
+
) || echo "Warning : Bad SSL config, can't generate certificate"
chown root:root $SSL_CERT || true
chmod 0644 $SSL_CERT || true
chown root:root $SSL_KEY || true
chmod 0600 $SSL_KEY || true
fi
chmod +t /var/spool/xmail/spool/temp
chmod +t /var/spool/xmail/spool/local
dpkg-statoverride --force --update --add root mail 2555 /var/lib/xmail/sendmail/xsendmail
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
# Automatically added by dh_installinit
if [ -x "/etc/init.d/xmail" ] || [ -e "/etc/init/xmail.conf" ]; then
if [ ! -e "/etc/init/xmail.conf" ]; then
update-rc.d xmail defaults >/dev/null
fi
invoke-rc.d xmail start || exit $?
fi
# End automatically added section
if [ "$1" = "configure" ]; then
if [ ! -f /var/run/XMail.pid ]; then
echo "E: XMail not started. Skipping configuration...."
exit 0
fi
if [ -z "$2" ] || [ "$2" = "$CUR_VER" ]; then
#Make sure xmail starts
while [ ! -d /var/lib/xmail/spool/22/22/ ] ; do
sleep 1;
done
#there is not much i can do here, xmail's startup sucks
sleep 2
db_get xmail/domainname && domainname="$RET"
db_get xmail/daemonuser && daemonuser="$RET"
db_get xmail/daemonpasswd && daemonpasswd="$RET"
db_get xmail/redirect && redirect="$RET"
if [ "$domainname" = "/etc/mailname" ]; then
if [ -f "/etc/mailname" ]; then
domainname=`cat /etc/mailname`
else
echo "I: Configured to use /etc/mailname but none exists. Using hostname --fqdn."
domainname=`hostname --fqdn`
fi
fi
#add control account data - TAB is a MUST here.
cat >> /etc/xmail/ctrlaccounts.tab <<EOF
"debian" "0100070c040b"
EOF
#maybe we are reconfiguring
if [ -f "/etc/xmail/default_domain" ]; then
old_domain=`cat /etc/xmail/default_domain`
else
old_domain="xmailserver.test"
fi
echo "I: Adding new domain."
#Let's see if the domain exists or is an alias to another domain
EXISTS_D=$(CtrlClnt -s localhost -u debian -p debian domainlist "$domainname")
ALIAS_D=$(CtrlClnt -s localhost -u debian -p debian aliasdomainlist "*" "$domainname")
if [ -z "$EXISTS_D" ] && [ -z "$ALIAS_D" ]; then
CtrlClnt -s localhost -u debian -p debian domainadd $domainname
fi
#an alias domain with the same name exists
if [ "$ALIAS_D" ]; then
CtrlClnt -s localhost -u debian -p debian aliasdomaindel $domainname
CtrlClnt -s localhost -u debian -p debian domainadd $domainname
fi
echo "I: Adding user."
#Let's see if the special user exists
EXISTS=$(CtrlClnt -s localhost -u debian -p debian userlist "$domainname" "$daemonuser")
ALIAS=$(CtrlClnt -s localhost -u debian -p debian aliaslist "$domainname" "$daemonuser")
if [ -z "$ALIAS" ]; then
if [ "$EXISTS" ]; then
CtrlClnt -s localhost -u debian -p debian userpasswd $domainname $daemonuser $daemonpasswd
else
CtrlClnt -s localhost -u debian -p debian useradd $domainname $daemonuser $daemonpasswd U
fi
fi
if [ "$ALIAS" ]; then
CtrlClnt -s localhost -u debian -p debian aliasdel $domainname $daemonuser
CtrlClnt -s localhost -u debian -p debian useradd $domainname $daemonuser $daemonpasswd U
fi
# add aliases
for daemon in root postmaster abuse; do
if [ "$daemonuser" != "$daemon" ]; then
#delete old aliases if needed
EXISTS_U=$(CtrlClnt -s localhost -u debian -p debian userlist "$domainname" "$daemon")
ALIAS_U=$(CtrlClnt -s localhost -u debian -p debian aliaslist "$domainname" "$daemon")
if [ "$ALIAS_U" ]; then
CtrlClnt -s localhost -u debian -p debian aliasdel $domainname $daemon;
fi
#if there is already an daemon account then don't touch it
if [ -z "$EXISTS_U" ]; then
CtrlClnt -s localhost -u debian -p debian aliasadd $domainname $daemon $daemonuser;
fi
fi
done
# domain alias to `hostname`
EXISTS_H=$(CtrlClnt -s localhost -u debian -p debian domainlist "`hostname`")
ALIAS_H=$(CtrlClnt -s localhost -u debian -p debian aliasdomainlist "*" "`hostname`")
if [ -z "$EXISTS_H" ]; then
#make sure we delete the old alias if we have to
if [ "$ALIAS_H" ]; then
CtrlClnt -s localhost -u debian -p debian aliasdomaindel `hostname`
fi
CtrlClnt -s localhost -u debian -p debian aliasdomainadd $domainname `hostname`
else if [ "$domainname" != "`hostname`" ]; then
echo "E: A domain called `hostname` already exists. Please remove it and run dpkg-reconfigure."
fi
fi
#clear out debian install ctrl account
sed -i '/"debian"\t"0100070c040b"/d' /etc/xmail/ctrlaccounts.tab
#add default domain to cmdline
echo $domainname > /etc/xmail/default_domain
#change settings in server.tab and xsendmail
sed -i "s/${old_domain}/${domainname}/g" /etc/xmail/server.tab
sed -i "s/${old_domain}\|xmailserver.test/${domainname}/g" /var/lib/xmail/sendmail/xsendmail
#Add redirect settings in case it's not set
if [ "$redirect" ]; then
mailproc="/var/lib/xmail/domains/${domainname}/${daemonuser}/mailproc.tab"
if [ -f "$mailproc" ]; then
is_redirect=$(cat $mailproc | grep "redirect");
if [ -z "$is_redirect" ]; then ADD=1; fi
else ADD=1
fi
if [ "$ADD" ]; then
echo "I: Adding redirect."
# TAB is a MUST here too.
cat >> /var/lib/xmail/domains/${domainname}/${daemonuser}/mailproc.tab <<EOF
"redirect" "${redirect}"
EOF
fi
fi
#restart xmail
invoke-rc.d xmail restart
fi
fi
exit 0
|