-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_script.sh
78 lines (70 loc) · 3.23 KB
/
start_script.sh
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
#!/bin/bash
echo "policy-spf unix - n n - - spawn" >> /etc/postfix/master.cf
echo " user=nobody argv=/usr/bin/policyd-spf" >> /etc/postfix/master.cf
echo "myhostname = ${HOSTNAME}.home" >> /etc/postfix/main.cf
if [ ! -z "${POSTFIX_MAILNAME}" ]; then
echo "${POSTFIX_MAILNAME}" > /etc/mailname
echo "myorigin = /etc/mailname" >> /etc/postfix/main.cf
if [ "${POSTFIX_APPEND_MYDESTINATION_CF}" == "yes" ] || [ "${POSTFIX_APPEND_MYDESTINATION_CF}" == "true" ]; then
echo "mydestination = \$myhostname, ${POSTFIX_MAILNAME}, ${HOSTNAME}, localhost.localdomain, localhost" >> /etc/postfix/main.cf
fi
else
if [ "${POSTFIX_APPEND_MYDESTINATION_CF}" == "yes" ] || [ "${POSTFIX_APPEND_MYDESTINATION_CF}" == "true" ]; then
echo "mydestination = \$myhostname, ${HOSTNAME}, localhost.localdomain, localhost" >> /etc/postfix/main.cf
fi
fi
if [ ! -z "${POSTFIX_TLS_CERT_PATH}" ]; then
echo "smtpd_tls_cert_file=${POSTFIX_TLS_CERT_PATH}" >> /etc/postfix/main.cf
echo "smtpd_tls_key_file=${POSTFIX_TLS_KEY_PATH}" >> /etc/postfix/main.cf
chown postfix:postfix ${POSTFIX_TLS_CERT_PATH}
chown postfix:postfix ${POSTFIX_TLS_KEY_PATH}
chmod 644 ${POSTFIX_TLS_CERT_PATH}
chmod 600 ${POSTFIX_TLS_KEY_PATH}
fi
if [ "${POSTFIX_APPEND_VIRTUAL_ALIAS_CF}" == "yes" ] || [ "${POSTFIX_APPEND_VIRTUAL_ALIAS_CF}" == "true" ]; then
echo "virtual_alias_domains = ${POSTFIX_DOMAIN}" >> /etc/postfix/main.cf
echo "virtual_alias_maps = hash:/etc/postfix/virtual" >> /etc/postfix/main.cf
fi
if [ ! -s /etc/postfix/virtual ] && [ ! -z "${POSTFIX_RELAY_TO_ADDRESS}" ]; then
echo "@${POSTFIX_DOMAIN} ${POSTFIX_RELAY_TO_ADDRESS}" >> /etc/postfix/virtual
fi
if [ -s /etc/postfix/virtual ]; then
postmap /etc/postfix/virtual
fi
if [ ! -s /etc/mail/dkim-keys/${POSTFIX_DOMAIN} ]; then
mkdir -p /etc/mail/dkim-keys/${POSTFIX_DOMAIN}
cd /etc/mail/dkim-keys/${POSTFIX_DOMAIN}
opendkim-genkey -d ${POSTFIX_DOMAIN} --append-domain --subdomains
fi
echo "SET UP YOUR DKIM PUBLIC KEY ON default._domainkey.${POSTFIX_DOMAIN} IN TXT DNS RECORD:"
cat /etc/mail/dkim-keys/$POSTFIX_DOMAIN/default.txt
chown opendkim:opendkim /etc/mail/dkim-keys/${POSTFIX_DOMAIN}/default.private
chmod 600 /etc/mail/dkim-keys/${POSTFIX_DOMAIN}/default.private
chown opendkim:opendkim /etc/mail/dkim-keys/${POSTFIX_DOMAIN}/default.txt
chmod 600 /etc/mail/dkim-keys/${POSTFIX_DOMAIN}/default.txt
echo "KeyFile /etc/mail/dkim-keys/${POSTFIX_DOMAIN}/default.private" >> /etc/opendkim.conf
echo "Domain ${POSTFIX_DOMAIN}" >> /etc/opendkim.conf
echo "TrustedAuthservIDs smtp.${POSTFIX_DOMAIN}, mail.${POSTFIX_DOMAIN}, ${POSTFIX_DOMAIN}" >> /etc/opendmarc.conf
# postfix start-fg can be used instead without rsyslog or any of the lines below, though it is not nearly as verbose
service rsyslog start
service opendkim start
service opendmarc start
service postfix start
i=0
while [ $i -lt 5 ]
do
((i++))
if test -f "/var/log/mail.log"; then
echo "Tailing /var/log/mail.log ..."
break
fi
echo "Waiting 1s for postfix to produce a log file to tail..."
sleep 1
done
tail -f /var/log/mail.log &
# ensure container is terminated when postfix stops
while service postfix status > /dev/null
do
sleep 1
done
kill -HUP $!