update.sh 76 KB

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