2020-11-19 13:43:15 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-11-29 00:41:07 +00:00
|
|
|
ROOT="$(git rev-parse --show-toplevel)"
|
|
|
|
. $ROOT/docker/mail/mail.env
|
2020-11-19 13:43:15 +00:00
|
|
|
|
2020-11-29 00:41:07 +00:00
|
|
|
cd "${0%/*}"
|
2020-11-22 21:45:43 +00:00
|
|
|
|
2020-11-29 00:41:07 +00:00
|
|
|
if [ -z "${MAIL_SUBDOMAIN}" ]
|
2020-11-19 13:43:15 +00:00
|
|
|
then
|
2020-11-29 00:41:07 +00:00
|
|
|
domain="${MAIL_DOMAIN_ROOT}"
|
2020-11-19 13:43:15 +00:00
|
|
|
else
|
2020-11-29 00:41:07 +00:00
|
|
|
domain="${MAIL_SUBDOMAIN}.${MAIL_DOMAIN_ROOT}"
|
2020-11-19 13:43:15 +00:00
|
|
|
fi
|
|
|
|
|
2020-12-02 20:26:44 +00:00
|
|
|
PASSHASH="{SHA512-CRYPT}$(mkpasswd -m sha-512 -R 5000 ${MAIL_PASSWORD})"
|
2020-11-29 00:41:07 +00:00
|
|
|
|
2020-11-22 21:45:43 +00:00
|
|
|
cat > mail.env <<EOF
|
2020-11-19 13:43:15 +00:00
|
|
|
#!/bin/sh
|
2020-11-29 00:41:07 +00:00
|
|
|
DOMAINNAME=${MAIL_DOMAIN_ROOT}
|
2020-11-19 13:43:15 +00:00
|
|
|
MAILNAME=${domain}
|
2020-11-29 00:41:07 +00:00
|
|
|
SSL_CERT=/etc/letsencrypt/live/${MAIL_DOMAIN_ROOT}/fullchain.pem
|
|
|
|
SSL_KEY=/etc/letsencrypt/live/${MAIL_DOMAIN_ROOT}/privkey.pem
|
|
|
|
MAIL_USER="${MAIL_USER}"
|
|
|
|
USER="${MAIL_USER}@${MAIL_DOMAIN_ROOT}"
|
2020-11-19 13:43:15 +00:00
|
|
|
EOF
|
|
|
|
|
2020-11-29 00:41:07 +00:00
|
|
|
. $ROOT/docker/mail/mail.env
|
2020-11-22 21:45:43 +00:00
|
|
|
|
2020-11-19 13:43:15 +00:00
|
|
|
# Config postfix
|
2020-11-22 21:45:43 +00:00
|
|
|
sed -i -e "s#^\s*myhostname\s*=.*#myhostname = ${MAILNAME}#" config/postfix/main.cf
|
|
|
|
sed -i -e "s#^\s*mydomain\s*=.*#mydomain = ${DOMAINNAME}#" config/postfix/main.cf
|
|
|
|
sed -i -e "s#^\s*smtpd_tls_cert_file\s*=.*#smtpd_tls_cert_file = ${SSL_CERT}#" config/postfix/main.cf
|
|
|
|
sed -i -e "s#^\s*smtpd_tls_key_file\s*=.*#smtpd_tls_key_file = ${SSL_KEY}#" config/postfix/main.cf
|
2020-11-19 13:43:15 +00:00
|
|
|
|
|
|
|
# Config dovecot
|
2020-11-22 21:45:43 +00:00
|
|
|
sed -i -e "s#^\s*ssl_cert\s*=.*#ssl_cert = <${SSL_CERT}#" config/dovecot/dovecot.conf
|
|
|
|
sed -i -e "s#^\s*ssl_key\s*=.*#ssl_key = <${SSL_KEY}#" config/dovecot/dovecot.conf
|
|
|
|
sed -i -e "s#^\s*postmaster_address\s*=.*#postmaster_address = postmaster@${DOMAINNAME}#" config/dovecot/dovecot.conf
|
2020-11-19 13:43:15 +00:00
|
|
|
|
|
|
|
# Config dkim
|
2020-11-22 21:45:43 +00:00
|
|
|
sed -i -e "s/^.*#HOSTNAME/${MAILNAME}#HOSTNAME/" config/opendkim/TrustedHosts
|
2020-11-22 19:14:59 +00:00
|
|
|
|
|
|
|
# Prepare mail user
|
2020-11-22 21:45:43 +00:00
|
|
|
touch config/aliases config/domains config/mailboxes config/passwd
|
2020-11-22 22:13:47 +00:00
|
|
|
echo "${DOMAINNAME} #OK" > config/domains
|
|
|
|
echo "${USER} ${USER}" > config/aliases
|
2020-11-29 00:41:07 +00:00
|
|
|
echo "${USER} ${DOMAINNAME}/${MAIL_USER}/" > config/mailboxes
|
2020-11-22 22:13:47 +00:00
|
|
|
echo "${USER}:${PASSHASH}" > config/passwd
|