1
0
mirror of https://github.com/tomav/docker-mailserver.git synced 2024-06-27 19:55:40 +02:00

Added a check on needed files with specific message - #17

This commit is contained in:
Thomas VIAL 2015-08-26 10:04:07 +02:00
parent 5b06f844ca
commit c2c7ba70af

View File

@ -1,35 +1,49 @@
#!/bin/sh #!/bin/sh
echo "Regenerating postfix 'vmailbox' and 'virtual' for given users" die () {
echo "# WARNING: this file is auto-generated. Modify accounts.cf in postfix directory on host" > /etc/postfix/vmailbox echo >&2 "$@"
exit 1
}
# Checking that /tmp/postfix/accounts.cf ends with a newline if [ -f /tmp/postfix/accounts.cf ]; then
sed -i -e '$a\' /tmp/postfix/accounts.cf echo "Regenerating postfix 'vmailbox' and 'virtual' for given users"
echo "# WARNING: this file is auto-generated. Modify accounts.cf in postfix directory on host" > /etc/postfix/vmailbox
# Creating users # Checking that /tmp/postfix/accounts.cf ends with a newline
while IFS=$'|' read login pass sed -i -e '$a\' /tmp/postfix/accounts.cf
do
# Setting variables for better readability # Creating users
user=$(echo ${login} | cut -d @ -f1) while IFS=$'|' read login pass
domain=$(echo ${login} | cut -d @ -f2) do
# Let's go! # Setting variables for better readability
echo "user '${user}' for domain '${domain}' with password '********'" user=$(echo ${login} | cut -d @ -f1)
echo "${login} ${domain}/${user}/" >> /etc/postfix/vmailbox domain=$(echo ${login} | cut -d @ -f2)
/usr/sbin/userdb ${login} set uid=5000 gid=5000 home=/var/mail/${domain}/${user} mail=/var/mail/${domain}/${user} # Let's go!
echo "${pass}" | userdbpw -md5 | userdb ${login} set systempw echo "user '${user}' for domain '${domain}' with password '********'"
echo "${pass}" | saslpasswd2 -p -c -u ${domain} ${login} echo "${login} ${domain}/${user}/" >> /etc/postfix/vmailbox
mkdir -p /var/mail/${domain} /usr/sbin/userdb ${login} set uid=5000 gid=5000 home=/var/mail/${domain}/${user} mail=/var/mail/${domain}/${user}
maildirmake /var/mail/${domain}/${user} echo "${pass}" | userdbpw -md5 | userdb ${login} set systempw
echo ${domain} >> /tmp/vhost.tmp echo "${pass}" | saslpasswd2 -p -c -u ${domain} ${login}
done < /tmp/postfix/accounts.cf mkdir -p /var/mail/${domain}
makeuserdb maildirmake /var/mail/${domain}/${user}
# Copying virtual file echo ${domain} >> /tmp/vhost.tmp
cp /tmp/postfix/virtual /etc/postfix/virtual done < /tmp/postfix/accounts.cf
makeuserdb
cat /tmp/vhost.tmp | sort | uniq >> /etc/postfix/vhost && rm /tmp/vhost.tmp
else
echo "==> Warning: '/tmp/postfix/accounts.cf' is not provided. No mail account created."
fi
if [ -f /tmp/postfix/virtual ]; then
# Copying virtual file
cp /tmp/postfix/virtual /etc/postfix/virtual
else
echo "==> Warning: '/tmp/postfix/virtual' is not provided. No mail alias created."
fi
echo "Postfix configurations" echo "Postfix configurations"
postmap /etc/postfix/vmailbox touch /etc/postfix/vmailbox && postmap /etc/postfix/vmailbox
postmap /etc/postfix/virtual touch /etc/postfix/virtual && postmap /etc/postfix/virtual
cat /tmp/vhost.tmp | sort | uniq >> /etc/postfix/vhost && rm /tmp/vhost.tmp
# Adding self-signed SSL certificate if provided in 'postfix/ssl' folder # Adding self-signed SSL certificate if provided in 'postfix/ssl' folder
if [ -e "/tmp/postfix/ssl/$(hostname)-cert.pem" ] \ if [ -e "/tmp/postfix/ssl/$(hostname)-cert.pem" ] \