generate_config.sh 7.2 KB

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