This commit is contained in:
Thomas VIAL 2016-04-21 01:08:14 +02:00
parent a2109ff287
commit b58d0d33d6
13 changed files with 47 additions and 51 deletions

View file

@ -1,10 +1,12 @@
#!/bin/sh
touch /tmp/vhost.tmp
# Getting domains from mail accounts
while IFS=$'|' read login pass
do
domain=$(echo ${login} | cut -d @ -f2)
echo ${domain} >> /tmp/docker-mailserver/tmp/vhost.tmp
echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-accounts.cf
# Getting domains from mail aliases
@ -14,15 +16,15 @@ do
uname=$(echo ${from} | cut -d @ -f1)
domain=$(echo ${from} | cut -d @ -f2)
# if they are equal it means the line looks like: "user1 other@domain.tld"
test "$uname" != "$domain" && echo ${domain} >> /tmp/docker-mailserver/tmp/vhost.tmp
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-virtual.cf
# Keeping unique entries
if [ -f /tmp/docker-mailserver/tmp/vhost.tmp ]; then
cat /tmp/docker-mailserver/tmp/vhost.tmp | sort | uniq > /etc/postfix/vhost && rm /tmp/docker-mailserver/tmp/vhost.tmp
if [ -f /tmp/vhost.tmp ]; then
cat /tmp/vhost.tmp | sort | uniq > /tmp/vhost && rm /tmp/vhost.tmp
fi
grep -vE '^(\s*$|#)' /etc/postfix/vhost | while read domainname; do
grep -vE '^(\s*$|#)' /tmp/vhost | while read domainname; do
mkdir -p /tmp/docker-mailserver/opendkim/keys/$domainname
if [ ! -f "/tmp/docker-mailserver/opendkim/keys/$domainname/mail.private" ]; then
@ -53,3 +55,10 @@ grep -vE '^(\s*$|#)' /etc/postfix/vhost | while read domainname; do
fi
done
# Creates TrustedHosts if missing
if [ ! -f "/tmp/docker-mailserver/opendkim/TrustedHosts" ]; then
echo "Creating DKIM TrustedHosts";
echo "127.0.0.1" > /tmp/docker-mailserver/opendkim/TrustedHosts
echo "localhost" >> /tmp/docker-mailserver/opendkim/TrustedHosts
fi

View file

@ -1,2 +0,0 @@
127.0.0.1
localhost

View file

@ -5,12 +5,6 @@ die () {
exit 1
}
#
# Preparing
#
mkdir -p /tmp/docker-mailserver/tmp
#
# Users
#
@ -57,7 +51,7 @@ if [ -f /tmp/docker-mailserver/postfix-accounts.cf ]; then
touch "/var/mail/${domain}/${user}/.Sent/maildirfolder"
fi
echo ${domain} >> /tmp/docker-mailserver/tmp/vhost.tmp
echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-accounts.cf
else
echo "==> Warning: 'config/docker-mailserver/postfix-accounts.cf' is not provided. No mail account created."
@ -75,14 +69,14 @@ if [ -f /tmp/docker-mailserver/postfix-virtual.cf ]; then
uname=$(echo ${from} | cut -d @ -f1)
domain=$(echo ${from} | cut -d @ -f2)
# if they are equal it means the line looks like: "user1 other@domain.tld"
test "$uname" != "$domain" && echo ${domain} >> /tmp/docker-mailserver/tmp/vhost.tmp
test "$uname" != "$domain" && echo ${domain} >> /tmp/vhost.tmp
done < /tmp/docker-mailserver/postfix-virtual.cf
else
echo "==> Warning: 'config/postfix-virtual.cf' is not provided. No mail alias/forward created."
fi
if [ -f /tmp/docker-mailserver/tmp/vhost.tmp ]; then
cat /tmp/docker-mailserver/tmp/vhost.tmp | sort | uniq > /etc/postfix/vhost && rm /tmp/docker-mailserver/tmp/vhost.tmp
if [ -f /tmp/vhost.tmp ]; then
cat /tmp/vhost.tmp | sort | uniq > /etc/postfix/vhost && rm /tmp/vhost.tmp
fi
echo "Postfix configurations"