-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
95 lines (74 loc) · 2.07 KB
/
entrypoint.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/sh
set -e
# Avoid warning: smtputf8_enable is true, but EAI support is not compiled in
echo "smtputf8_enable = no" >> /etc/postfix/main.cf
cat >> /etc/postfix/main.cf << EOF
# limit smtp to loopback interface & compute engine doesn't support ipv6
inet_protocols = ipv4
EOF
# Do we want to modify the config first with the script?
# shellcheck disable=SC1091
[ -f /etc/service/postfix/run.config ] && source /etc/service/postfix/run.config
if [[ -n "$MAILNAME" ]]; then
echo "$MAILNAME" > /etc/mailname
postconf -e myorigin="/etc/mailname"
cat >> /etc/postfix/main.cf <<- EOF
# Force ehlo behavior
smtp_always_send_ehlo = yes
smtp_helo_name = $MAILNAME
EOF
fi
if [[ -n "$MY_NETWORKS" ]]; then
postconf -e mynetworks="$MY_NETWORKS"
fi
if [[ -n "$MY_DESTINATION" ]]; then
postconf -e mydestination="$MY_DESTINATION"
fi
if [[ -n "$ROOT_ALIAS" ]]; then
if [[ -f /etc/aliases ]]; then
sed -i '/^root:/d' /etc/aliases
fi
echo "root: $ROOT_ALIAS" >> /etc/aliases
newaliases
fi
if [[ -n "$RELAY" ]]; then
# setup the relay
cat >> /etc/postfix/main.cf <<- EOF
relayhost = $RELAY
# These lines can be used, if the result is not as expected
debug_peer_list = smtp-relay.gmail.com
debug_peer_level = 2
EOF
fi
if [[ -n "$TLS" ]]; then
# setup tls
cat >> /etc/postfix/main.cf <<- EOF
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
EOF
fi
if [[ -n "$SASL_AUTH" ]]; then
cat >> /etc/postfix/main.cf <<- EOF
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = lmdb:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
EOF
# generate the SASL password map
echo "$RELAY $SASL_AUTH" > /etc/postfix/sasl_passwd
# generate a .db file
postmap /etc/postfix/sasl_passwd
# cleanup
rm /etc/postfix/sasl_passwd
fi
if [[ -f "/usr/libexec/postfix/master" ]]; then
cmd="/usr/libexec/postfix/master"
fi
if [[ -f "/usr/lib/postfix/master" ]]; then
cmd="/usr/lib/postfix/master"
fi
if [[ -z "$cmd" ]]; then
echo "Could not find postfix master in /usr/lib or /usr/libexec"
exit 1
fi
postconf -e maillog_file="/dev/stdout"
exec postfix start-fg