update.sh 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622
  1. #!/usr/bin/env bash
  2. ############## Begin Function Section ##############
  3. check_online_status() {
  4. CHECK_ONLINE_DOMAINS=('https://github.com' 'https://hub.docker.com')
  5. for domain in "${CHECK_ONLINE_DOMAINS[@]}"; do
  6. if timeout 6 curl --head --silent --output /dev/null ${domain}; then
  7. return 0
  8. fi
  9. done
  10. return 1
  11. }
  12. prefetch_images() {
  13. [[ -z ${BRANCH} ]] && { echo -e "\e[33m\nUnknown branch...\e[0m"; exit 1; }
  14. git fetch origin #${BRANCH}
  15. while read image; do
  16. if [[ "${image}" == "robbertkl/ipv6nat" ]]; then
  17. if ! grep -qi "ipv6nat-mailcow" docker-compose.yml || grep -qi "enable_ipv6: false" docker-compose.yml; then
  18. continue
  19. fi
  20. fi
  21. RET_C=0
  22. until docker pull "${image}"; do
  23. RET_C=$((RET_C + 1))
  24. echo -e "\e[33m\nError pulling $image, retrying...\e[0m"
  25. [ ${RET_C} -gt 3 ] && { echo -e "\e[31m\nToo many failed retries, exiting\e[0m"; exit 1; }
  26. sleep 1
  27. done
  28. done < <(git show "origin/${BRANCH}:docker-compose.yml" | grep "image:" | awk '{ gsub("image:","", $3); print $2 }')
  29. }
  30. docker_garbage() {
  31. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  32. IMGS_TO_DELETE=()
  33. declare -A IMAGES_INFO
  34. COMPOSE_IMAGES=($(grep -oP "image: \Kmailcow.+" "${SCRIPT_DIR}/docker-compose.yml"))
  35. for existing_image in $(docker images --format "{{.ID}}:{{.Repository}}:{{.Tag}}" | grep 'mailcow/'); do
  36. ID=$(echo "$existing_image" | cut -d ':' -f 1)
  37. REPOSITORY=$(echo "$existing_image" | cut -d ':' -f 2)
  38. TAG=$(echo "$existing_image" | cut -d ':' -f 3)
  39. if [[ " ${COMPOSE_IMAGES[@]} " =~ " ${REPOSITORY}:${TAG} " ]]; then
  40. continue
  41. else
  42. IMGS_TO_DELETE+=("$ID")
  43. IMAGES_INFO["$ID"]="$REPOSITORY:$TAG"
  44. fi
  45. done
  46. if [[ ! -z ${IMGS_TO_DELETE[*]} ]]; then
  47. echo "The following unused mailcow images were found:"
  48. for id in "${IMGS_TO_DELETE[@]}"; do
  49. echo " ${IMAGES_INFO[$id]} ($id)"
  50. done
  51. if [ ! $FORCE ]; then
  52. read -r -p "Do you want to delete them to free up some space? [y/N] " response
  53. if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  54. docker rmi ${IMGS_TO_DELETE[*]}
  55. else
  56. echo "OK, skipped."
  57. fi
  58. else
  59. echo "Running in forced mode! Force removing old mailcow images..."
  60. docker rmi ${IMGS_TO_DELETE[*]}
  61. fi
  62. echo -e "\e[32mFurther cleanup...\e[0m"
  63. echo "If you want to cleanup further garbage collected by Docker, please make sure all containers are up and running before cleaning your system by executing \"docker system prune\""
  64. fi
  65. }
  66. in_array() {
  67. local e match="$1"
  68. shift
  69. for e; do [[ "$e" == "$match" ]] && return 0; done
  70. return 1
  71. }
  72. migrate_docker_nat() {
  73. NAT_CONFIG='{"ipv6":true,"fixed-cidr-v6":"fd00:dead:beef:c0::/80","experimental":true,"ip6tables":true}'
  74. # Min Docker version
  75. DOCKERV_REQ=20.10.2
  76. # Current Docker version
  77. DOCKERV_CUR=$(docker version -f '{{.Server.Version}}')
  78. if grep -qi "ipv6nat-mailcow" docker-compose.yml && grep -qi "enable_ipv6: true" docker-compose.yml; then
  79. echo -e "\e[32mNative IPv6 implementation available.\e[0m"
  80. echo "This will enable experimental features in the Docker daemon and configure Docker to do the IPv6 NATing instead of ipv6nat-mailcow."
  81. echo '!!! This step is recommended !!!'
  82. echo "mailcow will try to roll back the changes if starting Docker fails after modifying the daemon.json configuration file."
  83. read -r -p "Should we try to enable the native IPv6 implementation in Docker now (recommended)? [y/N] " dockernatresponse
  84. if [[ ! "${dockernatresponse}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  85. echo "OK, skipping this step."
  86. return 0
  87. fi
  88. fi
  89. # Sort versions and check if we are running a newer or equal version to req
  90. if [ $(printf "${DOCKERV_REQ}\n${DOCKERV_CUR}" | sort -V | tail -n1) == "${DOCKERV_CUR}" ]; then
  91. # If Dockerd daemon json exists
  92. if [ -s /etc/docker/daemon.json ]; then
  93. IFS=',' read -r -a dockerconfig <<< $(cat /etc/docker/daemon.json | tr -cd '[:alnum:],')
  94. if ! in_array ipv6true "${dockerconfig[@]}" || \
  95. ! in_array experimentaltrue "${dockerconfig[@]}" || \
  96. ! in_array ip6tablestrue "${dockerconfig[@]}" || \
  97. ! grep -qi "fixed-cidr-v6" /etc/docker/daemon.json; then
  98. echo -e "\e[33mWarning:\e[0m You seem to have modified the /etc/docker/daemon.json configuration by yourself and not fully/correctly activated the native IPv6 NAT implementation."
  99. echo "You will need to merge your existing configuration manually or fix/delete the existing daemon.json configuration before trying the update process again."
  100. echo -e "Please merge the following content and restart the Docker daemon:\n"
  101. echo "${NAT_CONFIG}"
  102. return 1
  103. fi
  104. else
  105. echo "Working on IPv6 NAT, please wait..."
  106. echo "${NAT_CONFIG}" > /etc/docker/daemon.json
  107. ip6tables -F -t nat
  108. [[ -e /etc/rc.conf ]] && rc-service docker restart || systemctl restart docker.service
  109. if [[ $? -ne 0 ]]; then
  110. echo -e "\e[31mError:\e[0m Failed to activate IPv6 NAT! Reverting and exiting."
  111. rm /etc/docker/daemon.json
  112. if [[ -e /etc/rc.conf ]]; then
  113. rc-service docker restart
  114. else
  115. systemctl reset-failed docker.service
  116. systemctl restart docker.service
  117. fi
  118. return 1
  119. fi
  120. fi
  121. # Removing legacy container
  122. sed -i '/ipv6nat-mailcow:$/,/^$/d' docker-compose.yml
  123. if [ -s docker-compose.override.yml ]; then
  124. sed -i '/ipv6nat-mailcow:$/,/^$/d' docker-compose.override.yml
  125. if [[ "$(cat docker-compose.override.yml | sed '/^\s*$/d' | wc -l)" == "2" ]]; then
  126. mv docker-compose.override.yml docker-compose.override.yml_backup
  127. fi
  128. fi
  129. echo -e "\e[32mGreat! \e[0mNative IPv6 NAT is active.\e[0m"
  130. else
  131. echo -e "\e[31mPlease upgrade Docker to version ${DOCKERV_REQ} or above.\e[0m"
  132. return 0
  133. fi
  134. }
  135. remove_obsolete_nginx_ports() {
  136. # Removing obsolete docker-compose.override.yml
  137. for override in docker-compose.override.yml docker-compose.override.yaml; do
  138. if [ -s $override ] ; then
  139. if cat $override | grep nginx-mailcow > /dev/null 2>&1; then
  140. if cat $override | grep -E '(\[::])' > /dev/null 2>&1; then
  141. if cat $override | grep -w 80:80 > /dev/null 2>&1 && cat $override | grep -w 443:443 > /dev/null 2>&1 ; then
  142. echo -e "\e[33mBacking up ${override} to preserve custom changes...\e[0m"
  143. echo -e "\e[33m!!! Manual Merge needed (if other overrides are set) !!!\e[0m"
  144. sleep 3
  145. cp $override ${override}_backup
  146. sed -i '/nginx-mailcow:$/,/^$/d' $override
  147. echo -e "\e[33mRemoved obsolete NGINX IPv6 Bind from original override File.\e[0m"
  148. if [[ "$(cat $override | sed '/^\s*$/d' | wc -l)" == "2" ]]; then
  149. mv $override ${override}_empty
  150. echo -e "\e[31m${override} is empty. Renamed it to ensure mailcow is startable.\e[0m"
  151. fi
  152. fi
  153. fi
  154. fi
  155. fi
  156. done
  157. }
  158. detect_docker_compose_command(){
  159. if ! [[ "${DOCKER_COMPOSE_VERSION}" =~ ^(native|standalone)$ ]]; then
  160. if docker compose > /dev/null 2>&1; then
  161. if docker compose version --short | grep -e "^2." -e "^v2." > /dev/null 2>&1; then
  162. DOCKER_COMPOSE_VERSION=native
  163. COMPOSE_COMMAND="docker compose"
  164. echo -e "\e[33mFound Docker Compose Plugin (native).\e[0m"
  165. echo -e "\e[33mSetting the DOCKER_COMPOSE_VERSION Variable to native\e[0m"
  166. sed -i 's/^DOCKER_COMPOSE_VERSION=.*/DOCKER_COMPOSE_VERSION=native/' "$SCRIPT_DIR/mailcow.conf"
  167. sleep 2
  168. echo -e "\e[33mNotice: You'll have to update this Compose Version via your Package Manager manually!\e[0m"
  169. else
  170. echo -e "\e[31mCannot find Docker Compose with a Version Higher than 2.X.X.\e[0m"
  171. echo -e "\e[31mPlease update/install it manually regarding to this doc site: https://docs.mailcow.email/install/\e[0m"
  172. exit 1
  173. fi
  174. elif docker-compose > /dev/null 2>&1; then
  175. if ! [[ $(alias docker-compose 2> /dev/null) ]] ; then
  176. if docker-compose version --short | grep "^2." > /dev/null 2>&1; then
  177. DOCKER_COMPOSE_VERSION=standalone
  178. COMPOSE_COMMAND="docker-compose"
  179. echo -e "\e[33mFound Docker Compose Standalone.\e[0m"
  180. echo -e "\e[33mSetting the DOCKER_COMPOSE_VERSION Variable to standalone\e[0m"
  181. sed -i 's/^DOCKER_COMPOSE_VERSION=.*/DOCKER_COMPOSE_VERSION=standalone/' "$SCRIPT_DIR/mailcow.conf"
  182. sleep 2
  183. echo -e "\e[33mNotice: For an automatic update of docker-compose please use the update_compose.sh scripts located at the helper-scripts folder.\e[0m"
  184. else
  185. echo -e "\e[31mCannot find Docker Compose with a Version Higher than 2.X.X.\e[0m"
  186. echo -e "\e[31mPlease update/install regarding to this doc site: https://docs.mailcow.email/install/\e[0m"
  187. exit 1
  188. fi
  189. fi
  190. else
  191. echo -e "\e[31mCannot find Docker Compose.\e[0m"
  192. echo -e "\e[31mPlease install it regarding to this doc site: https://docs.mailcow.email/install/\e[0m"
  193. exit 1
  194. fi
  195. elif [ "${DOCKER_COMPOSE_VERSION}" == "native" ]; then
  196. COMPOSE_COMMAND="docker compose"
  197. # Check if Native Compose works and has not been deleted
  198. if ! $COMPOSE_COMMAND > /dev/null 2>&1; then
  199. # IF it not exists/work anymore try the other command
  200. COMPOSE_COMMAND="docker-compose"
  201. if ! $COMPOSE_COMMAND > /dev/null 2>&1 || ! $COMPOSE_COMMAND --version | grep "^2." > /dev/null 2>&1; then
  202. # IF it cannot find Standalone in > 2.X, then script stops
  203. echo -e "\e[31mCannot find Docker Compose or the Version is lower then 2.X.X.\e[0m"
  204. echo -e "\e[31mPlease install it regarding to this doc site: https://docs.mailcow.email/install/\e[0m"
  205. exit 1
  206. fi
  207. # If it finds the standalone Plugin it will use this instead and change the mailcow.conf Variable accordingly
  208. echo -e "\e[31mFound different Docker Compose Version then declared in mailcow.conf!\e[0m"
  209. echo -e "\e[31mSetting the DOCKER_COMPOSE_VERSION Variable from native to standalone\e[0m"
  210. sed -i 's/^DOCKER_COMPOSE_VERSION=.*/DOCKER_COMPOSE_VERSION=standalone/' "$SCRIPT_DIR/mailcow.conf"
  211. sleep 2
  212. fi
  213. elif [ "${DOCKER_COMPOSE_VERSION}" == "standalone" ]; then
  214. COMPOSE_COMMAND="docker-compose"
  215. # Check if Standalone Compose works and has not been deleted
  216. if ! $COMPOSE_COMMAND > /dev/null 2>&1 && ! $COMPOSE_COMMAND --version > /dev/null 2>&1 | grep "^2." > /dev/null 2>&1; then
  217. # IF it not exists/work anymore try the other command
  218. COMPOSE_COMMAND="docker compose"
  219. if ! $COMPOSE_COMMAND > /dev/null 2>&1; then
  220. # IF it cannot find Native in > 2.X, then script stops
  221. echo -e "\e[31mCannot find Docker Compose.\e[0m"
  222. echo -e "\e[31mPlease install it regarding to this doc site: https://docs.mailcow.email/install/\e[0m"
  223. exit 1
  224. fi
  225. # If it finds the native Plugin it will use this instead and change the mailcow.conf Variable accordingly
  226. echo -e "\e[31mFound different Docker Compose Version then declared in mailcow.conf!\e[0m"
  227. echo -e "\e[31mSetting the DOCKER_COMPOSE_VERSION Variable from standalone to native\e[0m"
  228. sed -i 's/^DOCKER_COMPOSE_VERSION=.*/DOCKER_COMPOSE_VERSION=native/' "$SCRIPT_DIR/mailcow.conf"
  229. sleep 2
  230. fi
  231. fi
  232. }
  233. detect_bad_asn() {
  234. echo -e "\e[33mDetecting if your IP is listed on Spamhaus Bad ASN List...\e[0m"
  235. response=$(curl --connect-timeout 15 --max-time 30 -s -o /dev/null -w "%{http_code}" "https://asn-check.mailcow.email")
  236. if [ "$response" -eq 503 ]; then
  237. if [ -z "$SPAMHAUS_DQS_KEY" ]; then
  238. echo -e "\e[33mYour server's public IP uses an AS that is blocked by Spamhaus to use their DNS public blocklists for Postfix.\e[0m"
  239. echo -e "\e[33mmailcow did not detected a value for the variable SPAMHAUS_DQS_KEY inside mailcow.conf!\e[0m"
  240. sleep 2
  241. echo ""
  242. echo -e "\e[33mTo use the Spamhaus DNS Blocklists again, you will need to create a FREE account for their Data Query Service (DQS) at: https://www.spamhaus.com/free-trial/sign-up-for-a-free-data-query-service-account\e[0m"
  243. echo -e "\e[33mOnce done, enter your DQS API key in mailcow.conf and mailcow will do the rest for you!\e[0m"
  244. echo ""
  245. sleep 2
  246. else
  247. echo -e "\e[33mYour server's public IP uses an AS that is blocked by Spamhaus to use their DNS public blocklists for Postfix.\e[0m"
  248. echo -e "\e[32mmailcow detected a Value for the variable SPAMHAUS_DQS_KEY inside mailcow.conf. Postfix will use DQS with the given API key...\e[0m"
  249. fi
  250. elif [ "$response" -eq 200 ]; then
  251. echo -e "\e[33mCheck completed! Your IP is \e[32mclean\e[0m"
  252. elif [ "$response" -eq 429 ]; then
  253. echo -e "\e[33mCheck completed! \e[31mYour IP seems to be rate limited on the ASN Check service... please try again later!\e[0m"
  254. else
  255. echo -e "\e[31mCheck failed! \e[0mMaybe a DNS or Network problem?\e[0m"
  256. fi
  257. }
  258. fix_broken_dnslist_conf() {
  259. # Fixing issue: #6143. To be removed in a later patch
  260. local file="${SCRIPT_DIR}/data/conf/postfix/dns_blocklists.cf"
  261. # Check if the file exists
  262. if [[ ! -f "$file" ]]; then
  263. return 1
  264. fi
  265. # Check if the file contains the autogenerated comment
  266. if grep -q "# Autogenerated by mailcow" "$file"; then
  267. # Ask the user if custom changes were made
  268. echo -e "\e[91mWARNING!!! \e[31mAn old version of dns_blocklists.cf has been detected which may cause a broken postfix upon startup (see: https://github.com/mailcow/mailcow-dockerized/issues/6143)...\e[0m"
  269. echo -e "\e[31mIf you have any custom settings in there you might copy it away and adapt the changes after the file is regenerated...\e[0m"
  270. read -p "Do you want to delete the file now and let mailcow regenerate it properly? [y/n]" response
  271. if [[ "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  272. rm "$file"
  273. echo -e "\e[32mdns_blocklists.cf has been deleted and will be properly regenerated"
  274. return 0
  275. else
  276. echo -e "\e[35mOk, not deleting it! Please make sure you take a look at postfix upon start then..."
  277. return 2
  278. fi
  279. fi
  280. }
  281. adapt_new_options() {
  282. CONFIG_ARRAY=(
  283. "SKIP_LETS_ENCRYPT"
  284. "SKIP_SOGO"
  285. "USE_WATCHDOG"
  286. "WATCHDOG_NOTIFY_EMAIL"
  287. "WATCHDOG_NOTIFY_WEBHOOK"
  288. "WATCHDOG_NOTIFY_WEBHOOK_BODY"
  289. "WATCHDOG_NOTIFY_BAN"
  290. "WATCHDOG_NOTIFY_START"
  291. "WATCHDOG_EXTERNAL_CHECKS"
  292. "WATCHDOG_SUBJECT"
  293. "SKIP_CLAMD"
  294. "SKIP_IP_CHECK"
  295. "ADDITIONAL_SAN"
  296. "DOVEADM_PORT"
  297. "IPV4_NETWORK"
  298. "IPV6_NETWORK"
  299. "LOG_LINES"
  300. "SNAT_TO_SOURCE"
  301. "SNAT6_TO_SOURCE"
  302. "COMPOSE_PROJECT_NAME"
  303. "DOCKER_COMPOSE_VERSION"
  304. "SQL_PORT"
  305. "API_KEY"
  306. "API_KEY_READ_ONLY"
  307. "API_ALLOW_FROM"
  308. "MAILDIR_GC_TIME"
  309. "MAILDIR_SUB"
  310. "ACL_ANYONE"
  311. "FTS_HEAP"
  312. "FTS_PROCS"
  313. "SKIP_FTS"
  314. "ENABLE_SSL_SNI"
  315. "ALLOW_ADMIN_EMAIL_LOGIN"
  316. "SKIP_HTTP_VERIFICATION"
  317. "SOGO_EXPIRE_SESSION"
  318. "REDIS_PORT"
  319. "DOVECOT_MASTER_USER"
  320. "DOVECOT_MASTER_PASS"
  321. "MAILCOW_PASS_SCHEME"
  322. "ADDITIONAL_SERVER_NAMES"
  323. "ACME_CONTACT"
  324. "WATCHDOG_VERBOSE"
  325. "WEBAUTHN_ONLY_TRUSTED_VENDORS"
  326. "SPAMHAUS_DQS_KEY"
  327. "SKIP_UNBOUND_HEALTHCHECK"
  328. "DISABLE_NETFILTER_ISOLATION_RULE"
  329. "HTTP_REDIRECT"
  330. )
  331. sed -i --follow-symlinks '$a\' mailcow.conf
  332. for option in ${CONFIG_ARRAY[@]}; do
  333. if [[ ${option} == "ADDITIONAL_SAN" ]]; then
  334. if ! grep -q ${option} mailcow.conf; then
  335. echo "Adding new option \"${option}\" to mailcow.conf"
  336. echo "${option}=" >> mailcow.conf
  337. fi
  338. elif [[ ${option} == "COMPOSE_PROJECT_NAME" ]]; then
  339. if ! grep -q ${option} mailcow.conf; then
  340. echo "Adding new option \"${option}\" to mailcow.conf"
  341. echo "COMPOSE_PROJECT_NAME=mailcowdockerized" >> mailcow.conf
  342. fi
  343. elif [[ ${option} == "DOCKER_COMPOSE_VERSION" ]]; then
  344. if ! grep -q ${option} mailcow.conf; then
  345. echo "Adding new option \"${option}\" to mailcow.conf"
  346. echo "# Used Docker Compose version" >> mailcow.conf
  347. echo "# Switch here between native (compose plugin) and standalone" >> mailcow.conf
  348. echo "# For more informations take a look at the mailcow docs regarding the configuration options." >> mailcow.conf
  349. echo "# Normally this should be untouched but if you decided to use either of those you can switch it manually here." >> mailcow.conf
  350. echo "# Please be aware that at least one of those variants should be installed on your maschine or mailcow will fail." >> mailcow.conf
  351. echo "" >> mailcow.conf
  352. echo "DOCKER_COMPOSE_VERSION=${DOCKER_COMPOSE_VERSION}" >> mailcow.conf
  353. fi
  354. elif [[ ${option} == "DOVEADM_PORT" ]]; then
  355. if ! grep -q ${option} mailcow.conf; then
  356. echo "Adding new option \"${option}\" to mailcow.conf"
  357. echo "DOVEADM_PORT=127.0.0.1:19991" >> mailcow.conf
  358. fi
  359. elif [[ ${option} == "WATCHDOG_NOTIFY_EMAIL" ]]; then
  360. if ! grep -q ${option} mailcow.conf; then
  361. echo "Adding new option \"${option}\" to mailcow.conf"
  362. echo "WATCHDOG_NOTIFY_EMAIL=" >> mailcow.conf
  363. fi
  364. elif [[ ${option} == "LOG_LINES" ]]; then
  365. if ! grep -q ${option} mailcow.conf; then
  366. echo "Adding new option \"${option}\" to mailcow.conf"
  367. echo '# Max log lines per service to keep in Redis logs' >> mailcow.conf
  368. echo "LOG_LINES=9999" >> mailcow.conf
  369. fi
  370. elif [[ ${option} == "IPV4_NETWORK" ]]; then
  371. if ! grep -q ${option} mailcow.conf; then
  372. echo "Adding new option \"${option}\" to mailcow.conf"
  373. echo '# Internal IPv4 /24 subnet, format n.n.n. (expands to n.n.n.0/24)' >> mailcow.conf
  374. echo "IPV4_NETWORK=172.22.1" >> mailcow.conf
  375. fi
  376. elif [[ ${option} == "IPV6_NETWORK" ]]; then
  377. if ! grep -q ${option} mailcow.conf; then
  378. echo "Adding new option \"${option}\" to mailcow.conf"
  379. echo '# Internal IPv6 subnet in fc00::/7' >> mailcow.conf
  380. echo "IPV6_NETWORK=fd4d:6169:6c63:6f77::/64" >> mailcow.conf
  381. fi
  382. elif [[ ${option} == "SQL_PORT" ]]; then
  383. if ! grep -q ${option} mailcow.conf; then
  384. echo "Adding new option \"${option}\" to mailcow.conf"
  385. echo '# Bind SQL to 127.0.0.1 on port 13306' >> mailcow.conf
  386. echo "SQL_PORT=127.0.0.1:13306" >> mailcow.conf
  387. fi
  388. elif [[ ${option} == "API_KEY" ]]; then
  389. if ! grep -q ${option} mailcow.conf; then
  390. echo "Adding new option \"${option}\" to mailcow.conf"
  391. echo '# Create or override API key for web UI' >> mailcow.conf
  392. echo "#API_KEY=" >> mailcow.conf
  393. fi
  394. elif [[ ${option} == "API_KEY_READ_ONLY" ]]; then
  395. if ! grep -q ${option} mailcow.conf; then
  396. echo "Adding new option \"${option}\" to mailcow.conf"
  397. echo '# Create or override read-only API key for web UI' >> mailcow.conf
  398. echo "#API_KEY_READ_ONLY=" >> mailcow.conf
  399. fi
  400. elif [[ ${option} == "API_ALLOW_FROM" ]]; then
  401. if ! grep -q ${option} mailcow.conf; then
  402. echo "Adding new option \"${option}\" to mailcow.conf"
  403. echo '# Must be set for API_KEY to be active' >> mailcow.conf
  404. echo '# IPs only, no networks (networks can be set via UI)' >> mailcow.conf
  405. echo "#API_ALLOW_FROM=" >> mailcow.conf
  406. fi
  407. elif [[ ${option} == "SNAT_TO_SOURCE" ]]; then
  408. if ! grep -q ${option} mailcow.conf; then
  409. echo "Adding new option \"${option}\" to mailcow.conf"
  410. echo '# Use this IPv4 for outgoing connections (SNAT)' >> mailcow.conf
  411. echo "#SNAT_TO_SOURCE=" >> mailcow.conf
  412. fi
  413. elif [[ ${option} == "SNAT6_TO_SOURCE" ]]; then
  414. if ! grep -q ${option} mailcow.conf; then
  415. echo "Adding new option \"${option}\" to mailcow.conf"
  416. echo '# Use this IPv6 for outgoing connections (SNAT)' >> mailcow.conf
  417. echo "#SNAT6_TO_SOURCE=" >> mailcow.conf
  418. fi
  419. elif [[ ${option} == "MAILDIR_GC_TIME" ]]; then
  420. if ! grep -q ${option} mailcow.conf; then
  421. echo "Adding new option \"${option}\" to mailcow.conf"
  422. echo '# Garbage collector cleanup' >> mailcow.conf
  423. echo '# Deleted domains and mailboxes are moved to /var/vmail/_garbage/timestamp_sanitizedstring' >> mailcow.conf
  424. echo '# How long should objects remain in the garbage until they are being deleted? (value in minutes)' >> mailcow.conf
  425. echo '# Check interval is hourly' >> mailcow.conf
  426. echo 'MAILDIR_GC_TIME=1440' >> mailcow.conf
  427. fi
  428. elif [[ ${option} == "ACL_ANYONE" ]]; then
  429. if ! grep -q ${option} mailcow.conf; then
  430. echo "Adding new option \"${option}\" to mailcow.conf"
  431. echo '# Set this to "allow" to enable the anyone pseudo user. Disabled by default.' >> mailcow.conf
  432. echo '# When enabled, ACL can be created, that apply to "All authenticated users"' >> mailcow.conf
  433. echo '# This should probably only be activated on mail hosts, that are used exclusivly by one organisation.' >> mailcow.conf
  434. echo '# Otherwise a user might share data with too many other users.' >> mailcow.conf
  435. echo 'ACL_ANYONE=disallow' >> mailcow.conf
  436. fi
  437. elif [[ ${option} == "FTS_HEAP" ]]; then
  438. if ! grep -q ${option} mailcow.conf; then
  439. echo "Adding new option \"${option}\" to mailcow.conf"
  440. echo '# Dovecot Indexing (FTS) Process maximum heap size in MB, there is no recommendation, please see Dovecot docs.' >> mailcow.conf
  441. echo '# Flatcurve is used as FTS Engine. It is supposed to be pretty efficient in CPU and RAM consumption.' >> mailcow.conf
  442. echo '# Please always monitor your Resource consumption!' >> mailcow.conf
  443. echo "FTS_HEAP=128" >> mailcow.conf
  444. fi
  445. elif [[ ${option} == "SKIP_FTS" ]]; then
  446. if ! grep -q ${option} mailcow.conf; then
  447. echo "Adding new option \"${option}\" to mailcow.conf"
  448. echo '# Skip FTS (Fulltext Search) for Dovecot on low-memory, low-threaded systems or if you simply want to disable it.' >> mailcow.conf
  449. echo "# Dovecot inside mailcow use Flatcurve as FTS Backend." >> mailcow.conf
  450. echo "SKIP_FTS=y" >> mailcow.conf
  451. fi
  452. elif [[ ${option} == "FTS_PROCS" ]]; then
  453. if ! grep -q ${option} mailcow.conf; then
  454. echo "Adding new option \"${option}\" to mailcow.conf"
  455. echo '# Controls how many processes the Dovecot indexing process can spawn at max.' >> mailcow.conf
  456. echo '# Too many indexing processes can use a lot of CPU and Disk I/O' >> mailcow.conf
  457. echo '# Please visit: https://doc.dovecot.org/configuration_manual/service_configuration/#indexer-worker for more informations' >> mailcow.conf
  458. echo "FTS_PROCS=1" >> mailcow.conf
  459. fi
  460. elif [[ ${option} == "ENABLE_SSL_SNI" ]]; then
  461. if ! grep -q ${option} mailcow.conf; then
  462. echo "Adding new option \"${option}\" to mailcow.conf"
  463. echo '# Create seperate certificates for all domains - y/n' >> mailcow.conf
  464. echo '# this will allow adding more than 100 domains, but some email clients will not be able to connect with alternative hostnames' >> mailcow.conf
  465. echo '# see https://wiki.dovecot.org/SSL/SNIClientSupport' >> mailcow.conf
  466. echo "ENABLE_SSL_SNI=n" >> mailcow.conf
  467. fi
  468. elif [[ ${option} == "SKIP_SOGO" ]]; then
  469. if ! grep -q ${option} mailcow.conf; then
  470. echo "Adding new option \"${option}\" to mailcow.conf"
  471. echo '# Skip SOGo: Will disable SOGo integration and therefore webmail, DAV protocols and ActiveSync support (experimental, unsupported, not fully implemented) - y/n' >> mailcow.conf
  472. echo "SKIP_SOGO=n" >> mailcow.conf
  473. fi
  474. elif [[ ${option} == "MAILDIR_SUB" ]]; then
  475. if ! grep -q ${option} mailcow.conf; then
  476. echo "Adding new option \"${option}\" to mailcow.conf"
  477. echo '# MAILDIR_SUB defines a path in a users virtual home to keep the maildir in. Leave empty for updated setups.' >> mailcow.conf
  478. echo "#MAILDIR_SUB=Maildir" >> mailcow.conf
  479. echo "MAILDIR_SUB=" >> mailcow.conf
  480. fi
  481. elif [[ ${option} == "WATCHDOG_NOTIFY_WEBHOOK" ]]; then
  482. if ! grep -q ${option} mailcow.conf; then
  483. echo "Adding new option \"${option}\" to mailcow.conf"
  484. echo '# Send notifications to a webhook URL that receives a POST request with the content type "application/json".' >> mailcow.conf
  485. echo '# You can use this to send notifications to services like Discord, Slack and others.' >> mailcow.conf
  486. echo '#WATCHDOG_NOTIFY_WEBHOOK=https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' >> mailcow.conf
  487. fi
  488. elif [[ ${option} == "WATCHDOG_NOTIFY_WEBHOOK_BODY" ]]; then
  489. if ! grep -q ${option} mailcow.conf; then
  490. echo "Adding new option \"${option}\" to mailcow.conf"
  491. echo '# JSON body included in the webhook POST request. Needs to be in single quotes.' >> mailcow.conf
  492. echo '# Following variables are available: SUBJECT, BODY' >> mailcow.conf
  493. WEBHOOK_BODY='{"username": "mailcow Watchdog", "content": "**${SUBJECT}**\n${BODY}"}'
  494. echo "#WATCHDOG_NOTIFY_WEBHOOK_BODY='${WEBHOOK_BODY}'" >> mailcow.conf
  495. fi
  496. elif [[ ${option} == "WATCHDOG_NOTIFY_BAN" ]]; then
  497. if ! grep -q ${option} mailcow.conf; then
  498. echo "Adding new option \"${option}\" to mailcow.conf"
  499. echo '# Notify about banned IP. Includes whois lookup.' >> mailcow.conf
  500. echo "WATCHDOG_NOTIFY_BAN=y" >> mailcow.conf
  501. fi
  502. elif [[ ${option} == "WATCHDOG_NOTIFY_START" ]]; then
  503. if ! grep -q ${option} mailcow.conf; then
  504. echo "Adding new option \"${option}\" to mailcow.conf"
  505. echo '# Send a notification when the watchdog is started.' >> mailcow.conf
  506. echo "WATCHDOG_NOTIFY_START=y" >> mailcow.conf
  507. fi
  508. elif [[ ${option} == "WATCHDOG_SUBJECT" ]]; then
  509. if ! grep -q ${option} mailcow.conf; then
  510. echo "Adding new option \"${option}\" to mailcow.conf"
  511. echo '# Subject for watchdog mails. Defaults to "Watchdog ALERT" followed by the error message.' >> mailcow.conf
  512. echo "#WATCHDOG_SUBJECT=" >> mailcow.conf
  513. fi
  514. elif [[ ${option} == "WATCHDOG_EXTERNAL_CHECKS" ]]; then
  515. if ! grep -q ${option} mailcow.conf; then
  516. echo "Adding new option \"${option}\" to mailcow.conf"
  517. echo '# Checks if mailcow is an open relay. Requires a SAL. More checks will follow.' >> mailcow.conf
  518. echo '# No data is collected. Opt-in and anonymous.' >> mailcow.conf
  519. echo '# Will only work with unmodified mailcow setups.' >> mailcow.conf
  520. echo "WATCHDOG_EXTERNAL_CHECKS=n" >> mailcow.conf
  521. fi
  522. elif [[ ${option} == "SOGO_EXPIRE_SESSION" ]]; then
  523. if ! grep -q ${option} mailcow.conf; then
  524. echo "Adding new option \"${option}\" to mailcow.conf"
  525. echo '# SOGo session timeout in minutes' >> mailcow.conf
  526. echo "SOGO_EXPIRE_SESSION=480" >> mailcow.conf
  527. fi
  528. elif [[ ${option} == "REDIS_PORT" ]]; then
  529. if ! grep -q ${option} mailcow.conf; then
  530. echo "Adding new option \"${option}\" to mailcow.conf"
  531. echo "REDIS_PORT=127.0.0.1:7654" >> mailcow.conf
  532. fi
  533. elif [[ ${option} == "DOVECOT_MASTER_USER" ]]; then
  534. if ! grep -q ${option} mailcow.conf; then
  535. echo "Adding new option \"${option}\" to mailcow.conf"
  536. echo '# DOVECOT_MASTER_USER and _PASS must _both_ be provided. No special chars.' >> mailcow.conf
  537. echo '# Empty by default to auto-generate master user and password on start.' >> mailcow.conf
  538. echo '# User expands to DOVECOT_MASTER_USER@mailcow.local' >> mailcow.conf
  539. echo '# LEAVE EMPTY IF UNSURE' >> mailcow.conf
  540. echo "DOVECOT_MASTER_USER=" >> mailcow.conf
  541. fi
  542. elif [[ ${option} == "DOVECOT_MASTER_PASS" ]]; then
  543. if ! grep -q ${option} mailcow.conf; then
  544. echo "Adding new option \"${option}\" to mailcow.conf"
  545. echo '# LEAVE EMPTY IF UNSURE' >> mailcow.conf
  546. echo "DOVECOT_MASTER_PASS=" >> mailcow.conf
  547. fi
  548. elif [[ ${option} == "MAILCOW_PASS_SCHEME" ]]; then
  549. if ! grep -q ${option} mailcow.conf; then
  550. echo "Adding new option \"${option}\" to mailcow.conf"
  551. echo '# Password hash algorithm' >> mailcow.conf
  552. echo '# Only certain password hash algorithm are supported. For a fully list of supported schemes,' >> mailcow.conf
  553. echo '# see https://docs.mailcow.email/models/model-passwd/' >> mailcow.conf
  554. echo "MAILCOW_PASS_SCHEME=BLF-CRYPT" >> mailcow.conf
  555. fi
  556. elif [[ ${option} == "ADDITIONAL_SERVER_NAMES" ]]; then
  557. if ! grep -q ${option} mailcow.conf; then
  558. echo "Adding new option \"${option}\" to mailcow.conf"
  559. echo '# Additional server names for mailcow UI' >> mailcow.conf
  560. echo '#' >> mailcow.conf
  561. echo '# Specify alternative addresses for the mailcow UI to respond to' >> mailcow.conf
  562. echo '# This is useful when you set mail.* as ADDITIONAL_SAN and want to make sure mail.maildomain.com will always point to the mailcow UI.' >> mailcow.conf
  563. echo '# If the server name does not match a known site, Nginx decides by best-guess and may redirect users to the wrong web root.' >> mailcow.conf
  564. echo '# You can understand this as server_name directive in Nginx.' >> mailcow.conf
  565. echo '# Comma separated list without spaces! Example: ADDITIONAL_SERVER_NAMES=a.b.c,d.e.f' >> mailcow.conf
  566. echo 'ADDITIONAL_SERVER_NAMES=' >> mailcow.conf
  567. fi
  568. elif [[ ${option} == "ACME_CONTACT" ]]; then
  569. if ! grep -q ${option} mailcow.conf; then
  570. echo "Adding new option \"${option}\" to mailcow.conf"
  571. echo '# Lets Encrypt registration contact information' >> mailcow.conf
  572. echo '# Optional: Leave empty for none' >> mailcow.conf
  573. echo '# This value is only used on first order!' >> mailcow.conf
  574. echo '# Setting it at a later point will require the following steps:' >> mailcow.conf
  575. echo '# https://docs.mailcow.email/troubleshooting/debug-reset_tls/' >> mailcow.conf
  576. echo 'ACME_CONTACT=' >> mailcow.conf
  577. fi
  578. elif [[ ${option} == "WEBAUTHN_ONLY_TRUSTED_VENDORS" ]]; then
  579. if ! grep -q ${option} mailcow.conf; then
  580. echo "Adding new option \"${option}\" to mailcow.conf"
  581. echo "# WebAuthn device manufacturer verification" >> mailcow.conf
  582. echo '# After setting WEBAUTHN_ONLY_TRUSTED_VENDORS=y only devices from trusted manufacturers are allowed' >> mailcow.conf
  583. echo '# root certificates can be placed for validation under mailcow-dockerized/data/web/inc/lib/WebAuthn/rootCertificates' >> mailcow.conf
  584. echo 'WEBAUTHN_ONLY_TRUSTED_VENDORS=n' >> mailcow.conf
  585. fi
  586. elif [[ ${option} == "SPAMHAUS_DQS_KEY" ]]; then
  587. if ! grep -q ${option} mailcow.conf; then
  588. echo "Adding new option \"${option}\" to mailcow.conf"
  589. echo "# Spamhaus Data Query Service Key" >> mailcow.conf
  590. echo '# Optional: Leave empty for none' >> mailcow.conf
  591. echo '# Enter your key here if you are using a blocked ASN (OVH, AWS, Cloudflare e.g) for the unregistered Spamhaus Blocklist.' >> mailcow.conf
  592. echo '# If empty, it will completely disable Spamhaus blocklists if it detects that you are running on a server using a blocked AS.' >> mailcow.conf
  593. echo '# Otherwise it will work as usual.' >> mailcow.conf
  594. echo 'SPAMHAUS_DQS_KEY=' >> mailcow.conf
  595. fi
  596. elif [[ ${option} == "WATCHDOG_VERBOSE" ]]; then
  597. if ! grep -q ${option} mailcow.conf; then
  598. echo "Adding new option \"${option}\" to mailcow.conf"
  599. echo '# Enable watchdog verbose logging' >> mailcow.conf
  600. echo 'WATCHDOG_VERBOSE=n' >> mailcow.conf
  601. fi
  602. elif [[ ${option} == "SKIP_UNBOUND_HEALTHCHECK" ]]; then
  603. if ! grep -q ${option} mailcow.conf; then
  604. echo "Adding new option \"${option}\" to mailcow.conf"
  605. echo '# Skip Unbound (DNS Resolver) Healthchecks (NOT Recommended!) - y/n' >> mailcow.conf
  606. echo 'SKIP_UNBOUND_HEALTHCHECK=n' >> mailcow.conf
  607. fi
  608. elif [[ ${option} == "DISABLE_NETFILTER_ISOLATION_RULE" ]]; then
  609. if ! grep -q ${option} mailcow.conf; then
  610. echo "Adding new option \"${option}\" to mailcow.conf"
  611. echo '# Prevent netfilter from setting an iptables/nftables rule to isolate the mailcow docker network - y/n' >> mailcow.conf
  612. echo '# CAUTION: Disabling this may expose container ports to other neighbors on the same subnet, even if the ports are bound to localhost' >> mailcow.conf
  613. echo 'DISABLE_NETFILTER_ISOLATION_RULE=n' >> mailcow.conf
  614. fi
  615. elif [[ ${option} == "HTTP_REDIRECT" ]]; then
  616. if ! grep -q ${option} mailcow.conf; then
  617. echo "Adding new option \"${option}\" to mailcow.conf"
  618. echo '# Redirect HTTP connections to HTTPS - y/n' >> mailcow.conf
  619. echo 'HTTP_REDIRECT=n' >> mailcow.conf
  620. fi
  621. elif ! grep -q ${option} mailcow.conf; then
  622. echo "Adding new option \"${option}\" to mailcow.conf"
  623. echo "${option}=n" >> mailcow.conf
  624. fi
  625. done
  626. }
  627. migrate_solr_config_options() {
  628. sed -i --follow-symlinks '$a\' mailcow.conf
  629. if grep -q "SOLR_HEAP" mailcow.conf; then
  630. echo "Removing SOLR_HEAP in mailcow.conf"
  631. sed -i '/# Solr heap size in MB\b/d' mailcow.conf
  632. sed -i '/# Solr is a prone to run\b/d' mailcow.conf
  633. sed -i '/SOLR_HEAP\b/d' mailcow.conf
  634. fi
  635. if grep -q "SKIP_SOLR" mailcow.conf; then
  636. echo "Removing SKIP_SOLR in mailcow.conf"
  637. sed -i '/\bSkip Solr on low-memory\b/d' mailcow.conf
  638. sed -i '/\bSolr is disabled by default\b/d' mailcow.conf
  639. sed -i '/\bDisable Solr or\b/d' mailcow.conf
  640. sed -i '/\bSKIP_SOLR\b/d' mailcow.conf
  641. fi
  642. if grep -q "SOLR_PORT" mailcow.conf; then
  643. echo "Removing SOLR_PORT in mailcow.conf"
  644. sed -i '/\bSOLR_PORT\b/d' mailcow.conf
  645. fi
  646. if grep -q "FLATCURVE_EXPERIMENTAL" mailcow.conf; then
  647. echo "Removing FLATCURVE_EXPERIMENTAL in mailcow.conf"
  648. sed -i '/\bFLATCURVE_EXPERIMENTAL\b/d' mailcow.conf
  649. fi
  650. solr_volume=$(docker volume ls -qf name=^${COMPOSE_PROJECT_NAME}_solr-vol-1)
  651. if [[ -n $solr_volume ]]; then
  652. echo -e "\e[34mSolr has been replaced within mailcow since 2025-01.\nThe volume $solr_volume is unused.\e[0m"
  653. sleep 1
  654. if [ ! "$FORCE" ]; then
  655. read -r -p "Remove $solr_volume? [y/N] " response
  656. if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  657. echo -e "\e[33mRemoving $solr_volume...\e[0m"
  658. docker volume rm $solr_volume || echo -e "\e[31mFailed to remove. Remove it manually!\e[0m"
  659. echo -e "\e[32mSuccessfully removed $solr_volume!\e[0m"
  660. else
  661. echo -e "Not removing $solr_volume. Run \`docker volume rm $solr_volume\` manually if needed."
  662. fi
  663. else
  664. echo -e "\e[33mForce removing $solr_volume...\e[0m"
  665. docker volume rm $solr_volume || echo -e "\e[31mFailed to remove. Remove it manually!\e[0m"
  666. echo -e "\e[32mSuccessfully removed $solr_volume!\e[0m"
  667. fi
  668. fi
  669. # Delete old fts.conf before forced switch to flatcurve to ensure update is working properly
  670. FTS_CONF_PATH="${SCRIPT_DIR}/data/conf/dovecot/conf.d/fts.conf"
  671. if [[ -f "$FTS_CONF_PATH" ]]; then
  672. if grep -q "Autogenerated by mailcow" "$FTS_CONF_PATH"; then
  673. rm -rf $FTS_CONF_PATH
  674. fi
  675. fi
  676. }
  677. detect_major_update() {
  678. if [ ${BRANCH} == "master" ]; then
  679. # Array with major versions
  680. # Add major versions here
  681. MAJOR_VERSIONS=(
  682. "2025-02"
  683. )
  684. current_version=$(git describe --tags $(git rev-list --tags --max-count=1))
  685. release_url="https://github.com/mailcow/mailcow-dockerized/releases/tag"
  686. updates_to_apply=()
  687. for version in "${MAJOR_VERSIONS[@]}"; do
  688. if [[ "$current_version" < "$version" ]]; then
  689. updates_to_apply+=("$version")
  690. fi
  691. done
  692. if [[ ${#updates_to_apply[@]} -gt 0 ]]; then
  693. echo -e "\e[33m\nMAJOR UPDATES to be applied:\e[0m"
  694. for update in "${updates_to_apply[@]}"; do
  695. echo "$update - $release_url/$update"
  696. done
  697. echo -e "\n⚠️ Please read the release notes before proceeding.\n"
  698. read -p "Do you want to proceed with the update? [y/n] " response
  699. if [[ "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  700. echo "Proceeding with the update..."
  701. else
  702. echo "Update canceled. Exiting."
  703. exit 1
  704. fi
  705. fi
  706. fi
  707. }
  708. ############## End Function Section ##############
  709. # Check permissions
  710. if [ "$(id -u)" -ne "0" ]; then
  711. echo "You need to be root"
  712. exit 1
  713. fi
  714. SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  715. # Run pre-update-hook
  716. if [ -f "${SCRIPT_DIR}/pre_update_hook.sh" ]; then
  717. bash "${SCRIPT_DIR}/pre_update_hook.sh"
  718. fi
  719. if [[ "$(uname -r)" =~ ^4\.15\.0-60 ]]; then
  720. echo "DO NOT RUN mailcow ON THIS UBUNTU KERNEL!";
  721. echo "Please update to 5.x or use another distribution."
  722. exit 1
  723. fi
  724. if [[ "$(uname -r)" =~ ^4\.4\. ]]; then
  725. if grep -q Ubuntu <<< "$(uname -a)"; then
  726. echo "DO NOT RUN mailcow ON THIS UBUNTU KERNEL!"
  727. echo "Please update to linux-generic-hwe-16.04 by running \"apt-get install --install-recommends linux-generic-hwe-16.04\""
  728. exit 1
  729. fi
  730. echo "mailcow on a 4.4.x kernel is not supported. It may or may not work, please upgrade your kernel or continue at your own risk."
  731. read -p "Press any key to continue..." < /dev/tty
  732. fi
  733. # Exit on error and pipefail
  734. set -o pipefail
  735. # Setting high dc timeout
  736. export COMPOSE_HTTP_TIMEOUT=600
  737. # Add /opt/bin to PATH
  738. PATH=$PATH:/opt/bin
  739. umask 0022
  740. # Unset COMPOSE_COMMAND and DOCKER_COMPOSE_VERSION Variable to be on the newest state.
  741. unset COMPOSE_COMMAND
  742. unset DOCKER_COMPOSE_VERSION
  743. for bin in curl docker git awk sha1sum grep cut; do
  744. if [[ -z $(command -v ${bin}) ]]; then
  745. echo "Cannot find ${bin}, exiting..."
  746. exit 1;
  747. fi
  748. done
  749. # Check Docker Version (need at least 24.X)
  750. docker_version=$(docker -v | grep -oP '\d+\.\d+\.\d+' | cut -d '.' -f 1 | head -1)
  751. if [[ $docker_version -lt 24 ]]; then
  752. echo -e "\e[31mCannot find Docker with a Version higher or equals 24.0.0\e[0m"
  753. echo -e "\e[33mmailcow needs a newer Docker version to work properly... continuing on your own risk!\e[0m"
  754. echo -e "\e[31mPlease update your Docker installation... sleeping 10s\e[0m"
  755. sleep 10
  756. fi
  757. export LC_ALL=C
  758. DATE=$(date +%Y-%m-%d_%H_%M_%S)
  759. BRANCH="$(cd "${SCRIPT_DIR}"; git rev-parse --abbrev-ref HEAD)"
  760. while (($#)); do
  761. case "${1}" in
  762. --check|-c)
  763. echo "Checking remote code for updates..."
  764. LATEST_REV=$(git ls-remote --exit-code --refs --quiet https://github.com/mailcow/mailcow-dockerized "${BRANCH}" | cut -f1)
  765. if [ "$?" -ne 0 ]; then
  766. echo "A problem occurred while trying to fetch the latest revision from github."
  767. exit 99
  768. fi
  769. if [[ -z $(git log HEAD --pretty=format:"%H" | grep "${LATEST_REV}") ]]; then
  770. echo -e "Updated code is available.\nThe changes can be found here: https://github.com/mailcow/mailcow-dockerized/commits/master"
  771. git log --date=short --pretty=format:"%ad - %s" "$(git rev-parse --short HEAD)"..origin/master
  772. exit 0
  773. else
  774. echo "No updates available."
  775. exit 3
  776. fi
  777. ;;
  778. --check-tags)
  779. echo "Checking remote tags for updates..."
  780. LATEST_TAG_REV=$(git ls-remote --exit-code --quiet --tags origin | tail -1 | cut -f1)
  781. if [ "$?" -ne 0 ]; then
  782. echo "A problem occurred while trying to fetch the latest tag from github."
  783. exit 99
  784. fi
  785. if [[ -z $(git log HEAD --pretty=format:"%H" | grep "${LATEST_TAG_REV}") ]]; then
  786. echo -e "New tag is available.\nThe changes can be found here: https://github.com/mailcow/mailcow-dockerized/releases/latest"
  787. exit 0
  788. else
  789. echo "No updates available."
  790. exit 3
  791. fi
  792. ;;
  793. --ours)
  794. MERGE_STRATEGY=ours
  795. ;;
  796. --skip-start)
  797. SKIP_START=y
  798. ;;
  799. --skip-ping-check)
  800. SKIP_PING_CHECK=y
  801. ;;
  802. --stable)
  803. CURRENT_BRANCH="$(cd "${SCRIPT_DIR}"; git rev-parse --abbrev-ref HEAD)"
  804. NEW_BRANCH="master"
  805. ;;
  806. --gc)
  807. echo -e "\e[32mCollecting garbage...\e[0m"
  808. docker_garbage
  809. exit 0
  810. ;;
  811. --nightly)
  812. CURRENT_BRANCH="$(cd "${SCRIPT_DIR}"; git rev-parse --abbrev-ref HEAD)"
  813. NEW_BRANCH="nightly"
  814. ;;
  815. --prefetch)
  816. echo -e "\e[32mPrefetching images...\e[0m"
  817. prefetch_images
  818. exit 0
  819. ;;
  820. -f|--force)
  821. echo -e "\e[32mRunning in forced mode...\e[0m"
  822. FORCE=y
  823. ;;
  824. -d|--dev)
  825. echo -e "\e[32mRunning in Developer mode...\e[0m"
  826. DEV=y
  827. ;;
  828. --legacy)
  829. CURRENT_BRANCH="$(cd "${SCRIPT_DIR}"; git rev-parse --abbrev-ref HEAD)"
  830. NEW_BRANCH="legacy"
  831. ;;
  832. --help|-h)
  833. echo './update.sh [-c|--check, --check-tags, --ours, --gc, --nightly, --prefetch, --skip-start, --skip-ping-check, --stable, --legacy, -f|--force, -d|--dev, -h|--help]
  834. -c|--check - Check for updates and exit (exit codes => 0: update available, 3: no updates)
  835. --check-tags - Check for newer tags and exit (exit codes => 0: newer tag available, 3: no newer tag)
  836. --ours - Use merge strategy option "ours" to solve conflicts in favor of non-mailcow code (local changes over remote changes), not recommended!
  837. --gc - Run garbage collector to delete old image tags
  838. --nightly - Switch your mailcow updates to the unstable (nightly) branch. FOR TESTING PURPOSES ONLY!!!!
  839. --prefetch - Only prefetch new images and exit (useful to prepare updates)
  840. --skip-start - Do not start mailcow after update
  841. --skip-ping-check - Skip ICMP Check to public DNS resolvers (Use it only if you'\''ve blocked any ICMP Connections to your mailcow machine)
  842. --stable - Switch your mailcow updates to the stable (master) branch. Default unless you changed it with --nightly or --legacy.
  843. --legacy - Switch your mailcow updates to the legacy branch. The legacy branch will only recieve security updates until February 2026.
  844. -f|--force - Force update, do not ask questions
  845. -d|--dev - Enables Developer Mode (No Checkout of update.sh for tests)
  846. '
  847. exit 0
  848. esac
  849. shift
  850. done
  851. [[ ! -f mailcow.conf ]] && { echo -e "\e[31mmailcow.conf is missing! Is mailcow installed?\e[0m"; exit 1;}
  852. chmod 600 mailcow.conf
  853. source mailcow.conf
  854. detect_docker_compose_command
  855. fix_broken_dnslist_conf
  856. DOTS=${MAILCOW_HOSTNAME//[^.]};
  857. if [ ${#DOTS} -lt 1 ]; then
  858. echo -e "\e[31mMAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) is not a FQDN!\e[0m"
  859. sleep 1
  860. echo "Please change it to a FQDN and redeploy the stack with $COMPOSE_COMMAND up -d"
  861. exit 1
  862. elif [[ "${MAILCOW_HOSTNAME: -1}" == "." ]]; then
  863. echo "MAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) is ending with a dot. This is not a valid FQDN!"
  864. exit 1
  865. elif [ ${#DOTS} -eq 1 ]; then
  866. echo -e "\e[33mMAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) does not contain a Subdomain. This is not fully tested and may cause issues.\e[0m"
  867. echo "Find more information about why this message exists here: https://github.com/mailcow/mailcow-dockerized/issues/1572"
  868. read -r -p "Do you want to proceed anyway? [y/N] " response
  869. if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  870. echo "OK. Proceeding."
  871. else
  872. echo "OK. Exiting."
  873. exit 1
  874. fi
  875. fi
  876. if grep --help 2>&1 | head -n 1 | grep -q -i "busybox"; then echo "BusyBox grep detected, please install gnu grep, \"apk add --no-cache --upgrade grep\""; exit 1; fi
  877. # This will also cover sort
  878. if cp --help 2>&1 | head -n 1 | grep -q -i "busybox"; then echo "BusyBox cp detected, please install coreutils, \"apk add --no-cache --upgrade coreutils\""; exit 1; fi
  879. if sed --help 2>&1 | head -n 1 | grep -q -i "busybox"; then echo "BusyBox sed detected, please install gnu sed, \"apk add --no-cache --upgrade sed\""; exit 1; fi
  880. CONFIG_ARRAY=(
  881. "SKIP_LETS_ENCRYPT"
  882. "SKIP_SOGO"
  883. "USE_WATCHDOG"
  884. "WATCHDOG_NOTIFY_EMAIL"
  885. "WATCHDOG_NOTIFY_WEBHOOK"
  886. "WATCHDOG_NOTIFY_WEBHOOK_BODY"
  887. "WATCHDOG_NOTIFY_BAN"
  888. "WATCHDOG_NOTIFY_START"
  889. "WATCHDOG_EXTERNAL_CHECKS"
  890. "WATCHDOG_SUBJECT"
  891. "SKIP_CLAMD"
  892. "SKIP_IP_CHECK"
  893. "ADDITIONAL_SAN"
  894. "AUTODISCOVER_SAN"
  895. "DOVEADM_PORT"
  896. "IPV4_NETWORK"
  897. "IPV6_NETWORK"
  898. "LOG_LINES"
  899. "SNAT_TO_SOURCE"
  900. "SNAT6_TO_SOURCE"
  901. "COMPOSE_PROJECT_NAME"
  902. "DOCKER_COMPOSE_VERSION"
  903. "SQL_PORT"
  904. "API_KEY"
  905. "API_KEY_READ_ONLY"
  906. "API_ALLOW_FROM"
  907. "MAILDIR_GC_TIME"
  908. "MAILDIR_SUB"
  909. "ACL_ANYONE"
  910. "ENABLE_SSL_SNI"
  911. "ALLOW_ADMIN_EMAIL_LOGIN"
  912. "SKIP_HTTP_VERIFICATION"
  913. "SOGO_EXPIRE_SESSION"
  914. "REDIS_PORT"
  915. "DOVECOT_MASTER_USER"
  916. "DOVECOT_MASTER_PASS"
  917. "MAILCOW_PASS_SCHEME"
  918. "ADDITIONAL_SERVER_NAMES"
  919. "ACME_CONTACT"
  920. "WATCHDOG_VERBOSE"
  921. "WEBAUTHN_ONLY_TRUSTED_VENDORS"
  922. "SPAMHAUS_DQS_KEY"
  923. "SKIP_UNBOUND_HEALTHCHECK"
  924. "DISABLE_NETFILTER_ISOLATION_RULE"
  925. "REDISPASS"
  926. )
  927. detect_bad_asn
  928. sed -i --follow-symlinks '$a\' mailcow.conf
  929. for option in "${CONFIG_ARRAY[@]}"; do
  930. if [[ ${option} == "ADDITIONAL_SAN" ]]; then
  931. if ! grep -q "${option}" mailcow.conf; then
  932. echo "Adding new option \"${option}\" to mailcow.conf"
  933. echo "${option}=" >> mailcow.conf
  934. fi
  935. elif [[ "${option}" == "COMPOSE_PROJECT_NAME" ]]; then
  936. if ! grep -q "${option}" mailcow.conf; then
  937. echo "Adding new option \"${option}\" to mailcow.conf"
  938. echo "COMPOSE_PROJECT_NAME=mailcowdockerized" >> mailcow.conf
  939. fi
  940. elif [[ "${option}" == "DOCKER_COMPOSE_VERSION" ]]; then
  941. if ! grep -q "${option}" mailcow.conf; then
  942. echo "Adding new option \"${option}\" to mailcow.conf"
  943. echo "# Used Docker Compose version" >> mailcow.conf
  944. echo "# Switch here between native (compose plugin) and standalone" >> mailcow.conf
  945. echo "# For more informations take a look at the mailcow docs regarding the configuration options." >> mailcow.conf
  946. echo "# Normally this should be untouched but if you decided to use either of those you can switch it manually here." >> mailcow.conf
  947. echo "# Please be aware that at least one of those variants should be installed on your maschine or mailcow will fail." >> mailcow.conf
  948. echo "" >> mailcow.conf
  949. echo "DOCKER_COMPOSE_VERSION=${DOCKER_COMPOSE_VERSION}" >> mailcow.conf
  950. fi
  951. elif [[ "${option}" == "DOVEADM_PORT" ]]; then
  952. if ! grep -q "${option}" mailcow.conf; then
  953. echo "Adding new option \"${option}\" to mailcow.conf"
  954. echo "DOVEADM_PORT=127.0.0.1:19991" >> mailcow.conf
  955. fi
  956. elif [[ "${option}" == "WATCHDOG_NOTIFY_EMAIL" ]]; then
  957. if ! grep -q "${option}" mailcow.conf; then
  958. echo "Adding new option \"${option}\" to mailcow.conf"
  959. echo "WATCHDOG_NOTIFY_EMAIL=" >> mailcow.conf
  960. fi
  961. elif [[ "${option}" == "LOG_LINES" ]]; then
  962. if ! grep -q "${option}" mailcow.conf; then
  963. echo "Adding new option \"${option}\" to mailcow.conf"
  964. echo '# Max log lines per service to keep in Redis logs' >> mailcow.conf
  965. echo "LOG_LINES=9999" >> mailcow.conf
  966. fi
  967. elif [[ "${option}" == "IPV4_NETWORK" ]]; then
  968. if ! grep -q "${option}" mailcow.conf; then
  969. echo "Adding new option \"${option}\" to mailcow.conf"
  970. echo '# Internal IPv4 /24 subnet, format n.n.n. (expands to n.n.n.0/24)' >> mailcow.conf
  971. echo "IPV4_NETWORK=172.22.1" >> mailcow.conf
  972. fi
  973. elif [[ "${option}" == "IPV6_NETWORK" ]]; then
  974. if ! grep -q "${option}" mailcow.conf; then
  975. echo "Adding new option \"${option}\" to mailcow.conf"
  976. echo '# Internal IPv6 subnet in fc00::/7' >> mailcow.conf
  977. echo "IPV6_NETWORK=fd4d:6169:6c63:6f77::/64" >> mailcow.conf
  978. fi
  979. elif [[ "${option}" == "SQL_PORT" ]]; then
  980. if ! grep -q "${option}" mailcow.conf; then
  981. echo "Adding new option \"${option}\" to mailcow.conf"
  982. echo '# Bind SQL to 127.0.0.1 on port 13306' >> mailcow.conf
  983. echo "SQL_PORT=127.0.0.1:13306" >> mailcow.conf
  984. fi
  985. elif [[ "${option}" == "API_KEY" ]]; then
  986. if ! grep -q "${option}" mailcow.conf; then
  987. echo "Adding new option \"${option}\" to mailcow.conf"
  988. echo '# Create or override API key for web UI' >> mailcow.conf
  989. echo "#API_KEY=" >> mailcow.conf
  990. fi
  991. elif [[ "${option}" == "API_KEY_READ_ONLY" ]]; then
  992. if ! grep -q "${option}" mailcow.conf; then
  993. echo "Adding new option \"${option}\" to mailcow.conf"
  994. echo '# Create or override read-only API key for web UI' >> mailcow.conf
  995. echo "#API_KEY_READ_ONLY=" >> mailcow.conf
  996. fi
  997. elif [[ "${option}" == "API_ALLOW_FROM" ]]; then
  998. if ! grep -q "${option}" mailcow.conf; then
  999. echo "Adding new option \"${option}\" to mailcow.conf"
  1000. echo '# Must be set for API_KEY to be active' >> mailcow.conf
  1001. echo '# IPs only, no networks (networks can be set via UI)' >> mailcow.conf
  1002. echo "#API_ALLOW_FROM=" >> mailcow.conf
  1003. fi
  1004. elif [[ "${option}" == "SNAT_TO_SOURCE" ]]; then
  1005. if ! grep -q "${option}" mailcow.conf; then
  1006. echo "Adding new option \"${option}\" to mailcow.conf"
  1007. echo '# Use this IPv4 for outgoing connections (SNAT)' >> mailcow.conf
  1008. echo "#SNAT_TO_SOURCE=" >> mailcow.conf
  1009. fi
  1010. elif [[ "${option}" == "SNAT6_TO_SOURCE" ]]; then
  1011. if ! grep -q "${option}" mailcow.conf; then
  1012. echo "Adding new option \"${option}\" to mailcow.conf"
  1013. echo '# Use this IPv6 for outgoing connections (SNAT)' >> mailcow.conf
  1014. echo "#SNAT6_TO_SOURCE=" >> mailcow.conf
  1015. fi
  1016. elif [[ "${option}" == "MAILDIR_GC_TIME" ]]; then
  1017. if ! grep -q "${option}" mailcow.conf; then
  1018. echo "Adding new option \"${option}\" to mailcow.conf"
  1019. echo '# Garbage collector cleanup' >> mailcow.conf
  1020. echo '# Deleted domains and mailboxes are moved to /var/vmail/_garbage/timestamp_sanitizedstring' >> mailcow.conf
  1021. echo '# How long should objects remain in the garbage until they are being deleted? (value in minutes)' >> mailcow.conf
  1022. echo '# Check interval is hourly' >> mailcow.conf
  1023. echo 'MAILDIR_GC_TIME=1440' >> mailcow.conf
  1024. fi
  1025. elif [[ "${option}" == "ACL_ANYONE" ]]; then
  1026. if ! grep -q "${option}" mailcow.conf; then
  1027. echo "Adding new option \"${option}\" to mailcow.conf"
  1028. echo '# Set this to "allow" to enable the anyone pseudo user. Disabled by default.' >> mailcow.conf
  1029. echo '# When enabled, ACL can be created, that apply to "All authenticated users"' >> mailcow.conf
  1030. echo '# This should probably only be activated on mail hosts, that are used exclusivly by one organisation.' >> mailcow.conf
  1031. echo '# Otherwise a user might share data with too many other users.' >> mailcow.conf
  1032. echo 'ACL_ANYONE=disallow' >> mailcow.conf
  1033. fi
  1034. elif [[ "${option}" == "ENABLE_SSL_SNI" ]]; then
  1035. if ! grep -q "${option}" mailcow.conf; then
  1036. echo "Adding new option \"${option}\" to mailcow.conf"
  1037. echo '# Create seperate certificates for all domains - y/n' >> mailcow.conf
  1038. echo '# this will allow adding more than 100 domains, but some email clients will not be able to connect with alternative hostnames' >> mailcow.conf
  1039. echo '# see https://wiki.dovecot.org/SSL/SNIClientSupport' >> mailcow.conf
  1040. echo "ENABLE_SSL_SNI=n" >> mailcow.conf
  1041. fi
  1042. elif [[ "${option}" == "SKIP_SOGO" ]]; then
  1043. if ! grep -q "${option}" mailcow.conf; then
  1044. echo "Adding new option \"${option}\" to mailcow.conf"
  1045. echo '# Skip SOGo: Will disable SOGo integration and therefore webmail, DAV protocols and ActiveSync support (experimental, unsupported, not fully implemented) - y/n' >> mailcow.conf
  1046. echo "SKIP_SOGO=n" >> mailcow.conf
  1047. fi
  1048. elif [[ "${option}" == "MAILDIR_SUB" ]]; then
  1049. if ! grep -q "${option}" mailcow.conf; then
  1050. echo "Adding new option \"${option}\" to mailcow.conf"
  1051. echo '# MAILDIR_SUB defines a path in a users virtual home to keep the maildir in. Leave empty for updated setups.' >> mailcow.conf
  1052. echo "#MAILDIR_SUB=Maildir" >> mailcow.conf
  1053. echo "MAILDIR_SUB=" >> mailcow.conf
  1054. fi
  1055. elif [[ "${option}" == "WATCHDOG_NOTIFY_WEBHOOK" ]]; then
  1056. if ! grep -q "${option}" mailcow.conf; then
  1057. echo "Adding new option \"${option}\" to mailcow.conf"
  1058. echo '# Send notifications to a webhook URL that receives a POST request with the content type "application/json".' >> mailcow.conf
  1059. echo '# You can use this to send notifications to services like Discord, Slack and others.' >> mailcow.conf
  1060. echo '#WATCHDOG_NOTIFY_WEBHOOK=https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' >> mailcow.conf
  1061. fi
  1062. elif [[ "${option}" == "WATCHDOG_NOTIFY_WEBHOOK_BODY" ]]; then
  1063. if ! grep -q "${option}" mailcow.conf; then
  1064. echo "Adding new option \"${option}\" to mailcow.conf"
  1065. echo '# JSON body included in the webhook POST request. Needs to be in single quotes.' >> mailcow.conf
  1066. echo '# Following variables are available: SUBJECT, BODY' >> mailcow.conf
  1067. WEBHOOK_BODY='{"username": "mailcow Watchdog", "content": "**${SUBJECT}**\n${BODY}"}'
  1068. echo "#WATCHDOG_NOTIFY_WEBHOOK_BODY='${WEBHOOK_BODY}'" >> mailcow.conf
  1069. fi
  1070. elif [[ "${option}" == "WATCHDOG_NOTIFY_BAN" ]]; then
  1071. if ! grep -q "${option}" mailcow.conf; then
  1072. echo "Adding new option \"${option}\" to mailcow.conf"
  1073. echo '# Notify about banned IP. Includes whois lookup.' >> mailcow.conf
  1074. echo "WATCHDOG_NOTIFY_BAN=y" >> mailcow.conf
  1075. fi
  1076. elif [[ "${option}" == "WATCHDOG_NOTIFY_START" ]]; then
  1077. if ! grep -q "${option}" mailcow.conf; then
  1078. echo "Adding new option \"${option}\" to mailcow.conf"
  1079. echo '# Send a notification when the watchdog is started.' >> mailcow.conf
  1080. echo "WATCHDOG_NOTIFY_START=y" >> mailcow.conf
  1081. fi
  1082. elif [[ "${option}" == "WATCHDOG_SUBJECT" ]]; then
  1083. if ! grep -q "${option}" mailcow.conf; then
  1084. echo "Adding new option \"${option}\" to mailcow.conf"
  1085. echo '# Subject for watchdog mails. Defaults to "Watchdog ALERT" followed by the error message.' >> mailcow.conf
  1086. echo "#WATCHDOG_SUBJECT=" >> mailcow.conf
  1087. fi
  1088. elif [[ "${option}" == "WATCHDOG_EXTERNAL_CHECKS" ]]; then
  1089. if ! grep -q "${option}" mailcow.conf; then
  1090. echo "Adding new option \"${option}\" to mailcow.conf"
  1091. echo '# Checks if mailcow is an open relay. Requires a SAL. More checks will follow.' >> mailcow.conf
  1092. echo '# No data is collected. Opt-in and anonymous.' >> mailcow.conf
  1093. echo '# Will only work with unmodified mailcow setups.' >> mailcow.conf
  1094. echo "WATCHDOG_EXTERNAL_CHECKS=n" >> mailcow.conf
  1095. fi
  1096. elif [[ "${option}" == "SOGO_EXPIRE_SESSION" ]]; then
  1097. if ! grep -q "${option}" mailcow.conf; then
  1098. echo "Adding new option \"${option}\" to mailcow.conf"
  1099. echo '# SOGo session timeout in minutes' >> mailcow.conf
  1100. echo "SOGO_EXPIRE_SESSION=480" >> mailcow.conf
  1101. fi
  1102. elif [[ "${option}" == "REDIS_PORT" ]]; then
  1103. if ! grep -q "${option}" mailcow.conf; then
  1104. echo "Adding new option \"${option}\" to mailcow.conf"
  1105. echo "REDIS_PORT=127.0.0.1:7654" >> mailcow.conf
  1106. fi
  1107. elif [[ "${option}" == "DOVECOT_MASTER_USER" ]]; then
  1108. if ! grep -q "${option}" mailcow.conf; then
  1109. echo "Adding new option \"${option}\" to mailcow.conf"
  1110. echo '# DOVECOT_MASTER_USER and _PASS must _both_ be provided. No special chars.' >> mailcow.conf
  1111. echo '# Empty by default to auto-generate master user and password on start.' >> mailcow.conf
  1112. echo '# User expands to DOVECOT_MASTER_USER@mailcow.local' >> mailcow.conf
  1113. echo '# LEAVE EMPTY IF UNSURE' >> mailcow.conf
  1114. echo "DOVECOT_MASTER_USER=" >> mailcow.conf
  1115. fi
  1116. elif [[ "${option}" == "DOVECOT_MASTER_PASS" ]]; then
  1117. if ! grep -q "${option}" mailcow.conf; then
  1118. echo "Adding new option \"${option}\" to mailcow.conf"
  1119. echo '# LEAVE EMPTY IF UNSURE' >> mailcow.conf
  1120. echo "DOVECOT_MASTER_PASS=" >> mailcow.conf
  1121. fi
  1122. elif [[ "${option}" == "MAILCOW_PASS_SCHEME" ]]; then
  1123. if ! grep -q "${option}" mailcow.conf; then
  1124. echo "Adding new option \"${option}\" to mailcow.conf"
  1125. echo '# Password hash algorithm' >> mailcow.conf
  1126. echo '# Only certain password hash algorithm are supported. For a fully list of supported schemes,' >> mailcow.conf
  1127. echo '# see https://docs.mailcow.email/models/model-passwd/' >> mailcow.conf
  1128. echo "MAILCOW_PASS_SCHEME=BLF-CRYPT" >> mailcow.conf
  1129. fi
  1130. elif [[ "${option}" == "ADDITIONAL_SERVER_NAMES" ]]; then
  1131. if ! grep -q "${option}" mailcow.conf; then
  1132. echo "Adding new option \"${option}\" to mailcow.conf"
  1133. echo '# Additional server names for mailcow UI' >> mailcow.conf
  1134. echo '#' >> mailcow.conf
  1135. echo '# Specify alternative addresses for the mailcow UI to respond to' >> mailcow.conf
  1136. echo '# This is useful when you set mail.* as ADDITIONAL_SAN and want to make sure mail.maildomain.com will always point to the mailcow UI.' >> mailcow.conf
  1137. echo '# If the server name does not match a known site, Nginx decides by best-guess and may redirect users to the wrong web root.' >> mailcow.conf
  1138. echo '# You can understand this as server_name directive in Nginx.' >> mailcow.conf
  1139. echo '# Comma separated list without spaces! Example: ADDITIONAL_SERVER_NAMES=a.b.c,d.e.f' >> mailcow.conf
  1140. echo 'ADDITIONAL_SERVER_NAMES=' >> mailcow.conf
  1141. fi
  1142. elif [[ "${option}" == "AUTODISCOVER_SAN" ]]; then
  1143. if ! grep -q "${option}" mailcow.conf; then
  1144. echo "Adding new option \"${option}\" to mailcow.conf"
  1145. echo '# Obtain certificates for autodiscover.* and autoconfig.* domains.' >> mailcow.conf
  1146. echo '# This can be useful to switch off in case you are in a scenario where a reverse proxy already handles those.' >> mailcow.conf
  1147. echo '# There are mixed scenarios where ports 80,443 are occupied and you do not want to share certs' >> mailcow.conf
  1148. echo '# between services. So acme-mailcow obtains for maildomains and all web-things get handled' >> mailcow.conf
  1149. echo '# in the reverse proxy.' >> mailcow.conf
  1150. echo 'AUTODISCOVER_SAN=y' >> mailcow.conf
  1151. fi
  1152. elif [[ "${option}" == "ACME_CONTACT" ]]; then
  1153. if ! grep -q "${option}" mailcow.conf; then
  1154. echo "Adding new option \"${option}\" to mailcow.conf"
  1155. echo '# Lets Encrypt registration contact information' >> mailcow.conf
  1156. echo '# Optional: Leave empty for none' >> mailcow.conf
  1157. echo '# This value is only used on first order!' >> mailcow.conf
  1158. echo '# Setting it at a later point will require the following steps:' >> mailcow.conf
  1159. echo '# https://docs.mailcow.email/troubleshooting/debug-reset_tls/' >> mailcow.conf
  1160. echo 'ACME_CONTACT=' >> mailcow.conf
  1161. fi
  1162. elif [[ "${option}" == "WEBAUTHN_ONLY_TRUSTED_VENDORS" ]]; then
  1163. if ! grep -q "${option}" mailcow.conf; then
  1164. echo "Adding new option \"${option}\" to mailcow.conf"
  1165. echo "# WebAuthn device manufacturer verification" >> mailcow.conf
  1166. echo '# After setting WEBAUTHN_ONLY_TRUSTED_VENDORS=y only devices from trusted manufacturers are allowed' >> mailcow.conf
  1167. echo '# root certificates can be placed for validation under mailcow-dockerized/data/web/inc/lib/WebAuthn/rootCertificates' >> mailcow.conf
  1168. echo 'WEBAUTHN_ONLY_TRUSTED_VENDORS=n' >> mailcow.conf
  1169. fi
  1170. elif [[ "${option}" == "SPAMHAUS_DQS_KEY" ]]; then
  1171. if ! grep -q "${option}" mailcow.conf; then
  1172. echo "Adding new option \"${option}\" to mailcow.conf"
  1173. echo "# Spamhaus Data Query Service Key" >> mailcow.conf
  1174. echo '# Optional: Leave empty for none' >> mailcow.conf
  1175. echo '# Enter your key here if you are using a blocked ASN (OVH, AWS, Cloudflare e.g) for the unregistered Spamhaus Blocklist.' >> mailcow.conf
  1176. echo '# If empty, it will completely disable Spamhaus blocklists if it detects that you are running on a server using a blocked AS.' >> mailcow.conf
  1177. echo '# Otherwise it will work as usual.' >> mailcow.conf
  1178. echo 'SPAMHAUS_DQS_KEY=' >> mailcow.conf
  1179. fi
  1180. elif [[ "${option}" == "WATCHDOG_VERBOSE" ]]; then
  1181. if ! grep -q "${option}" mailcow.conf; then
  1182. echo "Adding new option \"${option}\" to mailcow.conf"
  1183. echo '# Enable watchdog verbose logging' >> mailcow.conf
  1184. echo 'WATCHDOG_VERBOSE=n' >> mailcow.conf
  1185. fi
  1186. elif [[ "${option}" == "SKIP_UNBOUND_HEALTHCHECK" ]]; then
  1187. if ! grep -q "${option}" mailcow.conf; then
  1188. echo "Adding new option \"${option}\" to mailcow.conf"
  1189. echo '# Skip Unbound (DNS Resolver) Healthchecks (NOT Recommended!) - y/n' >> mailcow.conf
  1190. echo 'SKIP_UNBOUND_HEALTHCHECK=n' >> mailcow.conf
  1191. fi
  1192. elif [[ "${option}" == "DISABLE_NETFILTER_ISOLATION_RULE" ]]; then
  1193. if ! grep -q "${option}" mailcow.conf; then
  1194. echo "Adding new option \"${option}\" to mailcow.conf"
  1195. echo '# Prevent netfilter from setting an iptables/nftables rule to isolate the mailcow docker network - y/n' >> mailcow.conf
  1196. echo '# CAUTION: Disabling this may expose container ports to other neighbors on the same subnet, even if the ports are bound to localhost' >> mailcow.conf
  1197. echo 'DISABLE_NETFILTER_ISOLATION_RULE=n' >> mailcow.conf
  1198. fi
  1199. elif [[ "${option}" == "REDISPASS" ]]; then
  1200. if ! grep -q "${option}" mailcow.conf; then
  1201. echo "Adding new option \"${option}\" to mailcow.conf"
  1202. echo -e '\n# ------------------------------' >> mailcow.conf
  1203. echo '# REDIS configuration' >> mailcow.conf
  1204. echo -e '# ------------------------------\n' >> mailcow.conf
  1205. echo "REDISPASS=$(LC_ALL=C </dev/urandom tr -dc A-Za-z0-9 2> /dev/null | head -c 28)" >> mailcow.conf
  1206. fi
  1207. elif ! grep -q "${option}" mailcow.conf; then
  1208. echo "Adding new option \"${option}\" to mailcow.conf"
  1209. echo "${option}=n" >> mailcow.conf
  1210. fi
  1211. done
  1212. if [[ ("${SKIP_PING_CHECK}" == "y") ]]; then
  1213. echo -e "\e[32mSkipping Ping Check...\e[0m"
  1214. else
  1215. echo -en "Checking internet connection... "
  1216. if ! check_online_status; then
  1217. echo -e "\e[31mfailed\e[0m"
  1218. exit 1
  1219. else
  1220. echo -e "\e[32mOK\e[0m"
  1221. fi
  1222. fi
  1223. if ! [ "$NEW_BRANCH" ]; then
  1224. echo -e "\e[33mDetecting which build your mailcow runs on...\e[0m"
  1225. sleep 1
  1226. if [ "${BRANCH}" == "master" ]; then
  1227. echo -e "\e[32mYou are receiving stable updates (master).\e[0m"
  1228. echo -e "\e[33mTo change that run the update.sh Script one time with the --nightly parameter to switch to nightly builds.\e[0m"
  1229. elif [ "${BRANCH}" == "nightly" ]; then
  1230. echo -e "\e[31mYou are receiving unstable updates (nightly). These are for testing purposes only!!!\e[0m"
  1231. sleep 1
  1232. echo -e "\e[33mTo change that run the update.sh Script one time with the --stable parameter to switch to stable builds.\e[0m"
  1233. elif [ "${BRANCH}" == "legacy" ]; then
  1234. echo -e "\e[31mYou are receiving legacy updates. The legacy branch will only recieve security updates until February 2026.\e[0m"
  1235. sleep 1
  1236. echo -e "\e[33mTo change that run the update.sh Script one time with the --stable parameter to switch to stable builds.\e[0m"
  1237. else
  1238. echo -e "\e[33mYou are receiving updates from an unsupported branch.\e[0m"
  1239. sleep 1
  1240. echo -e "\e[33mThe mailcow stack might still work but it is recommended to switch to the master branch (stable builds).\e[0m"
  1241. echo -e "\e[33mTo change that run the update.sh Script one time with the --stable parameter to switch to stable builds.\e[0m"
  1242. fi
  1243. elif [ "$FORCE" ]; then
  1244. echo -e "\e[31mYou are running in forced mode!\e[0m"
  1245. echo -e "\e[31mA Branch Switch can only be performed manually (monitored).\e[0m"
  1246. echo -e "\e[31mPlease rerun the update.sh Script without the --force/-f parameter.\e[0m"
  1247. sleep 1
  1248. elif [ "$NEW_BRANCH" == "master" ] && [ "$CURRENT_BRANCH" != "master" ]; then
  1249. echo -e "\e[33mYou are about to switch your mailcow updates to the stable (master) branch.\e[0m"
  1250. sleep 1
  1251. echo -e "\e[33mBefore you do: Please take a backup of all components to ensure that no data is lost...\e[0m"
  1252. sleep 1
  1253. echo -e "\e[31mWARNING: Please see on GitHub or ask in the community if a switch to master is stable or not.
  1254. In some rear cases an update back to master can destroy your mailcow configuration such as database upgrade, etc.
  1255. Normally an upgrade back to master should be safe during each full release.
  1256. Check GitHub for Database changes and update only if there similar to the full release!\e[0m"
  1257. read -r -p "Are you sure you that want to continue upgrading to the stable (master) branch? [y/N] " response
  1258. if [[ ! "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  1259. echo "OK. If you prepared yourself for that please run the update.sh Script with the --stable parameter again to trigger this process here."
  1260. exit 0
  1261. fi
  1262. BRANCH="$NEW_BRANCH"
  1263. DIFF_DIRECTORY=update_diffs
  1264. DIFF_FILE="${DIFF_DIRECTORY}/diff_before_upgrade_to_master_$(date +"%Y-%m-%d-%H-%M-%S")"
  1265. mv diff_before_upgrade* "${DIFF_DIRECTORY}/" 2> /dev/null
  1266. if ! git diff-index --quiet HEAD; then
  1267. echo -e "\e[32mSaving diff to ${DIFF_FILE}...\e[0m"
  1268. mkdir -p "${DIFF_DIRECTORY}"
  1269. git diff "${BRANCH}" --stat > "${DIFF_FILE}"
  1270. git diff "${BRANCH}" >> "${DIFF_FILE}"
  1271. fi
  1272. echo -e "\e[32mSwitching Branch to ${BRANCH}...\e[0m"
  1273. git fetch origin
  1274. git checkout -f "${BRANCH}"
  1275. elif [ "$NEW_BRANCH" == "nightly" ] && [ "$CURRENT_BRANCH" != "nightly" ]; then
  1276. echo -e "\e[33mYou are about to switch your mailcow Updates to the unstable (nightly) branch.\e[0m"
  1277. sleep 1
  1278. echo -e "\e[33mBefore you do: Please take a backup of all components to ensure that no Data is lost...\e[0m"
  1279. sleep 1
  1280. echo -e "\e[31mWARNING: A switch to nightly is possible any time. But a switch back (to master) isn't.\e[0m"
  1281. read -r -p "Are you sure you that want to continue upgrading to the unstable (nightly) branch? [y/N] " response
  1282. if [[ ! "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  1283. echo "OK. If you prepared yourself for that please run the update.sh Script with the --nightly parameter again to trigger this process here."
  1284. exit 0
  1285. fi
  1286. BRANCH=$NEW_BRANCH
  1287. DIFF_DIRECTORY=update_diffs
  1288. DIFF_FILE=${DIFF_DIRECTORY}/diff_before_upgrade_to_nightly_$(date +"%Y-%m-%d-%H-%M-%S")
  1289. mv diff_before_upgrade* ${DIFF_DIRECTORY}/ 2> /dev/null
  1290. if ! git diff-index --quiet HEAD; then
  1291. echo -e "\e[32mSaving diff to ${DIFF_FILE}...\e[0m"
  1292. mkdir -p ${DIFF_DIRECTORY}
  1293. git diff "${BRANCH}" --stat > "${DIFF_FILE}"
  1294. git diff "${BRANCH}" >> "${DIFF_FILE}"
  1295. fi
  1296. git fetch origin
  1297. git checkout -f "${BRANCH}"
  1298. elif [ "$NEW_BRANCH" == "legacy" ] && [ "$CURRENT_BRANCH" != "legacy" ]; then
  1299. echo -e "\e[33mYou are about to switch your mailcow Updates to the legacy branch.\e[0m"
  1300. sleep 1
  1301. echo -e "\e[33mBefore you do: Please take a backup of all components to ensure that no Data is lost...\e[0m"
  1302. sleep 1
  1303. echo -e "\e[31mWARNING: A switch to stable or nightly is possible any time.\e[0m"
  1304. read -r -p "Are you sure you want to continue upgrading to the legacy branch? [y/N] " response
  1305. if [[ ! "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  1306. echo "OK. If you prepared yourself for that please run the update.sh Script with the --legacy parameter again to trigger this process here."
  1307. exit 0
  1308. fi
  1309. BRANCH=$NEW_BRANCH
  1310. DIFF_DIRECTORY=update_diffs
  1311. DIFF_FILE=${DIFF_DIRECTORY}/diff_before_upgrade_to_legacy_$(date +"%Y-%m-%d-%H-%M-%S")
  1312. mv diff_before_upgrade* ${DIFF_DIRECTORY}/ 2> /dev/null
  1313. if ! git diff-index --quiet HEAD; then
  1314. echo -e "\e[32mSaving diff to ${DIFF_FILE}...\e[0m"
  1315. mkdir -p ${DIFF_DIRECTORY}
  1316. git diff "${BRANCH}" --stat > "${DIFF_FILE}"
  1317. git diff "${BRANCH}" >> "${DIFF_FILE}"
  1318. fi
  1319. git fetch origin
  1320. git checkout -f "${BRANCH}"
  1321. fi
  1322. if [ ! "$DEV" ]; then
  1323. echo -e "\e[32mChecking for newer update script...\e[0m"
  1324. SHA1_1="$(sha1sum update.sh)"
  1325. git fetch origin #${BRANCH}
  1326. git checkout "origin/${BRANCH}" update.sh
  1327. SHA1_2=$(sha1sum update.sh)
  1328. if [[ "${SHA1_1}" != "${SHA1_2}" ]]; then
  1329. echo "update.sh changed, please run this script again, exiting."
  1330. chmod +x update.sh
  1331. exit 2
  1332. fi
  1333. fi
  1334. if [ ! "$FORCE" ]; then
  1335. read -r -p "Are you sure you want to update mailcow: dockerized? All containers will be stopped. [y/N] " response
  1336. if [[ ! "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  1337. echo "OK, exiting."
  1338. exit 0
  1339. fi
  1340. detect_major_update
  1341. migrate_docker_nat
  1342. fi
  1343. remove_obsolete_nginx_ports
  1344. echo -e "\e[32mValidating docker-compose stack configuration...\e[0m"
  1345. sed -i 's/HTTPS_BIND:-:/HTTPS_BIND:-/g' docker-compose.yml
  1346. sed -i 's/HTTP_BIND:-:/HTTP_BIND:-/g' docker-compose.yml
  1347. if ! $COMPOSE_COMMAND config -q; then
  1348. echo -e "\e[31m\nOh no, something went wrong. Please check the error message above.\e[0m"
  1349. exit 1
  1350. fi
  1351. echo -e "\e[32mChecking for conflicting bridges...\e[0m"
  1352. MAILCOW_BRIDGE=$($COMPOSE_COMMAND config | grep -i com.docker.network.bridge.name | cut -d':' -f2)
  1353. while read NAT_ID; do
  1354. iptables -t nat -D POSTROUTING "$NAT_ID"
  1355. done < <(iptables -L -vn -t nat --line-numbers | grep "$IPV4_NETWORK" | grep -E 'MASQUERADE.*all' | grep -v "${MAILCOW_BRIDGE}" | cut -d' ' -f1)
  1356. DIFF_DIRECTORY=update_diffs
  1357. DIFF_FILE=${DIFF_DIRECTORY}/diff_before_update_$(date +"%Y-%m-%d-%H-%M-%S")
  1358. mv diff_before_update* ${DIFF_DIRECTORY}/ 2> /dev/null
  1359. if ! git diff-index --quiet HEAD; then
  1360. echo -e "\e[32mSaving diff to ${DIFF_FILE}...\e[0m"
  1361. mkdir -p ${DIFF_DIRECTORY}
  1362. git diff --stat > "${DIFF_FILE}"
  1363. git diff >> "${DIFF_FILE}"
  1364. fi
  1365. echo -e "\e[32mPrefetching images...\e[0m"
  1366. prefetch_images
  1367. echo -e "\e[32mStopping mailcow...\e[0m"
  1368. sleep 2
  1369. MAILCOW_CONTAINERS=($($COMPOSE_COMMAND ps -q))
  1370. $COMPOSE_COMMAND down
  1371. echo -e "\e[32mChecking for remaining containers...\e[0m"
  1372. sleep 2
  1373. for container in "${MAILCOW_CONTAINERS[@]}"; do
  1374. docker rm -f "$container" 2> /dev/null
  1375. done
  1376. [[ -f data/conf/nginx/ZZZ-ejabberd.conf ]] && rm data/conf/nginx/ZZZ-ejabberd.conf
  1377. migrate_solr_config_options
  1378. adapt_new_options
  1379. # Silently fixing remote url from andryyy to mailcow
  1380. # git remote set-url origin https://github.com/mailcow/mailcow-dockerized
  1381. DEFAULT_REPO="https://github.com/mailcow/mailcow-dockerized"
  1382. CURRENT_REPO=$(git config --get remote.origin.url)
  1383. if [ "$CURRENT_REPO" != "$DEFAULT_REPO" ]; then
  1384. echo "The Repository currently used is not the default Mailcow Repository."
  1385. echo "Currently Repository: $CURRENT_REPO"
  1386. echo "Default Repository: $DEFAULT_REPO"
  1387. if [ ! "$FORCE" ]; then
  1388. read -r -p "Should it be changed back to default? [y/N] " repo_response
  1389. if [[ "$repo_response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
  1390. git remote set-url origin $DEFAULT_REPO
  1391. fi
  1392. else
  1393. echo "Running in forced mode... setting Repo to default!"
  1394. git remote set-url origin $DEFAULT_REPO
  1395. fi
  1396. fi
  1397. if [ ! "$DEV" ]; then
  1398. echo -e "\e[32mCommitting current status...\e[0m"
  1399. [[ -z "$(git config user.name)" ]] && git config user.name moo
  1400. [[ -z "$(git config user.email)" ]] && git config user.email moo@cow.moo
  1401. [[ ! -z $(git ls-files data/conf/rspamd/override.d/worker-controller-password.inc) ]] && git rm data/conf/rspamd/override.d/worker-controller-password.inc
  1402. git add -u
  1403. git commit -am "Before update on ${DATE}" > /dev/null
  1404. echo -e "\e[32mFetching updated code from remote...\e[0m"
  1405. git fetch origin #${BRANCH}
  1406. echo -e "\e[32mMerging local with remote code (recursive, strategy: \"${MERGE_STRATEGY:-theirs}\", options: \"patience\"...\e[0m"
  1407. git config merge.defaultToUpstream true
  1408. git merge -X"${MERGE_STRATEGY:-theirs}" -Xpatience -m "After update on ${DATE}"
  1409. # Need to use a variable to not pass return codes of if checks
  1410. MERGE_RETURN=$?
  1411. if [[ ${MERGE_RETURN} == 128 ]]; then
  1412. echo -e "\e[31m\nOh no, what happened?\n=> You most likely added files to your local mailcow instance that were now added to the official mailcow repository. Please move them to another location before updating mailcow.\e[0m"
  1413. exit 1
  1414. elif [[ ${MERGE_RETURN} == 1 ]]; then
  1415. echo -e "\e[93mPotential conflict, trying to fix...\e[0m"
  1416. git status --porcelain | grep -E "UD|DU" | awk '{print $2}' | xargs rm -v
  1417. git add -A
  1418. git commit -m "After update on ${DATE}" > /dev/null
  1419. git checkout .
  1420. echo -e "\e[32mRemoved and recreated files if necessary.\e[0m"
  1421. elif [[ ${MERGE_RETURN} != 0 ]]; then
  1422. echo -e "\e[31m\nOh no, something went wrong. Please check the error message above.\e[0m"
  1423. echo
  1424. echo "Run $COMPOSE_COMMAND up -d to restart your stack without updates or try again after fixing the mentioned errors."
  1425. exit 1
  1426. fi
  1427. elif [ "$DEV" ]; then
  1428. echo -e "\e[33mDEVELOPER MODE: Not creating a git diff and commiting it to prevent development stuff within a backup diff...\e[0m"
  1429. fi
  1430. echo -e "\e[32mFetching new images, if any...\e[0m"
  1431. sleep 2
  1432. $COMPOSE_COMMAND pull
  1433. # Fix missing SSL, does not overwrite existing files
  1434. [[ ! -d data/assets/ssl ]] && mkdir -p data/assets/ssl
  1435. cp -n -d data/assets/ssl-example/*.pem data/assets/ssl/
  1436. echo -e "Checking IPv6 settings... "
  1437. if grep -q 'SYSCTL_IPV6_DISABLED=1' mailcow.conf; then
  1438. echo
  1439. echo '!! IMPORTANT !!'
  1440. echo
  1441. echo 'SYSCTL_IPV6_DISABLED was removed due to complications. IPv6 can be disabled by editing "docker-compose.yml" and setting "enable_ipv6: true" to "enable_ipv6: false".'
  1442. echo "This setting will only be active after a complete shutdown of mailcow by running $COMPOSE_COMMAND down followed by $COMPOSE_COMMAND up -d."
  1443. echo
  1444. echo '!! IMPORTANT !!'
  1445. echo
  1446. read -p "Press any key to continue..." < /dev/tty
  1447. fi
  1448. # Checking for old project name bug
  1449. sed -i --follow-symlinks 's#COMPOSEPROJECT_NAME#COMPOSE_PROJECT_NAME#g' mailcow.conf
  1450. # Fix Rspamd maps
  1451. if [ -f data/conf/rspamd/custom/global_from_blacklist.map ]; then
  1452. mv data/conf/rspamd/custom/global_from_blacklist.map data/conf/rspamd/custom/global_smtp_from_blacklist.map
  1453. fi
  1454. if [ -f data/conf/rspamd/custom/global_from_whitelist.map ]; then
  1455. mv data/conf/rspamd/custom/global_from_whitelist.map data/conf/rspamd/custom/global_smtp_from_whitelist.map
  1456. fi
  1457. # Fix deprecated metrics.conf
  1458. if [ -f "data/conf/rspamd/local.d/metrics.conf" ]; then
  1459. if [ ! -z "$(git diff --name-only origin/master data/conf/rspamd/local.d/metrics.conf)" ]; then
  1460. echo -e "\e[33mWARNING\e[0m - Please migrate your customizations of data/conf/rspamd/local.d/metrics.conf to actions.conf and groups.conf after this update."
  1461. echo "The deprecated configuration file metrics.conf will be moved to metrics.conf_deprecated after updating mailcow."
  1462. fi
  1463. mv data/conf/rspamd/local.d/metrics.conf data/conf/rspamd/local.d/metrics.conf_deprecated
  1464. fi
  1465. # Set app_info.inc.php
  1466. if [ ${BRANCH} == "master" ]; then
  1467. mailcow_git_version=$(git describe --tags $(git rev-list --tags --max-count=1))
  1468. elif [ ${BRANCH} == "nightly" ]; then
  1469. mailcow_git_version=$(git rev-parse --short $(git rev-parse @{upstream}))
  1470. mailcow_last_git_version=""
  1471. else
  1472. mailcow_git_version=$(git rev-parse --short HEAD)
  1473. mailcow_last_git_version=""
  1474. fi
  1475. mailcow_git_commit=$(git rev-parse "origin/${BRANCH}")
  1476. mailcow_git_commit_date=$(git log -1 --format=%ci @{upstream} )
  1477. if [ $? -eq 0 ]; then
  1478. echo '<?php' > data/web/inc/app_info.inc.php
  1479. echo ' $MAILCOW_GIT_VERSION="'$mailcow_git_version'";' >> data/web/inc/app_info.inc.php
  1480. echo ' $MAILCOW_LAST_GIT_VERSION="";' >> data/web/inc/app_info.inc.php
  1481. echo ' $MAILCOW_GIT_OWNER="mailcow";' >> data/web/inc/app_info.inc.php
  1482. echo ' $MAILCOW_GIT_REPO="mailcow-dockerized";' >> data/web/inc/app_info.inc.php
  1483. echo ' $MAILCOW_GIT_URL="https://github.com/mailcow/mailcow-dockerized";' >> data/web/inc/app_info.inc.php
  1484. echo ' $MAILCOW_GIT_COMMIT="'$mailcow_git_commit'";' >> data/web/inc/app_info.inc.php
  1485. echo ' $MAILCOW_GIT_COMMIT_DATE="'$mailcow_git_commit_date'";' >> data/web/inc/app_info.inc.php
  1486. echo ' $MAILCOW_BRANCH="'$BRANCH'";' >> data/web/inc/app_info.inc.php
  1487. echo ' $MAILCOW_UPDATEDAT='$(date +%s)';' >> data/web/inc/app_info.inc.php
  1488. echo '?>' >> data/web/inc/app_info.inc.php
  1489. else
  1490. echo '<?php' > data/web/inc/app_info.inc.php
  1491. echo ' $MAILCOW_GIT_VERSION="'$mailcow_git_version'";' >> data/web/inc/app_info.inc.php
  1492. echo ' $MAILCOW_LAST_GIT_VERSION="";' >> data/web/inc/app_info.inc.php
  1493. echo ' $MAILCOW_GIT_OWNER="mailcow";' >> data/web/inc/app_info.inc.php
  1494. echo ' $MAILCOW_GIT_REPO="mailcow-dockerized";' >> data/web/inc/app_info.inc.php
  1495. echo ' $MAILCOW_GIT_URL="https://github.com/mailcow/mailcow-dockerized";' >> data/web/inc/app_info.inc.php
  1496. echo ' $MAILCOW_GIT_COMMIT="";' >> data/web/inc/app_info.inc.php
  1497. echo ' $MAILCOW_GIT_COMMIT_DATE="";' >> data/web/inc/app_info.inc.php
  1498. echo ' $MAILCOW_BRANCH="'$BRANCH'";' >> data/web/inc/app_info.inc.php
  1499. echo ' $MAILCOW_UPDATEDAT='$(date +%s)';' >> data/web/inc/app_info.inc.php
  1500. echo '?>' >> data/web/inc/app_info.inc.php
  1501. echo -e "\e[33mCannot determine current git repository version...\e[0m"
  1502. fi
  1503. if [[ ${SKIP_START} == "y" ]]; then
  1504. echo -e "\e[33mNot starting mailcow, please run \"$COMPOSE_COMMAND up -d --remove-orphans\" to start mailcow.\e[0m"
  1505. else
  1506. echo -e "\e[32mStarting mailcow...\e[0m"
  1507. sleep 2
  1508. $COMPOSE_COMMAND up -d --remove-orphans
  1509. fi
  1510. echo -e "\e[32mCollecting garbage...\e[0m"
  1511. docker_garbage
  1512. # Run post-update-hook
  1513. if [ -f "${SCRIPT_DIR}/post_update_hook.sh" ]; then
  1514. bash "${SCRIPT_DIR}/post_update_hook.sh"
  1515. fi
  1516. # echo "In case you encounter any problem, hard-reset to a state before updating mailcow:"
  1517. # echo
  1518. # git reflog --color=always | grep "Before update on "
  1519. # echo
  1520. # echo "Use \"git reset --hard hash-on-the-left\" and run $COMPOSE_COMMAND up -d afterwards."