Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -o pipefail |
| 4 | |
| 5 | if [[ "$(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 |
| 9 | fi |
| 10 | |
| 11 | if [[ "$(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 Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 15 | exit 1 |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 16 | fi |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 17 | fi |
| 18 | |
| 19 | if 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 |
| 22 | fi |
| 23 | if 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 |
| 26 | fi |
| 27 | |
| 28 | for 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 |
| 30 | done |
| 31 | |
| 32 | if [ -f mailcow.conf ]; then |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 33 | read -r -p "A config file exists and will be overwritten, are you sure you want to continue? [y/N] " response |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 34 | 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 |
| 43 | fi |
| 44 | |
| 45 | echo "Press enter to confirm the detected value '[value]' where applicable or enter a custom value." |
| 46 | while [ -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 |
| 53 | done |
| 54 | |
| 55 | if [ -a /etc/timezone ]; then |
| 56 | DETECTED_TZ=$(cat /etc/timezone) |
| 57 | elif [ -a /etc/localtime ]; then |
| 58 | DETECTED_TZ=$(readlink /etc/localtime|sed -n 's|^.*zoneinfo/||p') |
| 59 | fi |
| 60 | |
| 61 | while [ -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 |
| 68 | done |
| 69 | |
| 70 | MEM_TOTAL=$(awk '/MemTotal/ {print $2}' /proc/meminfo) |
| 71 | |
| 72 | if [ ${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 |
| 84 | else |
| 85 | SKIP_CLAMD=n |
| 86 | fi |
| 87 | |
| 88 | if [ ${MEM_TOTAL} -le "2097152" ]; then |
| 89 | echo "Disabling Solr on low-memory system." |
| 90 | SKIP_SOLR=y |
| 91 | elif [ ${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 |
| 104 | else |
| 105 | SKIP_SOLR=n |
| 106 | fi |
| 107 | |
| 108 | [ ! -f ./data/conf/rspamd/override.d/worker-controller-password.inc ] && echo '# Placeholder' > ./data/conf/rspamd/override.d/worker-controller-password.inc |
| 109 | |
| 110 | cat << 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 | |
| 118 | MAILCOW_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/ |
| 123 | MAILCOW_PASS_SCHEME=BLF-CRYPT |
| 124 | |
| 125 | # ------------------------------ |
| 126 | # SQL database configuration |
| 127 | # ------------------------------ |
| 128 | |
| 129 | DBNAME=mailcow |
| 130 | DBUSER=mailcow |
| 131 | |
| 132 | # Please use long, random alphanumeric strings (A-Za-z0-9) |
| 133 | |
| 134 | DBPASS=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 | head -c 28) |
| 135 | DBROOT=$(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 Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 146 | # 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 Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 149 | |
| 150 | HTTP_PORT=80 |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 151 | HTTP_BIND= |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 152 | |
| 153 | HTTPS_PORT=443 |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 154 | HTTPS_BIND= |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 155 | |
| 156 | # ------------------------------ |
| 157 | # Other bindings |
| 158 | # ------------------------------ |
| 159 | # You should leave that alone |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 160 | # Format: 11.22.33.44:25 or 12.34.56.78:465 etc. |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 161 | |
| 162 | SMTP_PORT=25 |
| 163 | SMTPS_PORT=465 |
| 164 | SUBMISSION_PORT=587 |
| 165 | IMAP_PORT=143 |
| 166 | IMAPS_PORT=993 |
| 167 | POP_PORT=110 |
| 168 | POPS_PORT=995 |
| 169 | SIEVE_PORT=4190 |
| 170 | DOVEADM_PORT=127.0.0.1:19991 |
| 171 | SQL_PORT=127.0.0.1:13306 |
| 172 | SOLR_PORT=127.0.0.1:18983 |
| 173 | REDIS_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 | |
| 179 | TZ=${MAILCOW_TZ} |
| 180 | |
| 181 | # Fixed project name |
| 182 | # Please use lowercase letters only |
| 183 | |
| 184 | COMPOSE_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. |
| 190 | ACL_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 | |
| 197 | MAILDIR_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 | |
| 213 | ADDITIONAL_SAN= |
| 214 | |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 215 | # 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 | |
| 223 | ADDITIONAL_SERVER_NAMES= |
| 224 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 225 | # Skip running ACME (acme-mailcow, Let's Encrypt certs) - y/n |
| 226 | |
| 227 | SKIP_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 |
| 232 | ENABLE_SSL_SNI=n |
| 233 | |
| 234 | # Skip IPv4 check in ACME container - y/n |
| 235 | |
| 236 | SKIP_IP_CHECK=n |
| 237 | |
| 238 | # Skip HTTP verification in ACME container - y/n |
| 239 | |
| 240 | SKIP_HTTP_VERIFICATION=n |
| 241 | |
| 242 | # Skip ClamAV (clamd-mailcow) anti-virus (Rspamd will auto-detect a missing ClamAV container) - y/n |
| 243 | |
| 244 | SKIP_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 | |
| 248 | SKIP_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 | |
| 252 | SKIP_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 | |
| 257 | SOLR_HEAP=1024 |
| 258 | |
| 259 | # Allow admins to log into SOGo as email user (without any password) |
| 260 | |
| 261 | ALLOW_ADMIN_EMAIL_LOGIN=n |
| 262 | |
| 263 | # Enable watchdog (watchdog-mailcow) to restart unhealthy containers |
| 264 | |
| 265 | USE_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) |
| 278 | WATCHDOG_NOTIFY_BAN=n |
| 279 | |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 280 | # Subject for watchdog mails. Defaults to "Watchdog ALERT" followed by the error message. |
| 281 | #WATCHDOG_SUBJECT= |
| 282 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 283 | # 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. |
| 288 | WATCHDOG_EXTERNAL_CHECKS=n |
| 289 | |
Matthias Andreas Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 290 | # Enable watchdog verbose logging |
| 291 | WATCHDOG_VERBOSE=n |
| 292 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 293 | # Max log lines per service to keep in Redis logs |
| 294 | |
| 295 | LOG_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 | |
| 300 | IPV4_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 | |
| 305 | IPV6_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 |
| 327 | MAILDIR_SUB=Maildir |
| 328 | |
| 329 | # SOGo session timeout in minutes |
| 330 | SOGO_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 |
| 336 | DOVECOT_MASTER_USER= |
| 337 | # LEAVE EMPTY IF UNSURE |
| 338 | DOVECOT_MASTER_PASS= |
| 339 | |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 340 | # 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 Benkard | 12a5735 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 344 | # https://mailcow.github.io/mailcow-dockerized-docs/debug-reset_tls/ |
Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 345 | ACME_CONTACT= |
| 346 | |
Matthias Andreas Benkard | b382b10 | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 347 | EOF |
| 348 | |
| 349 | mkdir -p data/assets/ssl |
| 350 | |
| 351 | chmod 600 mailcow.conf |
| 352 | |
| 353 | # copy but don't overwrite existing certificate |
| 354 | echo "Generating snake-oil certificate..." |
| 355 | # Making Willich more popular |
| 356 | openssl 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 |
| 357 | echo "Copying snake-oil certificate..." |
| 358 | cp -n -d data/assets/ssl-example/*.pem data/assets/ssl/ |