blob: 67ff3acf854c131ecf73b308b0b67f4f03b5bcb2 [file] [log] [blame]
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +01001#!/usr/bin/env bash
2
3set -o pipefail
4
5if [[ "$(uname -r)" =~ ^4\.15\.0-60 ]]; then
6 echo "DO NOT RUN mailcow ON THIS UBUNTU KERNEL!";
7 echo "Please update to 5.x or use another distribution."
8 exit 1
9fi
10
11if [[ "$(uname -r)" =~ ^4\.4\. ]]; then
12 if grep -q Ubuntu <<< $(uname -a); then
13 echo "DO NOT RUN mailcow ON THIS UBUNTU KERNEL!";
14 echo "Please update to linux-generic-hwe-16.04 by running \"apt-get install --install-recommends linux-generic-hwe-16.04\""
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +010015 exit 1
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010016 fi
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010017fi
18
19if grep --help 2>&1 | grep -q -i "busybox"; then
20 echo "BusyBox grep detected, please install gnu grep, \"apk add --no-cache --upgrade grep\""
21 exit 1
22fi
23if cp --help 2>&1 | grep -q -i "busybox"; then
24 echo "BusyBox cp detected, please install coreutils, \"apk add --no-cache --upgrade coreutils\""
25 exit 1
26fi
27
28for bin in openssl curl docker-compose docker git awk sha1sum; do
29 if [[ -z $(which ${bin}) ]]; then echo "Cannot find ${bin}, exiting..."; exit 1; fi
30done
31
32if [ -f mailcow.conf ]; then
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020033 read -r -p "A config file exists and will be overwritten, are you sure you want to continue? [y/N] " response
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +010034 case $response in
35 [yY][eE][sS]|[yY])
36 mv mailcow.conf mailcow.conf_backup
37 chmod 600 mailcow.conf_backup
38 ;;
39 *)
40 exit 1
41 ;;
42 esac
43fi
44
45echo "Press enter to confirm the detected value '[value]' where applicable or enter a custom value."
46while [ -z "${MAILCOW_HOSTNAME}" ]; do
47 read -p "Mail server hostname (FQDN) - this is not your mail domain, but your mail servers hostname: " -e MAILCOW_HOSTNAME
48 DOTS=${MAILCOW_HOSTNAME//[^.]};
49 if [ ${#DOTS} -lt 2 ] && [ ! -z ${MAILCOW_HOSTNAME} ]; then
50 echo "${MAILCOW_HOSTNAME} is not a FQDN"
51 MAILCOW_HOSTNAME=
52 fi
53done
54
55if [ -a /etc/timezone ]; then
56 DETECTED_TZ=$(cat /etc/timezone)
57elif [ -a /etc/localtime ]; then
58 DETECTED_TZ=$(readlink /etc/localtime|sed -n 's|^.*zoneinfo/||p')
59fi
60
61while [ -z "${MAILCOW_TZ}" ]; do
62 if [ -z "${DETECTED_TZ}" ]; then
63 read -p "Timezone: " -e MAILCOW_TZ
64 else
65 read -p "Timezone [${DETECTED_TZ}]: " -e MAILCOW_TZ
66 [ -z "${MAILCOW_TZ}" ] && MAILCOW_TZ=${DETECTED_TZ}
67 fi
68done
69
70MEM_TOTAL=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
71
72if [ ${MEM_TOTAL} -le "2621440" ]; then
73 echo "Installed memory is <= 2.5 GiB. It is recommended to disable ClamAV to prevent out-of-memory situations."
74 echo "ClamAV can be re-enabled by setting SKIP_CLAMD=n in mailcow.conf."
75 read -r -p "Do you want to disable ClamAV now? [Y/n] " response
76 case $response in
77 [nN][oO]|[nN])
78 SKIP_CLAMD=n
79 ;;
80 *)
81 SKIP_CLAMD=y
82 ;;
83 esac
84else
85 SKIP_CLAMD=n
86fi
87
88if [ ${MEM_TOTAL} -le "2097152" ]; then
89 echo "Disabling Solr on low-memory system."
90 SKIP_SOLR=y
91elif [ ${MEM_TOTAL} -le "3670016" ]; then
92 echo "Installed memory is <= 3.5 GiB. It is recommended to disable Solr to prevent out-of-memory situations."
93 echo "Solr is a prone to run OOM and should be monitored. The default Solr heap size is 1024 MiB and should be set in mailcow.conf according to your expected load."
94 echo "Solr can be re-enabled by setting SKIP_SOLR=n in mailcow.conf but will refuse to start with less than 2 GB total memory."
95 read -r -p "Do you want to disable Solr now? [Y/n] " response
96 case $response in
97 [nN][oO]|[nN])
98 SKIP_SOLR=n
99 ;;
100 *)
101 SKIP_SOLR=y
102 ;;
103 esac
104else
105 SKIP_SOLR=n
106fi
107
108[ ! -f ./data/conf/rspamd/override.d/worker-controller-password.inc ] && echo '# Placeholder' > ./data/conf/rspamd/override.d/worker-controller-password.inc
109
110cat << EOF > mailcow.conf
111# ------------------------------
112# mailcow web ui configuration
113# ------------------------------
114# example.org is _not_ a valid hostname, use a fqdn here.
115# Default admin user is "admin"
116# Default password is "moohoo"
117
118MAILCOW_HOSTNAME=${MAILCOW_HOSTNAME}
119
120# Password hash algorithm
121# Only certain password hash algorithm are supported. For a fully list of supported schemes,
122# see https://mailcow.github.io/mailcow-dockerized-docs/model-passwd/
123MAILCOW_PASS_SCHEME=BLF-CRYPT
124
125# ------------------------------
126# SQL database configuration
127# ------------------------------
128
129DBNAME=mailcow
130DBUSER=mailcow
131
132# Please use long, random alphanumeric strings (A-Za-z0-9)
133
134DBPASS=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 | head -c 28)
135DBROOT=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 | head -c 28)
136
137# ------------------------------
138# HTTP/S Bindings
139# ------------------------------
140
141# You should use HTTPS, but in case of SSL offloaded reverse proxies:
142# Might be important: This will also change the binding within the container.
143# If you use a proxy within Docker, point it to the ports you set below.
144# Do _not_ use IP:PORT in HTTP(S)_BIND or HTTP(S)_PORT
145# IMPORTANT: Do not use port 8081, 9081 or 65510!
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200146# Example: HTTP_BIND=1.2.3.4
147# For IPv4 and IPv6 leave it empty: HTTP_BIND= & HTTPS_PORT=
148# For IPv6 see https://mailcow.github.io/mailcow-dockerized-docs/firststeps-ip_bindings/
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100149
150HTTP_PORT=80
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200151HTTP_BIND=
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100152
153HTTPS_PORT=443
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200154HTTPS_BIND=
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100155
156# ------------------------------
157# Other bindings
158# ------------------------------
159# You should leave that alone
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200160# Format: 11.22.33.44:25 or 12.34.56.78:465 etc.
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100161
162SMTP_PORT=25
163SMTPS_PORT=465
164SUBMISSION_PORT=587
165IMAP_PORT=143
166IMAPS_PORT=993
167POP_PORT=110
168POPS_PORT=995
169SIEVE_PORT=4190
170DOVEADM_PORT=127.0.0.1:19991
171SQL_PORT=127.0.0.1:13306
172SOLR_PORT=127.0.0.1:18983
173REDIS_PORT=127.0.0.1:7654
174
175# Your timezone
176# See https://en.wikipedia.org/wiki/List_of_tz_database_time_zones for a list of timezones
177# Use the row named 'TZ database name' + pay attention for 'Notes' row
178
179TZ=${MAILCOW_TZ}
180
181# Fixed project name
182# Please use lowercase letters only
183
184COMPOSE_PROJECT_NAME=mailcowdockerized
185
186# Set this to "allow" to enable the anyone pseudo user. Disabled by default.
187# When enabled, ACL can be created, that apply to "All authenticated users"
188# This should probably only be activated on mail hosts, that are used exclusivly by one organisation.
189# Otherwise a user might share data with too many other users.
190ACL_ANYONE=disallow
191
192# Garbage collector cleanup
193# Deleted domains and mailboxes are moved to /var/vmail/_garbage/timestamp_sanitizedstring
194# How long should objects remain in the garbage until they are being deleted? (value in minutes)
195# Check interval is hourly
196
197MAILDIR_GC_TIME=7200
198
199# Additional SAN for the certificate
200#
201# You can use wildcard records to create specific names for every domain you add to mailcow.
202# Example: Add domains "example.com" and "example.net" to mailcow, change ADDITIONAL_SAN to a value like:
203#ADDITIONAL_SAN=imap.*,smtp.*
204# This will expand the certificate to "imap.example.com", "smtp.example.com", "imap.example.net", "imap.example.net"
205# plus every domain you add in the future.
206#
207# You can also just add static names...
208#ADDITIONAL_SAN=srv1.example.net
209# ...or combine wildcard and static names:
210#ADDITIONAL_SAN=imap.*,srv1.example.com
211#
212
213ADDITIONAL_SAN=
214
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200215# Additional server names for mailcow UI
216#
217# Specify alternative addresses for the mailcow UI to respond to
218# This is useful when you set mail.* as ADDITIONAL_SAN and want to make sure mail.maildomain.com will always point to the mailcow UI.
219# If the server name does not match a known site, Nginx decides by best-guess and may redirect users to the wrong web root.
220# You can understand this as server_name directive in Nginx.
221# Comma separated list without spaces! Example: ADDITIONAL_SERVER_NAMES=a.b.c,d.e.f
222
223ADDITIONAL_SERVER_NAMES=
224
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100225# Skip running ACME (acme-mailcow, Let's Encrypt certs) - y/n
226
227SKIP_LETS_ENCRYPT=n
228
229# Create seperate certificates for all domains - y/n
230# this will allow adding more than 100 domains, but some email clients will not be able to connect with alternative hostnames
231# see https://wiki.dovecot.org/SSL/SNIClientSupport
232ENABLE_SSL_SNI=n
233
234# Skip IPv4 check in ACME container - y/n
235
236SKIP_IP_CHECK=n
237
238# Skip HTTP verification in ACME container - y/n
239
240SKIP_HTTP_VERIFICATION=n
241
242# Skip ClamAV (clamd-mailcow) anti-virus (Rspamd will auto-detect a missing ClamAV container) - y/n
243
244SKIP_CLAMD=${SKIP_CLAMD}
245
246# Skip SOGo: Will disable SOGo integration and therefore webmail, DAV protocols and ActiveSync support (experimental, unsupported, not fully implemented) - y/n
247
248SKIP_SOGO=n
249
250# Skip Solr on low-memory systems or if you do not want to store a readable index of your mails in solr-vol-1.
251
252SKIP_SOLR=${SKIP_SOLR}
253
254# Solr heap size in MB, there is no recommendation, please see Solr docs.
255# Solr is a prone to run OOM and should be monitored. Unmonitored Solr setups are not recommended.
256
257SOLR_HEAP=1024
258
259# Allow admins to log into SOGo as email user (without any password)
260
261ALLOW_ADMIN_EMAIL_LOGIN=n
262
263# Enable watchdog (watchdog-mailcow) to restart unhealthy containers
264
265USE_WATCHDOG=y
266
267# Send watchdog notifications by mail (sent from watchdog@MAILCOW_HOSTNAME)
268# CAUTION:
269# 1. You should use external recipients
270# 2. Mails are sent unsigned (no DKIM)
271# 3. If you use DMARC, create a separate DMARC policy ("v=DMARC1; p=none;" in _dmarc.MAILCOW_HOSTNAME)
272# Multiple rcpts allowed, NO quotation marks, NO spaces
273
274#WATCHDOG_NOTIFY_EMAIL=a@example.com,b@example.com,c@example.com
275#WATCHDOG_NOTIFY_EMAIL=
276
277# Notify about banned IP (includes whois lookup)
278WATCHDOG_NOTIFY_BAN=n
279
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200280# Subject for watchdog mails. Defaults to "Watchdog ALERT" followed by the error message.
281#WATCHDOG_SUBJECT=
282
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100283# Checks if mailcow is an open relay. Requires a SAL. More checks will follow.
284# https://www.servercow.de/mailcow?lang=en
285# https://www.servercow.de/mailcow?lang=de
286# No data is collected. Opt-in and anonymous.
287# Will only work with unmodified mailcow setups.
288WATCHDOG_EXTERNAL_CHECKS=n
289
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100290# Enable watchdog verbose logging
291WATCHDOG_VERBOSE=n
292
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100293# Max log lines per service to keep in Redis logs
294
295LOG_LINES=9999
296
297# Internal IPv4 /24 subnet, format n.n.n (expands to n.n.n.0/24)
298# Use private IPv4 addresses only, see https://en.wikipedia.org/wiki/Private_network#Private_IPv4_addresses
299
300IPV4_NETWORK=172.22.1
301
302# Internal IPv6 subnet in fc00::/7
303# Use private IPv6 addresses only, see https://en.wikipedia.org/wiki/Private_network#Private_IPv6_addresses
304
305IPV6_NETWORK=fd4d:6169:6c63:6f77::/64
306
307# Use this IPv4 for outgoing connections (SNAT)
308
309#SNAT_TO_SOURCE=
310
311# Use this IPv6 for outgoing connections (SNAT)
312
313#SNAT6_TO_SOURCE=
314
315# Create or override an API key for the web UI
316# You _must_ define API_ALLOW_FROM, which is a comma separated list of IPs
317# An API key defined as API_KEY has read-write access
318# An API key defined as API_KEY_READ_ONLY has read-only access
319# Allowed chars for API_KEY and API_KEY_READ_ONLY: a-z, A-Z, 0-9, -
320# You can define API_KEY and/or API_KEY_READ_ONLY
321
322#API_KEY=
323#API_KEY_READ_ONLY=
324#API_ALLOW_FROM=172.22.1.1,127.0.0.1
325
326# mail_home is ~/Maildir
327MAILDIR_SUB=Maildir
328
329# SOGo session timeout in minutes
330SOGO_EXPIRE_SESSION=480
331
332# DOVECOT_MASTER_USER and DOVECOT_MASTER_PASS must both be provided. No special chars.
333# Empty by default to auto-generate master user and password on start.
334# User expands to DOVECOT_MASTER_USER@mailcow.local
335# LEAVE EMPTY IF UNSURE
336DOVECOT_MASTER_USER=
337# LEAVE EMPTY IF UNSURE
338DOVECOT_MASTER_PASS=
339
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200340# Let's Encrypt registration contact information
341# Optional: Leave empty for none
342# This value is only used on first order!
343# Setting it at a later point will require the following steps:
Matthias Andreas Benkard12a57352021-12-28 18:02:04 +0100344# https://mailcow.github.io/mailcow-dockerized-docs/debug-reset_tls/
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +0200345ACME_CONTACT=
346
Matthias Andreas Benkardb382b102021-01-02 15:32:21 +0100347EOF
348
349mkdir -p data/assets/ssl
350
351chmod 600 mailcow.conf
352
353# copy but don't overwrite existing certificate
354echo "Generating snake-oil certificate..."
355# Making Willich more popular
356openssl req -x509 -newkey rsa:4096 -keyout data/assets/ssl-example/key.pem -out data/assets/ssl-example/cert.pem -days 365 -subj "/C=DE/ST=NRW/L=Willich/O=mailcow/OU=mailcow/CN=${MAILCOW_HOSTNAME}" -sha256 -nodes
357echo "Copying snake-oil certificate..."
358cp -n -d data/assets/ssl-example/*.pem data/assets/ssl/