-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathentrypoint.sh
executable file
·139 lines (125 loc) · 4.31 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env bash
set -e
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both ${var} and ${fileVar} are set (but are mutually exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
file_env GMAIL_USER
file_env GMAIL_PASSWORD
file_env SES_USER
file_env SES_PASSWORD
file_env SMARTHOST_USER
file_env SMARTHOST_PASSWORD
# Initialize localmacros as an empty file
echo -n "" > /etc/exim4/exim4.conf.localmacros
if [ "$MAILNAME" ]; then
echo "MAIN_HARDCODE_PRIMARY_HOSTNAME = $MAILNAME" > /etc/exim4/exim4.conf.localmacros
echo "$MAILNAME" > /etc/mailname
fi
if [ "${SMTPPORTOUT}" ]; then
awk -v port_var="${SMTPPORTOUT}" '/remote_smtp:/{ n=NR+2 } NR==n{ $0=" driver = smtp\n port = "port_var }1' /etc/exim4/exim4.conf.template > /etc/exim4/exim4.conf.temp
mv /etc/exim4/exim4.conf.temp /etc/exim4/exim4.conf.template
fi
if [ -s "$KEY_PATH" ] && [ -s "$CERTIFICATE_PATH" ]; then
echo "MAIN_TLS_ENABLE = yes" >> /etc/exim4/exim4.conf.localmacros
cp "$KEY_PATH" /etc/exim4/exim.key
cp "$CERTIFICATE_PATH" /etc/exim4/exim.crt
chgrp Debian-exim /etc/exim4/exim.key
chgrp Debian-exim /etc/exim4/exim.crt
chmod 640 /etc/exim4/exim.key
chmod 640 /etc/exim4/exim.crt
else
{
echo "MAIN_TLS_ENABLE = no"
echo "MAIN_TLS_ADVERTISE_HOSTS = !*"
} >> /etc/exim4/exim4.conf.localmacros
fi
if [ -s "$DKIM_KEY_PATH" ]; then
cp "$DKIM_KEY_PATH" /etc/exim4/dkim.key
chown Debian-exim /etc/exim4/dkim.key
chmod 640 /etc/exim4/dkim.key
{
echo "DKIM_DOMAIN = \${lc:\${domain:\$h_from:}}"
echo "DKIM_KEY_FILE = /etc/exim4/dkim.key"
echo "DKIM_PRIVATE_KEY = \${if exists{DKIM_KEY_FILE}{DKIM_KEY_FILE}{0}}"
echo "DKIM_SELECTOR = ${DKIM_SELECTOR:-dkim}"
echo "DKIM_CANON = simple"
} >> /etc/exim4/exim4.conf.localmacros
fi
opts=(
dc_local_interfaces "[${BIND_IP:-0.0.0.0}]:${PORT:-25} ; [${BIND_IP6:-::0}]:${PORT:-25}"
dc_other_hostnames "${OTHER_HOSTNAMES}"
dc_relay_nets "$(ip addr show dev "${NET_DEV:-eth0}" | awk '$1 == "inet" { print $2 }' | xargs | sed 's/ /:/g')${RELAY_NETWORKS}"
)
if [ "$DISABLE_IPV6" ]; then
echo 'disable_ipv6=true' >> /etc/exim4/exim4.conf.localmacros
fi
if [ "$GMAIL_USER" ] && [ "$GMAIL_PASSWORD" ]; then
opts+=(
dc_eximconfig_configtype 'smarthost'
dc_smarthost 'smtp.gmail.com::587'
dc_relay_domains "${RELAY_DOMAINS}"
)
echo "*.gmail.com:$GMAIL_USER:$GMAIL_PASSWORD" > /etc/exim4/passwd.client
elif [ "$SES_USER" ] && [ "$SES_PASSWORD" ]; then
opts+=(
dc_eximconfig_configtype 'smarthost'
dc_smarthost "email-smtp.${SES_REGION:=us-east-1}.amazonaws.com::${SES_PORT:=587}"
dc_relay_domains "${RELAY_DOMAINS}"
)
echo "*.amazonaws.com:$SES_USER:$SES_PASSWORD" > /etc/exim4/passwd.client
# Allow to specify an arbitrary smarthost.
# Parameters: SMARTHOST_USER, SMARTHOST_PASSWORD: authentication parameters
# SMARTHOST_ALIASES: list of aliases to puth auth data for (semicolon separated)
# SMARTHOST_ADDRESS, SMARTHOST_PORT: connection parameters.
elif [ "$SMARTHOST_ADDRESS" ] ; then
opts+=(
dc_eximconfig_configtype 'smarthost'
dc_smarthost "${SMARTHOST_ADDRESS}::${SMARTHOST_PORT-25}"
dc_relay_domains "${RELAY_DOMAINS}"
)
rm -f /etc/exim4/passwd.client
if [ "$SMARTHOST_ALIASES" ] && [ "$SMARTHOST_USER" ] && [ "$SMARTHOST_PASSWORD" ] ; then
echo "$SMARTHOST_ALIASES;" | while read -r -d ";" alias; do
echo "${alias}:$SMARTHOST_USER:$SMARTHOST_PASSWORD" >> /etc/exim4/passwd.client
done
fi
elif [ "$RELAY_DOMAINS" ]; then
opts+=(
dc_relay_domains "${RELAY_DOMAINS}"
dc_eximconfig_configtype 'internet'
)
else
opts+=(
dc_eximconfig_configtype 'internet'
)
fi
# allow to add additional macros by bind-mounting a file
if [ -f /etc/exim4/_docker_additional_macros ]; then
cat /etc/exim4/_docker_additional_macros >> /etc/exim4/exim4.conf.localmacros
fi
# allow using split-file config instead of monolithic config
if [ "${USE_SPLIT_CONFIG:-false}" == "true" ]; then
opts+=(
dc_use_split_config "true"
)
fi
/bin/set-exim4-update-conf "${opts[@]}"
exec "$@"