This repository has been archived by the owner on Jul 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 324
/
run.sh
executable file
·155 lines (128 loc) · 3.83 KB
/
run.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
export FQDN
export DOMAIN
export VMAILUID
export VMAILGID
export VMAIL_SUBDIR
export DBDRIVER
export DBHOST
export DBPORT
export DBNAME
export DBUSER
export REDIS_HOST
export REDIS_PORT
export REDIS_PASS
export REDIS_NUMB
export DISABLE_CLAMAV
export DISABLE_DNS_RESOLVER
FQDN=${FQDN:-$(hostname --fqdn)}
DOMAIN=${DOMAIN:-$(hostname --domain)}
VMAILUID=${VMAILUID:-1024}
VMAILGID=${VMAILGID:-1024}
VMAIL_SUBDIR=${VMAIL_SUBDIR:-"mail"}
DBDRIVER=${DBDRIVER:-mysql}
DBHOST=${DBHOST:-mariadb}
DBNAME=${DBNAME:-postfix}
DBUSER=${DBUSER:-postfix}
if [ "$DBDRIVER" = "ldap" ]; then
DBPORT=${DBPORT:-389}
else
DBPORT=${DBPORT:-3306}
fi
REDIS_HOST=${REDIS_HOST:-redis}
REDIS_PORT=${REDIS_PORT:-6379}
REDIS_PASS=$([ -f "$REDIS_PASS" ] && cat "$REDIS_PASS" || echo "${REDIS_PASS:-}")
REDIS_NUMB=${REDIS_NUMB:-0}
DISABLE_CLAMAV=${DISABLE_CLAMAV:-false} # --
DISABLE_DNS_RESOLVER=${DISABLE_DNS_RESOLVER:-false} # --
if [ "$DBDRIVER" = "ldap" ]; then
export LDAP_BIND
export LDAP_BIND_DN
export LDAP_BIND_PW
LDAP_BIND=${LDAP_BIND:-true}
LDAP_BIND_DN=${LDAP_BIND_DN:-}
LDAP_BIND_PW=$([ -f "$LDAP_BIND_PW" ] && cat "$LDAP_BIND_PW" || echo "${LDAP_BIND_PW:-}")
if [ "$LDAP_BIND" = true ]; then
if [ -z "$LDAP_BIND_DN" ]; then
echo "[ERROR] LDAP_BIND_ED must be set !"
exit 1
fi
if [ -z "$LDAP_BIND_PW" ]; then
echo "[ERROR] LDAP_BIND_PW must be set !"
exit 1
fi
fi
else
if [ -z "$DBPASS" ]; then
echo "[ERROR] MariaDB/PostgreSQL database password must be set !"
exit 1
fi
fi
if [ -z "$RSPAMD_PASSWORD" ]; then
echo "[ERROR] Rspamd password must be set !"
exit 1
fi
if [ -z "$FQDN" ]; then
echo "[ERROR] The fully qualified domain name must be set !"
exit 1
fi
if [ -z "$DOMAIN" ]; then
echo "[ERROR] The domain name must be set !"
exit 1
fi
# https://github.com/docker-library/redis/issues/53
if [[ "$REDIS_PORT" =~ [^[:digit:]] ]]; then
REDIS_PORT=6379
fi
# DATABASES HOSTNAME CHECKING
# We need to set these in the hosts file before Unbound takes over for DNS
# ---------------------------------------------------------------------------------------------
# Check mariadb/postgres hostname
grep -q "${DBHOST}" /etc/hosts
if [ $? -ne 0 ]; then
echo "[INFO] MariaDB/PostgreSQL hostname not found in /etc/hosts"
IP=$(dig A ${DBHOST} +short +search)
if [ -n "$IP" ]; then
echo "[INFO] Container IP found, adding a new record in /etc/hosts"
echo "${IP} ${DBHOST}" >> /etc/hosts
else
echo "[ERROR] Container IP not found with embedded DNS server... Abort !"
echo "[ERROR] Check your DBHOST environment variable"
exit 1
fi
else
echo "[INFO] MariaDB/PostgreSQL hostname found in /etc/hosts"
fi
# Check redis hostname
grep -q "${REDIS_HOST}" /etc/hosts
if [ $? -ne 0 ]; then
echo "[INFO] Redis hostname not found in /etc/hosts"
IP=$(dig A ${REDIS_HOST} +short +search)
if [ -n "$IP" ]; then
echo "[INFO] Container IP found, adding a new record in /etc/hosts"
echo "${IP} ${REDIS_HOST}" >> /etc/hosts
else
echo "[ERROR] Container IP not found with embedded DNS server... Abort !"
echo "[ERROR] Check your REDIS_HOST environment variable"
exit 1
fi
else
echo "[INFO] Redis hostname found in /etc/hosts"
fi
# SETUP CONFIG FILES
# ---------------------------------------------------------------------------------------------
certs_helper.sh update_certs
# Make sure that configuration is only run once
if [ ! -f "/etc/configuration_built" ]; then
touch "/etc/configuration_built"
setup.sh
fi
# Unrecoverable errors detection
if [ -f "/etc/setup-error" ]; then
echo "[ERROR] One or more unrecoverable errors have occurred during initial setup. See above to find the cause."
exit 1
fi
# LAUNCH ALL SERVICES
# ---------------------------------------------------------------------------------------------
echo "[INFO] Starting services"
exec s6-svscan /services