generate_config.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. HTTP_PORT=80
  107. HTTP_BIND=0.0.0.0
  108. HTTPS_PORT=443
  109. HTTPS_BIND=0.0.0.0
  110. # ------------------------------
  111. # Other bindings
  112. # ------------------------------
  113. # You should leave that alone
  114. # Format: 11.22.33.44:25 or 0.0.0.0:465 etc.
  115. # Do _not_ use IP:PORT in HTTP(S)_BIND or HTTP(S)_PORT
  116. SMTP_PORT=25
  117. SMTPS_PORT=465
  118. SUBMISSION_PORT=587
  119. IMAP_PORT=143
  120. IMAPS_PORT=993
  121. POP_PORT=110
  122. POPS_PORT=995
  123. SIEVE_PORT=4190
  124. DOVEADM_PORT=127.0.0.1:19991
  125. SQL_PORT=127.0.0.1:13306
  126. # Your timezone
  127. TZ=${MAILCOW_TZ}
  128. # Fixed project name
  129. COMPOSE_PROJECT_NAME=mailcowdockerized
  130. # Set this to "allow" to enable the anyone pseudo user. Disabled by default.
  131. # When enabled, ACL can be created, that apply to "All authenticated users"
  132. # This should probably only be activated on mail hosts, that are used exclusivly by one organisation.
  133. # Otherwise a user might share data with too many other users.
  134. ACL_ANYONE=disallow
  135. # Garbage collector cleanup
  136. # Deleted domains and mailboxes are moved to /var/vmail/_garbage/timestamp_sanitizedstring
  137. # How long should objects remain in the garbage until they are being deleted? (value in minutes)
  138. # Check interval is hourly
  139. MAILDIR_GC_TIME=1440
  140. # Additional SAN for the certificate
  141. #
  142. # You can use wildcard records to create specific names for every domain you add to mailcow.
  143. # Example: Add domains "example.com" and "example.net" to mailcow, change ADDITIONAL_SAN to a value like:
  144. #ADDITIONAL_SAN=imap.*,smtp.*
  145. # This will expand the certificate to "imap.example.com", "smtp.example.com", "imap.example.net", "imap.example.net"
  146. # plus every domain you add in the future.
  147. #
  148. # You can also just add static names...
  149. #ADDITIONAL_SAN=srv1.example.net
  150. # ...or combine wildcard and static names:
  151. #ADDITIONAL_SAN=imap.*,srv1.example.com
  152. #
  153. ADDITIONAL_SAN=
  154. # Skip running ACME (acme-mailcow, Let's Encrypt certs) - y/n
  155. SKIP_LETS_ENCRYPT=n
  156. # Skip IPv4 check in ACME container - y/n
  157. SKIP_IP_CHECK=n
  158. # Skip HTTP verification in ACME container - y/n
  159. SKIP_HTTP_VERIFICATION=n
  160. # Skip ClamAV (clamd-mailcow) anti-virus (Rspamd will auto-detect a missing ClamAV container) - y/n
  161. SKIP_CLAMD=${SKIP_CLAMD}
  162. # Skip Solr on low-memory systems or if you do not want to store a readable index of your mails in solr-vol-1.
  163. SKIP_SOLR=${SKIP_SOLR}
  164. # Solr heap size in MB, there is no recommendation, please see Solr docs.
  165. # Solr is a prone to run OOM and should be monitored. Unmonitored Solr setups are not recommended.
  166. SOLR_HEAP=1024
  167. # Enable watchdog (watchdog-mailcow) to restart unhealthy containers (experimental)
  168. USE_WATCHDOG=n
  169. # Allow admins to log into SOGo as email user (without any password)
  170. ALLOW_ADMIN_EMAIL_LOGIN=n
  171. # Send notifications by mail (no DKIM signature, sent from watchdog@MAILCOW_HOSTNAME)
  172. # Can by multiple rcpts, NO quotation marks
  173. #WATCHDOG_NOTIFY_EMAIL=a@example.com,b@example.com,c@example.com
  174. #WATCHDOG_NOTIFY_EMAIL=
  175. # Notify about banned IP (includes whois lookup)
  176. WATCHDOG_NOTIFY_BAN=y
  177. # Max log lines per service to keep in Redis logs
  178. LOG_LINES=9999
  179. # Internal IPv4 /24 subnet, format n.n.n (expands to n.n.n.0/24)
  180. IPV4_NETWORK=172.22.1
  181. # Internal IPv6 subnet in fc00::/7
  182. IPV6_NETWORK=fd4d:6169:6c63:6f77::/64
  183. # Use this IPv4 for outgoing connections (SNAT)
  184. #SNAT_TO_SOURCE=
  185. # Use this IPv6 for outgoing connections (SNAT)
  186. #SNAT6_TO_SOURCE=
  187. # Create or override API key for web ui
  188. # You _must_ define API_ALLOW_FROM, which is a comma separated list of IPs
  189. # API_KEY allowed chars: a-z, A-Z, 0-9, -
  190. #API_KEY=
  191. #API_ALLOW_FROM=172.22.1.1,127.0.0.1
  192. # mail_home is ~/Maildir
  193. MAILDIR_SUB=Maildir
  194. # SOGo session timeout in minutes
  195. SOGO_EXPIRE_SESSION=480
  196. EOF
  197. mkdir -p data/assets/ssl
  198. chmod 600 mailcow.conf
  199. # copy but don't overwrite existing certificate
  200. cp -n data/assets/ssl-example/*.pem data/assets/ssl/