This repository has been archived by the owner on Jan 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
entrypoint
105 lines (86 loc) · 2.98 KB
/
entrypoint
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
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
set -e
_add_line() {
local check="$1"
local line="$2"
local file="$3"
if ! grep -q "$check" "$file"; then
echo "$line" >> "$file"
fi
}
_log() {
local logfile=/var/log/mail.log
if [ ! -f $logfile ]; then
touch $logfile
chmod 640 $logfile
fi
echo "$(date '+%b %e %H:%I:%S') $(hostname) entrypoint[$$]: $1" >> $logfile
}
_stop() {
/etc/init.d/postfix stop
/etc/init.d/rsyslog stop
_log "Docker entrypoint stop"
}
trap "_stop" SIGINT SIGTERM SIGHUP
_log "Docker entrypoint start"
routes=$(ip route | grep -v default | cut -d' ' -f1 | tr '\n' ' ')
if [ -n "$ROUTE_CUSTOM" ]; then
routes="$routes$ROUTE_CUSTOM"
fi
if [ -n "$routes" ]; then
postconf -e mynetworks="127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 $routes"
postconf -e inet_interfaces=all
fi
postconf -e "inet_protocols=$INET_PROTOCOLS"
postconf -e "myhostname=$HOST"
postconf -e "mydomain=$DOMAIN"
echo $MAILNAME > /etc/mailname
# Email size limits
postconf -e message_size_limit=$MESSAGE_SIZE_LIMIT
# Mail relay host
if [ -n "$MAIL_RELAY_HOST" ] && [ -z "$MAIL_RELAY_PORT" ]; then
postconf -e relayhost=$MAIL_RELAY_HOST;
fi
if [ -n "$MAIL_RELAY_HOST" ] && [ -n "$MAIL_RELAY_PORT" ]; then
postconf -e relayhost="$MAIL_RELAY_HOST:$MAIL_RELAY_PORT";
fi
if [ -n "$MAIL_RELAY_HOST" ] && [ -n "$MAIL_RELAY_USER" ] && [ -n "$MAIL_RELAY_PASS" ]; then
_add_line "$MAIL_RELAY_HOST" "$MAIL_RELAY_HOST $MAIL_RELAY_USER:$MAIL_RELAY_PASS" /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
fi
# Configure SMTPS wrapping if port is 465
if [ "$MAIL_RELAY_PORT" == "465" ]; then
postconf -e smtp_tls_wrappermode=yes
postconf -e smtp_tls_security_level=encrypt
fi
# Force to send all emails to one email address
if [ -n "$MAIL_VIRTUAL_FORCE_TO" ]; then
_add_line "$MAIL_VIRTUAL_FORCE_TO" "/.+@.+/ $MAIL_VIRTUAL_FORCE_TO" /etc/postfix/virtual_regexp
postmap /etc/postfix/virtual_regexp
fi
# Define some virtual email_to addresses
if [ -n "$MAIL_VIRTUAL_DEFAULT" ] && [ -n "$MAIL_VIRTUAL_ADDRESSES" ]; then
for addr in $MAIL_VIRTUAL_ADDRESSES; do
_add_line "$addr" "$addr $MAIL_VIRTUAL_DEFAULT" /etc/postfix/virtual
done
postmap /etc/postfix/virtual
fi
# Define canonical and non-canonical sender domain
if [ -n "$MAIL_CANONICAL_DOMAINS" ]; then
for domain in $MAIL_CANONICAL_DOMAINS; do
_add_line "{1}@$domain" "/^(.+)@${domain//\./\\.}$/ \${1}@$domain" /etc/postfix/sender_canonical_regexp
done
postmap /etc/postfix/sender_canonical_regexp
fi
if [ -n "$MAIL_NON_CANONICAL_DEFAULT" ]; then
_add_line "{2}@$MAIL_NON_CANONICAL_DEFAULT" "/^(.+)@(.+)$/ $MAIL_NON_CANONICAL_PREFIX\${1}-\${2}@$MAIL_NON_CANONICAL_DEFAULT" /etc/postfix/sender_canonical_regexp
postmap /etc/postfix/sender_canonical_regexp
fi
# Make sure no permission problems happen
postfix set-permissions
_log "Docker entrypoint configured"
# Start syslog daemon
/etc/init.d/rsyslog start
# Start Postfix daemon
/etc/init.d/postfix start
$@ & wait ${!}