generate_config.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #!/bin/bash
  2. set -o pipefail
  3. if grep --help 2>&1 | grep -q -i "busybox"; then
  4. echo "BusybBox grep detected, please install gnu grep, \"apk add --no-cache --upgrade grep\""
  5. exit 1
  6. fi
  7. if cp --help 2>&1 | grep -q -i "busybox"; then
  8. echo "BusybBox cp detected, please install coreutils, \"apk add --no-cache --upgrade coreutils\""
  9. exit 1
  10. fi
  11. if [ -f mailcow.conf ]; then
  12. read -r -p "A config file exists and will be overwritten, are you sure you want to contine? [y/N] " response
  13. case $response in
  14. [yY][eE][sS]|[yY])
  15. mv mailcow.conf mailcow.conf_backup
  16. ;;
  17. *)
  18. exit 1
  19. ;;
  20. esac
  21. fi
  22. echo "Press enter to confirm the detected value '[value]' where applicable or enter a custom value."
  23. while [ -z "${MAILCOW_HOSTNAME}" ]; do
  24. read -p "Hostname (FQDN): " -e MAILCOW_HOSTNAME
  25. DOTS=${MAILCOW_HOSTNAME//[^.]};
  26. if [ ${#DOTS} -lt 2 ] && [ ! -z ${MAILCOW_HOSTNAME} ]; then
  27. echo "${MAILCOW_HOSTNAME} is not a FQDN"
  28. MAILCOW_HOSTNAME=
  29. fi
  30. done
  31. if [ -a /etc/timezone ]; then
  32. DETECTED_TZ=$(cat /etc/timezone)
  33. elif [ -a /etc/localtime ]; then
  34. DETECTED_TZ=$(readlink /etc/localtime|sed -n 's|^.*zoneinfo/||p')
  35. fi
  36. while [ -z "${MAILCOW_TZ}" ]; do
  37. if [ -z "${DETECTED_TZ}" ]; then
  38. read -p "Timezone: " -e MAILCOW_TZ
  39. else
  40. read -p "Timezone [${DETECTED_TZ}]: " -e MAILCOW_TZ
  41. [ -z "${MAILCOW_TZ}" ] && MAILCOW_TZ=${DETECTED_TZ}
  42. fi
  43. done
  44. MEM_TOTAL=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
  45. if [ ${MEM_TOTAL} -le "1572864" ]; then
  46. echo "Installed memory is less than 1.5 GiB. It is recommended to disable ClamAV to prevent out-of-memory situations."
  47. read -r -p "Do you want to disable ClamAV now? ClamAV can be re-enabled by setting SKIP_CLAMD=n in mailcow.conf. [Y/n] " response
  48. case $response in
  49. [nN][oO]|[nN])
  50. SKIP_CLAMD=n
  51. ;;
  52. *)
  53. SKIP_CLAMD=y
  54. ;;
  55. esac
  56. else
  57. SKIP_CLAMD=n
  58. fi
  59. if [ ${MEM_TOTAL} -le "6815744" ]; then
  60. echo "Installed memory is less than 6.5 GiB. It is highly recommended to disable Solr to prevent out-of-memory situations."
  61. echo "Solr is a prone to run OOM and should be monitored. The default Solr heap size is 1024 MiB and should be set according to your expected load in mailcow.conf."
  62. read -r -p "Do you want to disable Solr now (recommended)? Solr can be re-enabled by setting SKIP_SOLR=n in mailcow.conf. [Y/n] " response
  63. case $response in
  64. [nN][oO]|[nN])
  65. SKIP_SOLR=n
  66. ;;
  67. *)
  68. SKIP_SOLR=y
  69. ;;
  70. esac
  71. else
  72. SKIP_SOLR=n
  73. fi
  74. [ ! -f ./data/conf/rspamd/override.d/worker-controller-password.inc ] && echo '# Placeholder' > ./data/conf/rspamd/override.d/worker-controller-password.inc
  75. cat << EOF > mailcow.conf
  76. # ------------------------------
  77. # mailcow web ui configuration
  78. # ------------------------------
  79. # example.org is _not_ a valid hostname, use a fqdn here.
  80. # Default admin user is "admin"
  81. # Default password is "moohoo"
  82. MAILCOW_HOSTNAME=${MAILCOW_HOSTNAME}
  83. # ------------------------------
  84. # SQL database configuration
  85. # ------------------------------
  86. DBNAME=mailcow
  87. DBUSER=mailcow
  88. # Please use long, random alphanumeric strings (A-Za-z0-9)
  89. DBPASS=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 | head -c 28)
  90. DBROOT=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 | head -c 28)
  91. # ------------------------------
  92. # HTTP/S Bindings
  93. # ------------------------------
  94. # You should use HTTPS, but in case of SSL offloaded reverse proxies:
  95. HTTP_PORT=80
  96. HTTP_BIND=0.0.0.0
  97. HTTPS_PORT=443
  98. HTTPS_BIND=0.0.0.0
  99. # ------------------------------
  100. # Other bindings
  101. # ------------------------------
  102. # You should leave that alone
  103. # Format: 11.22.33.44:25 or 0.0.0.0:465 etc.
  104. # Do _not_ use IP:PORT in HTTP(S)_BIND or HTTP(S)_PORT
  105. SMTP_PORT=25
  106. SMTPS_PORT=465
  107. SUBMISSION_PORT=587
  108. IMAP_PORT=143
  109. IMAPS_PORT=993
  110. POP_PORT=110
  111. POPS_PORT=995
  112. SIEVE_PORT=4190
  113. DOVEADM_PORT=127.0.0.1:19991
  114. SQL_PORT=127.0.0.1:13306
  115. # Your timezone
  116. TZ=${MAILCOW_TZ}
  117. # Fixed project name
  118. COMPOSE_PROJECT_NAME=mailcowdockerized
  119. # Garbage collector cleanup
  120. # Deleted domains and mailboxes are moved to /var/vmail/_garbage/timestamp_sanitizedstring
  121. # How long should objects remain in the garbage until they are being deleted? (value in minutes)
  122. # Check interval is hourly
  123. MAILDIR_GC_TIME=1440
  124. # Additional SAN for the certificate
  125. #
  126. # You can use wildcard records to create specific names for every domain you add to mailcow.
  127. # Example: Add domains "example.com" and "example.net" to mailcow, change ADDITIONAL_SAN to a value like:
  128. #ADDITIONAL_SAN=imap.*,smtp.*
  129. # This will expand the certificate to "imap.example.com", "smtp.example.com", "imap.example.net", "imap.example.net"
  130. # plus every domain you add in the future.
  131. #
  132. # You can also just add static names...
  133. #ADDITIONAL_SAN=srv1.example.net
  134. # ...or combine wildcard and static names:
  135. #ADDITIONAL_SAN=imap.*,srv1.example.com
  136. #
  137. ADDITIONAL_SAN=
  138. # Skip running ACME (acme-mailcow, Let's Encrypt certs) - y/n
  139. SKIP_LETS_ENCRYPT=n
  140. # Skip IPv4 check in ACME container - y/n
  141. SKIP_IP_CHECK=n
  142. # Skip ClamAV (clamd-mailcow) anti-virus (Rspamd will auto-detect a missing ClamAV container) - y/n
  143. SKIP_CLAMD=n
  144. # Skip Solr on low-memory systems
  145. SKIP_SOLR=${SKIP_SOLR}
  146. # Solr heap size in MB, there is no recommendation, please see Solr docs.
  147. # Solr is a prone to run OOM and should be monitored. Unmonitored Solr setups are not recommended.
  148. SOLR_HEAP=1024
  149. # Enable watchdog (watchdog-mailcow) to restart unhealthy containers (experimental)
  150. USE_WATCHDOG=n
  151. # Send notifications by mail (no DKIM signature, sent from watchdog@MAILCOW_HOSTNAME)
  152. # Can by multiple rcpts, NO quotation marks
  153. #WATCHDOG_NOTIFY_EMAIL=a@example.com,b@example.com,c@example.com
  154. #WATCHDOG_NOTIFY_EMAIL=
  155. # Max log lines per service to keep in Redis logs
  156. LOG_LINES=9999
  157. # Internal IPv4 /24 subnet, format n.n.n (expands to n.n.n.0/24)
  158. IPV4_NETWORK=172.22.1
  159. # Internal IPv6 subnet in fc00::/7
  160. IPV6_NETWORK=fd4d:6169:6c63:6f77::/64
  161. # Use this IPv4 for outgoing connections (SNAT)
  162. #SNAT_TO_SOURCE=
  163. # Use this IPv6 for outgoing connections (SNAT)
  164. #SNAT6_TO_SOURCE=
  165. # Create or override API key for web uI
  166. # You _must_ define API_ALLOW_FROM, which is a comma separated list of IPs
  167. # API_KEY allowed chars: a-z, A-Z, 0-9, -
  168. #API_KEY=
  169. #API_ALLOW_FROM=127.0.0.1,1.2.3.4
  170. EOF
  171. mkdir -p data/assets/ssl
  172. # copy but don't overwrite existing certificate
  173. cp -n data/assets/ssl-example/*.pem data/assets/ssl/