2015-03-28 14:59:15 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2015-07-16 17:35:11 +00:00
|
|
|
echo "Regenerating postfix 'vmailbox' and 'virtual' for given users"
|
|
|
|
# rm /etc/postfix/virtual
|
|
|
|
# rm /etc/postfix/virtual.db
|
|
|
|
# rm /etc/postfix/vmailbox
|
|
|
|
# rm /etc/postfix/vmailbox.db
|
2015-08-05 10:09:53 +00:00
|
|
|
echo "# WARNING: this file is auto-generated. Modify accounts.cf in postfix directory on host" > /etc/postfix/vmailbox
|
|
|
|
echo "# WARNING: this file is auto-generated. Modify redirects.cf in postfix directory on host" > /etc/postfix/virtual
|
2015-08-05 09:58:10 +00:00
|
|
|
# Creating users
|
|
|
|
while IFS=$'|' read -r login pass
|
2015-03-28 14:59:15 +00:00
|
|
|
do
|
2015-07-16 17:35:11 +00:00
|
|
|
|
2015-05-02 17:05:34 +00:00
|
|
|
# Setting variables for better readability
|
|
|
|
user=$(echo ${login} | cut -d @ -f1)
|
|
|
|
domain=$(echo ${login} | cut -d @ -f2)
|
|
|
|
|
|
|
|
# Let's go!
|
2015-07-16 17:35:11 +00:00
|
|
|
echo "user '${user}' for domain '${domain}' with password '********'"
|
2015-05-02 17:05:34 +00:00
|
|
|
echo "${login} ${domain}/${user}/" >> /etc/postfix/vmailbox
|
|
|
|
userdb ${login} set uid=5000 gid=5000 home=/var/mail/${domain}/${user} mail=/var/mail/${domain}/${user}
|
|
|
|
echo "${pass}" | userdbpw -md5 | userdb ${login} set systempw
|
|
|
|
echo "${pass}" | saslpasswd2 -p -c -u ${domain} ${login}
|
|
|
|
mkdir -p /var/mail/${domain}
|
|
|
|
maildirmake /var/mail/${domain}/${user}
|
|
|
|
echo ${domain} >> /tmp/vhost.tmp
|
2015-07-16 17:35:11 +00:00
|
|
|
done < /tmp/postfix/accounts.cf
|
|
|
|
makeuserdb
|
2015-08-05 10:09:53 +00:00
|
|
|
|
2015-08-05 09:58:10 +00:00
|
|
|
#creating virtuals
|
|
|
|
while IFS=$'|' read -r from to
|
|
|
|
do
|
|
|
|
echo "from : '$from' aliases: '$to'"
|
|
|
|
# Let's go!
|
|
|
|
echo "$from\t$to" >> /etc/postfix/virtual
|
|
|
|
done < /tmp/postfix/redirects.cf
|
2015-05-02 17:05:34 +00:00
|
|
|
|
2015-03-31 15:28:13 +00:00
|
|
|
echo "Postfix configurations"
|
2015-03-28 14:59:15 +00:00
|
|
|
postmap /etc/postfix/vmailbox
|
2015-07-16 17:35:11 +00:00
|
|
|
postmap /etc/postfix/virtual
|
2015-03-31 17:31:18 +00:00
|
|
|
sed -i -r 's/DOCKER_MAIL_DOMAIN/'"$docker_mail_domain"'/g' /etc/postfix/main.cf
|
|
|
|
cat /tmp/vhost.tmp | sort | uniq >> /etc/postfix/vhost && rm /tmp/vhost.tmp
|
2015-03-28 14:59:15 +00:00
|
|
|
|
|
|
|
echo "Fixing permissions"
|
|
|
|
chown -R 5000:5000 /var/mail
|
2015-03-29 12:07:56 +00:00
|
|
|
mkdir -p /var/log/clamav && chown -R clamav:root /var/log/clamav
|
2015-03-28 14:59:15 +00:00
|
|
|
|
|
|
|
echo "Creating /etc/mailname"
|
|
|
|
echo $docker_mail_domain > /etc/mailname
|
|
|
|
|
2015-07-04 13:54:40 +00:00
|
|
|
echo "Configuring Spamassassin"
|
|
|
|
echo "required_hits 5.0" >> /etc/mail/spamassassin/local.cf
|
|
|
|
echo "report_safe 0" >> /etc/mail/spamassassin/local.cf
|
|
|
|
echo "required_score 5" >> /etc/mail/spamassassin/local.cf
|
|
|
|
echo "rewrite_header Subject ***SPAM***" >> /etc/mail/spamassassin/local.cf
|
2015-07-16 17:35:11 +00:00
|
|
|
cp /tmp/spamassassin/rules.cf /etc/spamassassin/
|
2015-07-04 13:54:40 +00:00
|
|
|
|
2015-03-28 14:59:15 +00:00
|
|
|
echo "Starting daemons"
|
2015-03-29 12:07:56 +00:00
|
|
|
/etc/init.d/rsyslog start
|
2015-03-28 14:59:15 +00:00
|
|
|
/etc/init.d/fam start
|
|
|
|
/etc/init.d/saslauthd start
|
|
|
|
/etc/init.d/courier-authdaemon start
|
|
|
|
/etc/init.d/courier-imap start
|
2015-03-31 17:31:18 +00:00
|
|
|
/etc/init.d/courier-imap-ssl start
|
2015-03-28 14:59:15 +00:00
|
|
|
/etc/init.d/spamassassin start
|
|
|
|
/etc/init.d/clamav-daemon start
|
|
|
|
/etc/init.d/amavis start
|
|
|
|
/etc/init.d/postfix start
|
|
|
|
|
|
|
|
echo "Listing SASL users"
|
|
|
|
sasldblistusers2
|
|
|
|
|
2015-03-29 12:07:56 +00:00
|
|
|
echo "Starting..."
|
2015-03-31 14:36:53 +00:00
|
|
|
tail -f /var/log/mail.log
|