generate_config.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 "2621440" ]; then
  46. echo "Installed memory is <= 2.5 GiB. It is recommended to disable ClamAV to prevent out-of-memory situations."
  47. echo "ClamAV can be re-enabled by setting SKIP_CLAMD=n in mailcow.conf."
  48. read -r -p "Do you want to disable ClamAV now? [Y/n] " response
  49. case $response in
  50. [nN][oO]|[nN])
  51. SKIP_CLAMD=n
  52. ;;
  53. *)
  54. SKIP_CLAMD=y
  55. ;;
  56. esac
  57. else
  58. SKIP_CLAMD=n
  59. fi
  60. if [ ${MEM_TOTAL} -le "2097152" ]; then
  61. echo "Disabling Solr on low-memory system."
  62. SKIP_SOLR=y
  63. elif [ ${MEM_TOTAL} -le "3670016" ]; then
  64. echo "Installed memory is <= 3.5 GiB. It is recommended to disable Solr to prevent out-of-memory situations."
  65. 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."
  66. 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."
  67. read -r -p "Do you want to disable Solr now? [Y/n] " response
  68. case $response in
  69. [nN][oO]|[nN])
  70. SKIP_SOLR=n
  71. ;;
  72. *)
  73. SKIP_SOLR=y
  74. ;;
  75. esac
  76. else
  77. SKIP_SOLR=n
  78. fi
  79. [ ! -f ./data/conf/rspamd/override.d/worker-controller-password.inc ] && echo '# Placeholder' > ./data/conf/rspamd/override.d/worker-controller-password.inc
  80. cat << EOF > mailcow.conf
  81. # ------------------------------
  82. # mailcow web ui configuration
  83. # ------------------------------
  84. # example.org is _not_ a valid hostname, use a fqdn here.
  85. # Default admin user is "admin"
  86. # Default password is "moohoo"
  87. MAILCOW_HOSTNAME=${MAILCOW_HOSTNAME}
  88. # ------------------------------
  89. # SQL database configuration
  90. # ------------------------------
  91. DBNAME=mailcow
  92. DBUSER=mailcow
  93. # Please use long, random alphanumeric strings (A-Za-z0-9)
  94. DBPASS=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 | head -c 28)
  95. DBROOT=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 | head -c 28)
  96. # ------------------------------
  97. # HTTP/S Bindings
  98. # ------------------------------
  99. # You should use HTTPS, but in case of SSL offloaded reverse proxies:
  100. HTTP_PORT=80
  101. HTTP_BIND=0.0.0.0
  102. HTTPS_PORT=443
  103. HTTPS_BIND=0.0.0.0
  104. # ------------------------------
  105. # Other bindings
  106. # ------------------------------
  107. # You should leave that alone
  108. # Format: 11.22.33.44:25 or 0.0.0.0:465 etc.
  109. # Do _not_ use IP:PORT in HTTP(S)_BIND or HTTP(S)_PORT
  110. SMTP_PORT=25
  111. SMTPS_PORT=465
  112. SUBMISSION_PORT=587
  113. IMAP_PORT=143
  114. IMAPS_PORT=993
  115. POP_PORT=110
  116. POPS_PORT=995
  117. SIEVE_PORT=4190
  118. DOVEADM_PORT=127.0.0.1:19991
  119. SQL_PORT=127.0.0.1:13306
  120. # Your timezone
  121. TZ=${MAILCOW_TZ}
  122. # Fixed project name
  123. COMPOSE_PROJECT_NAME=mailcowdockerized
  124. # Set this to "allow" to enable the anyone pseudo user. Disabled by default.
  125. # When enabled, ACL can be created, that apply to "All authenticated users"
  126. # This should probably only be activated on mail hosts, that are used exclusivly by one organisation.
  127. # Otherwise a user might share data with too many other users.
  128. ACL_ANYONE=disallow
  129. # Garbage collector cleanup
  130. # Deleted domains and mailboxes are moved to /var/vmail/_garbage/timestamp_sanitizedstring
  131. # How long should objects remain in the garbage until they are being deleted? (value in minutes)
  132. # Check interval is hourly
  133. MAILDIR_GC_TIME=1440
  134. # Additional SAN for the certificate
  135. #
  136. # You can use wildcard records to create specific names for every domain you add to mailcow.
  137. # Example: Add domains "example.com" and "example.net" to mailcow, change ADDITIONAL_SAN to a value like:
  138. #ADDITIONAL_SAN=imap.*,smtp.*
  139. # This will expand the certificate to "imap.example.com", "smtp.example.com", "imap.example.net", "imap.example.net"
  140. # plus every domain you add in the future.
  141. #
  142. # You can also just add static names...
  143. #ADDITIONAL_SAN=srv1.example.net
  144. # ...or combine wildcard and static names:
  145. #ADDITIONAL_SAN=imap.*,srv1.example.com
  146. #
  147. ADDITIONAL_SAN=
  148. # Skip running ACME (acme-mailcow, Let's Encrypt certs) - y/n
  149. SKIP_LETS_ENCRYPT=n
  150. # Skip IPv4 check in ACME container - y/n
  151. SKIP_IP_CHECK=n
  152. # Skip ClamAV (clamd-mailcow) anti-virus (Rspamd will auto-detect a missing ClamAV container) - y/n
  153. SKIP_CLAMD=${SKIP_CLAMD}
  154. # Skip Solr on low-memory systems
  155. SKIP_SOLR=${SKIP_SOLR}
  156. # Solr heap size in MB, there is no recommendation, please see Solr docs.
  157. # Solr is a prone to run OOM and should be monitored. Unmonitored Solr setups are not recommended.
  158. SOLR_HEAP=1024
  159. # Enable watchdog (watchdog-mailcow) to restart unhealthy containers (experimental)
  160. USE_WATCHDOG=n
  161. # Send notifications by mail (no DKIM signature, sent from watchdog@MAILCOW_HOSTNAME)
  162. # Can by multiple rcpts, NO quotation marks
  163. #WATCHDOG_NOTIFY_EMAIL=a@example.com,b@example.com,c@example.com
  164. #WATCHDOG_NOTIFY_EMAIL=
  165. # Max log lines per service to keep in Redis logs
  166. LOG_LINES=9999
  167. # Internal IPv4 /24 subnet, format n.n.n (expands to n.n.n.0/24)
  168. IPV4_NETWORK=172.22.1
  169. # Internal IPv6 subnet in fc00::/7
  170. IPV6_NETWORK=fd4d:6169:6c63:6f77::/64
  171. # Use this IPv4 for outgoing connections (SNAT)
  172. #SNAT_TO_SOURCE=
  173. # Use this IPv6 for outgoing connections (SNAT)
  174. #SNAT6_TO_SOURCE=
  175. # Create or override API key for web uI
  176. # You _must_ define API_ALLOW_FROM, which is a comma separated list of IPs
  177. # API_KEY allowed chars: a-z, A-Z, 0-9, -
  178. #API_KEY=
  179. #API_ALLOW_FROM=127.0.0.1,1.2.3.4
  180. EOF
  181. mkdir -p data/assets/ssl
  182. # copy but don't overwrite existing certificate
  183. cp -n data/assets/ssl-example/*.pem data/assets/ssl/