generate_config.sh 7.8 KB

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