blob: f1e31652cd36b23fa9d2216372ee757e3f9527b9 [file] [log] [blame]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001#!/usr/bin/env bash
2
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01003############## Begin Function Section ##############
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01004
5check_online_status() {
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01006 CHECK_ONLINE_DOMAINS=('https://github.com' 'https://hub.docker.com')
7 for domain in "${CHECK_ONLINE_DOMAINS[@]}"; do
8 if timeout 6 curl --head --silent --output /dev/null ${domain}; then
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01009 return 0
10 fi
11 done
12 return 1
13}
14
15prefetch_images() {
16 [[ -z ${BRANCH} ]] && { echo -e "\e[33m\nUnknown branch...\e[0m"; exit 1; }
17 git fetch origin #${BRANCH}
18 while read image; do
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +020019 if [[ "${image}" == "robbertkl/ipv6nat" ]]; then
20 if ! grep -qi "ipv6nat-mailcow" docker-compose.yml || grep -qi "enable_ipv6: false" docker-compose.yml; then
21 continue
22 fi
23 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010024 RET_C=0
25 until docker pull ${image}; do
26 RET_C=$((RET_C + 1))
27 echo -e "\e[33m\nError pulling $image, retrying...\e[0m"
28 [ ${RET_C} -gt 3 ] && { echo -e "\e[31m\nToo many failed retries, exiting\e[0m"; exit 1; }
29 sleep 1
30 done
31 done < <(git show origin/${BRANCH}:docker-compose.yml | grep "image:" | awk '{ gsub("image:","", $3); print $2 }')
32}
33
34docker_garbage() {
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +010035 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010036 IMGS_TO_DELETE=()
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010037
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +010038 declare -A IMAGES_INFO
39 COMPOSE_IMAGES=($(grep -oP "image: \Kmailcow.+" "${SCRIPT_DIR}/docker-compose.yml"))
40
41 for existing_image in $(docker images --format "{{.ID}}:{{.Repository}}:{{.Tag}}" | grep 'mailcow/'); do
42 ID=$(echo $existing_image | cut -d ':' -f 1)
43 REPOSITORY=$(echo $existing_image | cut -d ':' -f 2)
44 TAG=$(echo $existing_image | cut -d ':' -f 3)
45
46 if [[ " ${COMPOSE_IMAGES[@]} " =~ " ${REPOSITORY}:${TAG} " ]]; then
47 continue
48 else
49 IMGS_TO_DELETE+=("$ID")
50 IMAGES_INFO["$ID"]="$REPOSITORY:$TAG"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010051 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010052 done
53
54 if [[ ! -z ${IMGS_TO_DELETE[*]} ]]; then
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +010055 echo "The following unused mailcow images were found:"
56 for id in "${IMGS_TO_DELETE[@]}"; do
57 echo " ${IMAGES_INFO[$id]} ($id)"
58 done
59
60 if [ ! $FORCE ]; then
61 read -r -p "Do you want to delete them to free up some space? [y/N] " response
62 if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
63 docker rmi ${IMGS_TO_DELETE[*]}
64 else
65 echo "OK, skipped."
66 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010067 else
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +010068 echo "Running in forced mode! Force removing old mailcow images..."
69 docker rmi ${IMGS_TO_DELETE[*]}
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010070 fi
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +010071 echo -e "\e[32mFurther cleanup...\e[0m"
72 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\""
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010073 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +010074}
75
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +020076in_array() {
77 local e match="$1"
78 shift
79 for e; do [[ "$e" == "$match" ]] && return 0; done
80 return 1
81}
82
83migrate_docker_nat() {
84 NAT_CONFIG='{"ipv6":true,"fixed-cidr-v6":"fd00:dead:beef:c0::/80","experimental":true,"ip6tables":true}'
85 # Min Docker version
86 DOCKERV_REQ=20.10.2
87 # Current Docker version
88 DOCKERV_CUR=$(docker version -f '{{.Server.Version}}')
89 if grep -qi "ipv6nat-mailcow" docker-compose.yml && grep -qi "enable_ipv6: true" docker-compose.yml; then
90 echo -e "\e[32mNative IPv6 implementation available.\e[0m"
91 echo "This will enable experimental features in the Docker daemon and configure Docker to do the IPv6 NATing instead of ipv6nat-mailcow."
92 echo '!!! This step is recommended !!!'
93 echo "mailcow will try to roll back the changes if starting Docker fails after modifying the daemon.json configuration file."
94 read -r -p "Should we try to enable the native IPv6 implementation in Docker now (recommended)? [y/N] " dockernatresponse
95 if [[ ! "${dockernatresponse}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
96 echo "OK, skipping this step."
97 return 0
98 fi
99 fi
100 # Sort versions and check if we are running a newer or equal version to req
101 if [ $(printf "${DOCKERV_REQ}\n${DOCKERV_CUR}" | sort -V | tail -n1) == "${DOCKERV_CUR}" ]; then
102 # If Dockerd daemon json exists
103 if [ -s /etc/docker/daemon.json ]; then
104 IFS=',' read -r -a dockerconfig <<< $(cat /etc/docker/daemon.json | tr -cd '[:alnum:],')
105 if ! in_array ipv6true "${dockerconfig[@]}" || \
106 ! in_array experimentaltrue "${dockerconfig[@]}" || \
107 ! in_array ip6tablestrue "${dockerconfig[@]}" || \
108 ! grep -qi "fixed-cidr-v6" /etc/docker/daemon.json; then
109 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."
110 echo "You will need to merge your existing configuration manually or fix/delete the existing daemon.json configuration before trying the update process again."
111 echo -e "Please merge the following content and restart the Docker daemon:\n"
112 echo ${NAT_CONFIG}
113 return 1
114 fi
115 else
116 echo "Working on IPv6 NAT, please wait..."
117 echo ${NAT_CONFIG} > /etc/docker/daemon.json
118 ip6tables -F -t nat
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100119 [[ -e /etc/rc.conf ]] && rc-service docker restart || systemctl restart docker.service
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +0100120 if [[ $? -ne 0 ]]; then
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200121 echo -e "\e[31mError:\e[0m Failed to activate IPv6 NAT! Reverting and exiting."
122 rm /etc/docker/daemon.json
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100123 if [[ -e /etc/rc.conf ]]; then
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +0100124 rc-service docker restart
125 else
126 systemctl reset-failed docker.service
127 systemctl restart docker.service
128 fi
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200129 return 1
130 fi
131 fi
132 # Removing legacy container
133 sed -i '/ipv6nat-mailcow:$/,/^$/d' docker-compose.yml
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +0100134 if [ -s docker-compose.override.yml ]; then
135 sed -i '/ipv6nat-mailcow:$/,/^$/d' docker-compose.override.yml
136 if [[ "$(cat docker-compose.override.yml | sed '/^\s*$/d' | wc -l)" == "2" ]]; then
137 mv docker-compose.override.yml docker-compose.override.yml_backup
138 fi
139 fi
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200140 echo -e "\e[32mGreat! \e[0mNative IPv6 NAT is active.\e[0m"
141 else
142 echo -e "\e[31mPlease upgrade Docker to version ${DOCKERV_REQ} or above.\e[0m"
143 return 0
144 fi
145}
146
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100147remove_obsolete_nginx_ports() {
148 # Removing obsolete docker-compose.override.yml
149 for override in docker-compose.override.yml docker-compose.override.yaml; do
150 if [ -s $override ] ; then
151 if cat $override | grep nginx-mailcow > /dev/null 2>&1; then
152 if cat $override | grep -E '(\[::])' > /dev/null 2>&1; then
153 if cat $override | grep -w 80:80 > /dev/null 2>&1 && cat $override | grep -w 443:443 > /dev/null 2>&1 ; then
154 echo -e "\e[33mBacking up ${override} to preserve custom changes...\e[0m"
155 echo -e "\e[33m!!! Manual Merge needed (if other overrides are set) !!!\e[0m"
156 sleep 3
157 cp $override ${override}_backup
158 sed -i '/nginx-mailcow:$/,/^$/d' $override
159 echo -e "\e[33mRemoved obsolete NGINX IPv6 Bind from original override File.\e[0m"
160 if [[ "$(cat $override | sed '/^\s*$/d' | wc -l)" == "2" ]]; then
161 mv $override ${override}_empty
162 echo -e "\e[31m${override} is empty. Renamed it to ensure mailcow is startable.\e[0m"
163 fi
164 fi
165 fi
166 fi
167 fi
168 done
169}
170
171detect_docker_compose_command(){
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100172if ! [[ "${DOCKER_COMPOSE_VERSION}" =~ ^(native|standalone)$ ]]; then
173 if docker compose > /dev/null 2>&1; then
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100174 if docker compose version --short | grep -e "^2." -e "^v2." > /dev/null 2>&1; then
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100175 DOCKER_COMPOSE_VERSION=native
176 COMPOSE_COMMAND="docker compose"
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100177 echo -e "\e[33mFound Docker Compose Plugin (native).\e[0m"
178 echo -e "\e[33mSetting the DOCKER_COMPOSE_VERSION Variable to native\e[0m"
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100179 sed -i 's/^DOCKER_COMPOSE_VERSION=.*/DOCKER_COMPOSE_VERSION=native/' $SCRIPT_DIR/mailcow.conf
180 sleep 2
181 echo -e "\e[33mNotice: You'll have to update this Compose Version via your Package Manager manually!\e[0m"
182 else
183 echo -e "\e[31mCannot find Docker Compose with a Version Higher than 2.X.X.\e[0m"
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100184 echo -e "\e[31mPlease update/install it manually regarding to this doc site: https://docs.mailcow.email/install/\e[0m"
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100185 exit 1
186 fi
187 elif docker-compose > /dev/null 2>&1; then
188 if ! [[ $(alias docker-compose 2> /dev/null) ]] ; then
189 if docker-compose version --short | grep "^2." > /dev/null 2>&1; then
190 DOCKER_COMPOSE_VERSION=standalone
191 COMPOSE_COMMAND="docker-compose"
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100192 echo -e "\e[33mFound Docker Compose Standalone.\e[0m"
193 echo -e "\e[33mSetting the DOCKER_COMPOSE_VERSION Variable to standalone\e[0m"
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100194 sed -i 's/^DOCKER_COMPOSE_VERSION=.*/DOCKER_COMPOSE_VERSION=standalone/' $SCRIPT_DIR/mailcow.conf
195 sleep 2
196 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"
197 else
198 echo -e "\e[31mCannot find Docker Compose with a Version Higher than 2.X.X.\e[0m"
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100199 echo -e "\e[31mPlease update/install regarding to this doc site: https://docs.mailcow.email/install/\e[0m"
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100200 exit 1
201 fi
202 fi
203
204 else
205 echo -e "\e[31mCannot find Docker Compose.\e[0m"
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100206 echo -e "\e[31mPlease install it regarding to this doc site: https://docs.mailcow.email/install/\e[0m"
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100207 exit 1
208 fi
209
210elif [ "${DOCKER_COMPOSE_VERSION}" == "native" ]; then
211 COMPOSE_COMMAND="docker compose"
212 # Check if Native Compose works and has not been deleted
213 if ! $COMPOSE_COMMAND > /dev/null 2>&1; then
214 # IF it not exists/work anymore try the other command
215 COMPOSE_COMMAND="docker-compose"
216 if ! $COMPOSE_COMMAND > /dev/null 2>&1 || ! $COMPOSE_COMMAND --version | grep "^2." > /dev/null 2>&1; then
217 # IF it cannot find Standalone in > 2.X, then script stops
218 echo -e "\e[31mCannot find Docker Compose or the Version is lower then 2.X.X.\e[0m"
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100219 echo -e "\e[31mPlease install it regarding to this doc site: https://docs.mailcow.email/install/\e[0m"
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100220 exit 1
221 fi
222 # If it finds the standalone Plugin it will use this instead and change the mailcow.conf Variable accordingly
223 echo -e "\e[31mFound different Docker Compose Version then declared in mailcow.conf!\e[0m"
224 echo -e "\e[31mSetting the DOCKER_COMPOSE_VERSION Variable from native to standalone\e[0m"
225 sed -i 's/^DOCKER_COMPOSE_VERSION=.*/DOCKER_COMPOSE_VERSION=standalone/' $SCRIPT_DIR/mailcow.conf
226 sleep 2
227 fi
228
229
230elif [ "${DOCKER_COMPOSE_VERSION}" == "standalone" ]; then
231 COMPOSE_COMMAND="docker-compose"
232 # Check if Standalone Compose works and has not been deleted
233 if ! $COMPOSE_COMMAND > /dev/null 2>&1 && ! $COMPOSE_COMMAND --version > /dev/null 2>&1 | grep "^2." > /dev/null 2>&1; then
234 # IF it not exists/work anymore try the other command
235 COMPOSE_COMMAND="docker compose"
236 if ! $COMPOSE_COMMAND > /dev/null 2>&1; then
237 # IF it cannot find Native in > 2.X, then script stops
238 echo -e "\e[31mCannot find Docker Compose.\e[0m"
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100239 echo -e "\e[31mPlease install it regarding to this doc site: https://docs.mailcow.email/install/\e[0m"
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100240 exit 1
241 fi
242 # If it finds the native Plugin it will use this instead and change the mailcow.conf Variable accordingly
243 echo -e "\e[31mFound different Docker Compose Version then declared in mailcow.conf!\e[0m"
244 echo -e "\e[31mSetting the DOCKER_COMPOSE_VERSION Variable from standalone to native\e[0m"
245 sed -i 's/^DOCKER_COMPOSE_VERSION=.*/DOCKER_COMPOSE_VERSION=native/' $SCRIPT_DIR/mailcow.conf
246 sleep 2
247 fi
248fi
249}
250
251detect_bad_asn() {
252 echo -e "\e[33mDetecting if your IP is listed on Spamhaus Bad ASN List...\e[0m"
253 response=$(curl --connect-timeout 15 --max-time 30 -s -o /dev/null -w "%{http_code}" "https://asn-check.mailcow.email")
254 if [ "$response" -eq 503 ]; then
255 if [ -z "$SPAMHAUS_DQS_KEY" ]; then
256 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"
257 echo -e "\e[33mmailcow did not detected a value for the variable SPAMHAUS_DQS_KEY inside mailcow.conf!\e[0m"
258 sleep 2
259 echo ""
260 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"
261 echo -e "\e[33mOnce done, enter your DQS API key in mailcow.conf and mailcow will do the rest for you!\e[0m"
262 echo ""
263 sleep 2
264
265 else
266 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"
267 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"
268 fi
269 elif [ "$response" -eq 200 ]; then
270 echo -e "\e[33mCheck completed! Your IP is \e[32mclean\e[0m"
271 elif [ "$response" -eq 429 ]; then
272 echo -e "\e[33mCheck completed! \e[31mYour IP seems to be rate limited on the ASN Check service... please try again later!\e[0m"
273 else
274 echo -e "\e[31mCheck failed! \e[0mMaybe a DNS or Network problem?\e[0m"
275 fi
276}
277
278############## End Function Section ##############
279
280# Check permissions
281if [ "$(id -u)" -ne "0" ]; then
282 echo "You need to be root"
283 exit 1
284fi
285
286SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
287
288# Run pre-update-hook
289if [ -f "${SCRIPT_DIR}/pre_update_hook.sh" ]; then
290 bash "${SCRIPT_DIR}/pre_update_hook.sh"
291fi
292
293if [[ "$(uname -r)" =~ ^4\.15\.0-60 ]]; then
294 echo "DO NOT RUN mailcow ON THIS UBUNTU KERNEL!";
295 echo "Please update to 5.x or use another distribution."
296 exit 1
297fi
298
299if [[ "$(uname -r)" =~ ^4\.4\. ]]; then
300 if grep -q Ubuntu <<< $(uname -a); then
301 echo "DO NOT RUN mailcow ON THIS UBUNTU KERNEL!"
302 echo "Please update to linux-generic-hwe-16.04 by running \"apt-get install --install-recommends linux-generic-hwe-16.04\""
303 exit 1
304 fi
305 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."
306 read -p "Press any key to continue..." < /dev/tty
307fi
308
309# Exit on error and pipefail
310set -o pipefail
311
312# Setting high dc timeout
313export COMPOSE_HTTP_TIMEOUT=600
314
315# Add /opt/bin to PATH
316PATH=$PATH:/opt/bin
317
318umask 0022
319
320# Unset COMPOSE_COMMAND and DOCKER_COMPOSE_VERSION Variable to be on the newest state.
321unset COMPOSE_COMMAND
322unset DOCKER_COMPOSE_VERSION
323
324for bin in curl docker git awk sha1sum grep cut; do
325 if [[ -z $(command -v ${bin}) ]]; then
326 echo "Cannot find ${bin}, exiting..."
327 exit 1;
328 fi
329done
330
331export LC_ALL=C
332DATE=$(date +%Y-%m-%d_%H_%M_%S)
333BRANCH=$(cd ${SCRIPT_DIR}; git rev-parse --abbrev-ref HEAD)
334
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100335while (($#)); do
336 case "${1}" in
337 --check|-c)
338 echo "Checking remote code for updates..."
339 LATEST_REV=$(git ls-remote --exit-code --refs --quiet https://github.com/mailcow/mailcow-dockerized ${BRANCH} | cut -f1)
340 if [ $? -ne 0 ]; then
341 echo "A problem occurred while trying to fetch the latest revision from github."
342 exit 99
343 fi
344 if [[ -z $(git log HEAD --pretty=format:"%H" | grep "${LATEST_REV}") ]]; then
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200345 echo -e "Updated code is available.\nThe changes can be found here: https://github.com/mailcow/mailcow-dockerized/commits/master"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100346 git log --date=short --pretty=format:"%ad - %s" $(git rev-parse --short HEAD)..origin/master
347 exit 0
348 else
349 echo "No updates available."
350 exit 3
351 fi
352 ;;
353 --ours)
354 MERGE_STRATEGY=ours
355 ;;
356 --skip-start)
357 SKIP_START=y
358 ;;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100359 --skip-ping-check)
360 SKIP_PING_CHECK=y
361 ;;
362 --stable)
363 CURRENT_BRANCH="$(cd ${SCRIPT_DIR}; git rev-parse --abbrev-ref HEAD)"
364 NEW_BRANCH="master"
365 ;;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100366 --gc)
367 echo -e "\e[32mCollecting garbage...\e[0m"
368 docker_garbage
369 exit 0
370 ;;
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100371 --nightly)
372 CURRENT_BRANCH="$(cd ${SCRIPT_DIR}; git rev-parse --abbrev-ref HEAD)"
373 NEW_BRANCH="nightly"
374 ;;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100375 --prefetch)
376 echo -e "\e[32mPrefetching images...\e[0m"
377 prefetch_images
378 exit 0
379 ;;
380 -f|--force)
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +0100381 echo -e "\e[32mRunning in forced mode...\e[0m"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100382 FORCE=y
383 ;;
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100384 -d|--dev)
385 echo -e "\e[32mRunning in Developer mode...\e[0m"
386 DEV=y
Matthias Andreas Benkardb7a13512023-11-18 16:44:25 +0100387 ;;
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100388 --help|-h)
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100389 echo './update.sh [-c|--check, --ours, --gc, --nightly, --prefetch, --skip-start, --skip-ping-check, --stable, -f|--force, -d|--dev, -h|--help]
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100390
391 -c|--check - Check for updates and exit (exit codes => 0: update available, 3: no updates)
392 --ours - Use merge strategy option "ours" to solve conflicts in favor of non-mailcow code (local changes over remote changes), not recommended!
393 --gc - Run garbage collector to delete old image tags
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100394 --nightly - Switch your mailcow updates to the unstable (nightly) branch. FOR TESTING PURPOSES ONLY!!!!
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100395 --prefetch - Only prefetch new images and exit (useful to prepare updates)
396 --skip-start - Do not start mailcow after update
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100397 --skip-ping-check - Skip ICMP Check to public DNS resolvers (Use it only if you´ve blocked any ICMP Connections to your mailcow machine)
398 --stable - Switch your mailcow updates to the stable (master) branch. Default unless you changed it with --nightly.
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100399 -f|--force - Force update, do not ask questions
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100400 -d|--dev - Enables Developer Mode (No Checkout of update.sh for tests)
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100401'
402 exit 1
403 esac
404 shift
405done
406
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100407chmod 600 mailcow.conf
408source mailcow.conf
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100409
410detect_docker_compose_command
411
412[[ ! -f mailcow.conf ]] && { echo "mailcow.conf is missing! Is mailcow installed?"; exit 1;}
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100413DOTS=${MAILCOW_HOSTNAME//[^.]};
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100414if [ ${#DOTS} -lt 1 ]; then
415 echo -e "\e[31mMAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) is not a FQDN!\e[0m"
416 sleep 1
417 echo "Please change it to a FQDN and redeploy the stack with $COMPOSE_COMMAND up -d"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100418 exit 1
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100419elif [[ "${MAILCOW_HOSTNAME: -1}" == "." ]]; then
420 echo "MAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) is ending with a dot. This is not a valid FQDN!"
421 exit 1
422elif [ ${#DOTS} -eq 1 ]; then
423 echo -e "\e[33mMAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) does not contain a Subdomain. This is not fully tested and may cause issues.\e[0m"
424 echo "Find more information about why this message exists here: https://github.com/mailcow/mailcow-dockerized/issues/1572"
425 read -r -p "Do you want to proceed anyway? [y/N] " response
426 if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
427 echo "OK. Procceding."
428 else
429 echo "OK. Exiting."
430 exit 1
431 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100432fi
433
434if 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
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200435# This will also cover sort
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100436if 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
437if 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
438
439CONFIG_ARRAY=(
440 "SKIP_LETS_ENCRYPT"
441 "SKIP_SOGO"
442 "USE_WATCHDOG"
443 "WATCHDOG_NOTIFY_EMAIL"
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100444 "WATCHDOG_NOTIFY_WEBHOOK"
445 "WATCHDOG_NOTIFY_WEBHOOK_BODY"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100446 "WATCHDOG_NOTIFY_BAN"
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100447 "WATCHDOG_NOTIFY_START"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100448 "WATCHDOG_EXTERNAL_CHECKS"
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200449 "WATCHDOG_SUBJECT"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100450 "SKIP_CLAMD"
451 "SKIP_IP_CHECK"
452 "ADDITIONAL_SAN"
453 "DOVEADM_PORT"
454 "IPV4_NETWORK"
455 "IPV6_NETWORK"
456 "LOG_LINES"
457 "SNAT_TO_SOURCE"
458 "SNAT6_TO_SOURCE"
459 "COMPOSE_PROJECT_NAME"
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100460 "DOCKER_COMPOSE_VERSION"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100461 "SQL_PORT"
462 "API_KEY"
463 "API_KEY_READ_ONLY"
464 "API_ALLOW_FROM"
465 "MAILDIR_GC_TIME"
466 "MAILDIR_SUB"
467 "ACL_ANYONE"
468 "SOLR_HEAP"
469 "SKIP_SOLR"
470 "ENABLE_SSL_SNI"
471 "ALLOW_ADMIN_EMAIL_LOGIN"
472 "SKIP_HTTP_VERIFICATION"
473 "SOGO_EXPIRE_SESSION"
474 "REDIS_PORT"
475 "DOVECOT_MASTER_USER"
476 "DOVECOT_MASTER_PASS"
477 "MAILCOW_PASS_SCHEME"
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200478 "ADDITIONAL_SERVER_NAMES"
479 "ACME_CONTACT"
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +0100480 "WATCHDOG_VERBOSE"
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100481 "WEBAUTHN_ONLY_TRUSTED_VENDORS"
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100482 "SPAMHAUS_DQS_KEY"
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100483 "SKIP_UNBOUND_HEALTHCHECK"
484 "DISABLE_NETFILTER_ISOLATION_RULE"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100485)
486
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100487detect_bad_asn
488
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100489sed -i --follow-symlinks '$a\' mailcow.conf
490for option in ${CONFIG_ARRAY[@]}; do
491 if [[ ${option} == "ADDITIONAL_SAN" ]]; then
492 if ! grep -q ${option} mailcow.conf; then
493 echo "Adding new option \"${option}\" to mailcow.conf"
494 echo "${option}=" >> mailcow.conf
495 fi
496 elif [[ ${option} == "COMPOSE_PROJECT_NAME" ]]; then
497 if ! grep -q ${option} mailcow.conf; then
498 echo "Adding new option \"${option}\" to mailcow.conf"
499 echo "COMPOSE_PROJECT_NAME=mailcowdockerized" >> mailcow.conf
500 fi
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100501 elif [[ ${option} == "DOCKER_COMPOSE_VERSION" ]]; then
502 if ! grep -q ${option} mailcow.conf; then
503 echo "Adding new option \"${option}\" to mailcow.conf"
504 echo "# Used Docker Compose version" >> mailcow.conf
505 echo "# Switch here between native (compose plugin) and standalone" >> mailcow.conf
506 echo "# For more informations take a look at the mailcow docs regarding the configuration options." >> mailcow.conf
507 echo "# Normally this should be untouched but if you decided to use either of those you can switch it manually here." >> mailcow.conf
508 echo "# Please be aware that at least one of those variants should be installed on your maschine or mailcow will fail." >> mailcow.conf
509 echo "" >> mailcow.conf
510 echo "DOCKER_COMPOSE_VERSION=${DOCKER_COMPOSE_VERSION}" >> mailcow.conf
511 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100512 elif [[ ${option} == "DOVEADM_PORT" ]]; then
513 if ! grep -q ${option} mailcow.conf; then
514 echo "Adding new option \"${option}\" to mailcow.conf"
515 echo "DOVEADM_PORT=127.0.0.1:19991" >> mailcow.conf
516 fi
517 elif [[ ${option} == "WATCHDOG_NOTIFY_EMAIL" ]]; then
518 if ! grep -q ${option} mailcow.conf; then
519 echo "Adding new option \"${option}\" to mailcow.conf"
520 echo "WATCHDOG_NOTIFY_EMAIL=" >> mailcow.conf
521 fi
522 elif [[ ${option} == "LOG_LINES" ]]; then
523 if ! grep -q ${option} mailcow.conf; then
524 echo "Adding new option \"${option}\" to mailcow.conf"
525 echo '# Max log lines per service to keep in Redis logs' >> mailcow.conf
526 echo "LOG_LINES=9999" >> mailcow.conf
527 fi
528 elif [[ ${option} == "IPV4_NETWORK" ]]; then
529 if ! grep -q ${option} mailcow.conf; then
530 echo "Adding new option \"${option}\" to mailcow.conf"
531 echo '# Internal IPv4 /24 subnet, format n.n.n. (expands to n.n.n.0/24)' >> mailcow.conf
532 echo "IPV4_NETWORK=172.22.1" >> mailcow.conf
533 fi
534 elif [[ ${option} == "IPV6_NETWORK" ]]; then
535 if ! grep -q ${option} mailcow.conf; then
536 echo "Adding new option \"${option}\" to mailcow.conf"
537 echo '# Internal IPv6 subnet in fc00::/7' >> mailcow.conf
538 echo "IPV6_NETWORK=fd4d:6169:6c63:6f77::/64" >> mailcow.conf
539 fi
540 elif [[ ${option} == "SQL_PORT" ]]; then
541 if ! grep -q ${option} mailcow.conf; then
542 echo "Adding new option \"${option}\" to mailcow.conf"
543 echo '# Bind SQL to 127.0.0.1 on port 13306' >> mailcow.conf
544 echo "SQL_PORT=127.0.0.1:13306" >> mailcow.conf
545 fi
546 elif [[ ${option} == "API_KEY" ]]; then
547 if ! grep -q ${option} mailcow.conf; then
548 echo "Adding new option \"${option}\" to mailcow.conf"
549 echo '# Create or override API key for web UI' >> mailcow.conf
550 echo "#API_KEY=" >> mailcow.conf
551 fi
552 elif [[ ${option} == "API_KEY_READ_ONLY" ]]; then
553 if ! grep -q ${option} mailcow.conf; then
554 echo "Adding new option \"${option}\" to mailcow.conf"
555 echo '# Create or override read-only API key for web UI' >> mailcow.conf
556 echo "#API_KEY_READ_ONLY=" >> mailcow.conf
557 fi
558 elif [[ ${option} == "API_ALLOW_FROM" ]]; then
559 if ! grep -q ${option} mailcow.conf; then
560 echo "Adding new option \"${option}\" to mailcow.conf"
561 echo '# Must be set for API_KEY to be active' >> mailcow.conf
562 echo '# IPs only, no networks (networks can be set via UI)' >> mailcow.conf
563 echo "#API_ALLOW_FROM=" >> mailcow.conf
564 fi
565 elif [[ ${option} == "SNAT_TO_SOURCE" ]]; then
566 if ! grep -q ${option} mailcow.conf; then
567 echo "Adding new option \"${option}\" to mailcow.conf"
568 echo '# Use this IPv4 for outgoing connections (SNAT)' >> mailcow.conf
569 echo "#SNAT_TO_SOURCE=" >> mailcow.conf
570 fi
571 elif [[ ${option} == "SNAT6_TO_SOURCE" ]]; then
572 if ! grep -q ${option} mailcow.conf; then
573 echo "Adding new option \"${option}\" to mailcow.conf"
574 echo '# Use this IPv6 for outgoing connections (SNAT)' >> mailcow.conf
575 echo "#SNAT6_TO_SOURCE=" >> mailcow.conf
576 fi
577 elif [[ ${option} == "MAILDIR_GC_TIME" ]]; then
578 if ! grep -q ${option} mailcow.conf; then
579 echo "Adding new option \"${option}\" to mailcow.conf"
580 echo '# Garbage collector cleanup' >> mailcow.conf
581 echo '# Deleted domains and mailboxes are moved to /var/vmail/_garbage/timestamp_sanitizedstring' >> mailcow.conf
582 echo '# How long should objects remain in the garbage until they are being deleted? (value in minutes)' >> mailcow.conf
583 echo '# Check interval is hourly' >> mailcow.conf
584 echo 'MAILDIR_GC_TIME=1440' >> mailcow.conf
585 fi
586 elif [[ ${option} == "ACL_ANYONE" ]]; then
587 if ! grep -q ${option} mailcow.conf; then
588 echo "Adding new option \"${option}\" to mailcow.conf"
589 echo '# Set this to "allow" to enable the anyone pseudo user. Disabled by default.' >> mailcow.conf
590 echo '# When enabled, ACL can be created, that apply to "All authenticated users"' >> mailcow.conf
591 echo '# This should probably only be activated on mail hosts, that are used exclusivly by one organisation.' >> mailcow.conf
592 echo '# Otherwise a user might share data with too many other users.' >> mailcow.conf
593 echo 'ACL_ANYONE=disallow' >> mailcow.conf
594 fi
595 elif [[ ${option} == "SOLR_HEAP" ]]; then
596 if ! grep -q ${option} mailcow.conf; then
597 echo "Adding new option \"${option}\" to mailcow.conf"
598 echo '# Solr heap size, there is no recommendation, please see Solr docs.' >> mailcow.conf
599 echo '# Solr is a prone to run OOM on large systems and should be monitored. Unmonitored Solr setups are not recommended.' >> mailcow.conf
600 echo '# Solr will refuse to start with total system memory below or equal to 2 GB.' >> mailcow.conf
601 echo "SOLR_HEAP=1024" >> mailcow.conf
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200602 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100603 elif [[ ${option} == "SKIP_SOLR" ]]; then
604 if ! grep -q ${option} mailcow.conf; then
605 echo "Adding new option \"${option}\" to mailcow.conf"
606 echo '# Solr is disabled by default after upgrading from non-Solr to Solr-enabled mailcows.' >> mailcow.conf
607 echo '# Disable Solr or if you do not want to store a readable index of your mails in solr-vol-1.' >> mailcow.conf
608 echo "SKIP_SOLR=y" >> mailcow.conf
609 fi
610 elif [[ ${option} == "ENABLE_SSL_SNI" ]]; then
611 if ! grep -q ${option} mailcow.conf; then
612 echo "Adding new option \"${option}\" to mailcow.conf"
613 echo '# Create seperate certificates for all domains - y/n' >> mailcow.conf
614 echo '# this will allow adding more than 100 domains, but some email clients will not be able to connect with alternative hostnames' >> mailcow.conf
615 echo '# see https://wiki.dovecot.org/SSL/SNIClientSupport' >> mailcow.conf
616 echo "ENABLE_SSL_SNI=n" >> mailcow.conf
617 fi
618 elif [[ ${option} == "SKIP_SOGO" ]]; then
619 if ! grep -q ${option} mailcow.conf; then
620 echo "Adding new option \"${option}\" to mailcow.conf"
621 echo '# Skip SOGo: Will disable SOGo integration and therefore webmail, DAV protocols and ActiveSync support (experimental, unsupported, not fully implemented) - y/n' >> mailcow.conf
622 echo "SKIP_SOGO=n" >> mailcow.conf
623 fi
624 elif [[ ${option} == "MAILDIR_SUB" ]]; then
625 if ! grep -q ${option} mailcow.conf; then
626 echo "Adding new option \"${option}\" to mailcow.conf"
627 echo '# MAILDIR_SUB defines a path in a users virtual home to keep the maildir in. Leave empty for updated setups.' >> mailcow.conf
628 echo "#MAILDIR_SUB=Maildir" >> mailcow.conf
629 echo "MAILDIR_SUB=" >> mailcow.conf
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200630 fi
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100631 elif [[ ${option} == "WATCHDOG_NOTIFY_WEBHOOK" ]]; then
632 if ! grep -q ${option} mailcow.conf; then
633 echo "Adding new option \"${option}\" to mailcow.conf"
634 echo '# Send notifications to a webhook URL that receives a POST request with the content type "application/json".' >> mailcow.conf
635 echo '# You can use this to send notifications to services like Discord, Slack and others.' >> mailcow.conf
636 echo '#WATCHDOG_NOTIFY_WEBHOOK=https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' >> mailcow.conf
637 fi
638 elif [[ ${option} == "WATCHDOG_NOTIFY_WEBHOOK_BODY" ]]; then
639 if ! grep -q ${option} mailcow.conf; then
640 echo "Adding new option \"${option}\" to mailcow.conf"
641 echo '# JSON body included in the webhook POST request. Needs to be in single quotes.' >> mailcow.conf
642 echo '# Following variables are available: SUBJECT, BODY' >> mailcow.conf
643 WEBHOOK_BODY='{"username": "mailcow Watchdog", "content": "**${SUBJECT}**\n${BODY}"}'
644 echo "#WATCHDOG_NOTIFY_WEBHOOK_BODY='${WEBHOOK_BODY}'" >> mailcow.conf
645 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100646 elif [[ ${option} == "WATCHDOG_NOTIFY_BAN" ]]; then
647 if ! grep -q ${option} mailcow.conf; then
648 echo "Adding new option \"${option}\" to mailcow.conf"
649 echo '# Notify about banned IP. Includes whois lookup.' >> mailcow.conf
650 echo "WATCHDOG_NOTIFY_BAN=y" >> mailcow.conf
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200651 fi
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100652 elif [[ ${option} == "WATCHDOG_NOTIFY_START" ]]; then
653 if ! grep -q ${option} mailcow.conf; then
654 echo "Adding new option \"${option}\" to mailcow.conf"
655 echo '# Send a notification when the watchdog is started.' >> mailcow.conf
656 echo "WATCHDOG_NOTIFY_START=y" >> mailcow.conf
657 fi
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200658 elif [[ ${option} == "WATCHDOG_SUBJECT" ]]; then
659 if ! grep -q ${option} mailcow.conf; then
660 echo "Adding new option \"${option}\" to mailcow.conf"
661 echo '# Subject for watchdog mails. Defaults to "Watchdog ALERT" followed by the error message.' >> mailcow.conf
662 echo "#WATCHDOG_SUBJECT=" >> mailcow.conf
663 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100664 elif [[ ${option} == "WATCHDOG_EXTERNAL_CHECKS" ]]; then
665 if ! grep -q ${option} mailcow.conf; then
666 echo "Adding new option \"${option}\" to mailcow.conf"
667 echo '# Checks if mailcow is an open relay. Requires a SAL. More checks will follow.' >> mailcow.conf
668 echo '# No data is collected. Opt-in and anonymous.' >> mailcow.conf
669 echo '# Will only work with unmodified mailcow setups.' >> mailcow.conf
670 echo "WATCHDOG_EXTERNAL_CHECKS=n" >> mailcow.conf
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200671 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100672 elif [[ ${option} == "SOGO_EXPIRE_SESSION" ]]; then
673 if ! grep -q ${option} mailcow.conf; then
674 echo "Adding new option \"${option}\" to mailcow.conf"
675 echo '# SOGo session timeout in minutes' >> mailcow.conf
676 echo "SOGO_EXPIRE_SESSION=480" >> mailcow.conf
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200677 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100678 elif [[ ${option} == "REDIS_PORT" ]]; then
679 if ! grep -q ${option} mailcow.conf; then
680 echo "Adding new option \"${option}\" to mailcow.conf"
681 echo "REDIS_PORT=127.0.0.1:7654" >> mailcow.conf
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200682 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100683 elif [[ ${option} == "DOVECOT_MASTER_USER" ]]; then
684 if ! grep -q ${option} mailcow.conf; then
685 echo "Adding new option \"${option}\" to mailcow.conf"
686 echo '# DOVECOT_MASTER_USER and _PASS must _both_ be provided. No special chars.' >> mailcow.conf
687 echo '# Empty by default to auto-generate master user and password on start.' >> mailcow.conf
688 echo '# User expands to DOVECOT_MASTER_USER@mailcow.local' >> mailcow.conf
689 echo '# LEAVE EMPTY IF UNSURE' >> mailcow.conf
690 echo "DOVECOT_MASTER_USER=" >> mailcow.conf
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200691 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100692 elif [[ ${option} == "DOVECOT_MASTER_PASS" ]]; then
693 if ! grep -q ${option} mailcow.conf; then
694 echo "Adding new option \"${option}\" to mailcow.conf"
695 echo '# LEAVE EMPTY IF UNSURE' >> mailcow.conf
696 echo "DOVECOT_MASTER_PASS=" >> mailcow.conf
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200697 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100698 elif [[ ${option} == "MAILCOW_PASS_SCHEME" ]]; then
699 if ! grep -q ${option} mailcow.conf; then
700 echo "Adding new option \"${option}\" to mailcow.conf"
701 echo '# Password hash algorithm' >> mailcow.conf
702 echo '# Only certain password hash algorithm are supported. For a fully list of supported schemes,' >> mailcow.conf
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100703 echo '# see https://docs.mailcow.email/models/model-passwd/' >> mailcow.conf
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100704 echo "MAILCOW_PASS_SCHEME=BLF-CRYPT" >> mailcow.conf
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200705 fi
706 elif [[ ${option} == "ADDITIONAL_SERVER_NAMES" ]]; then
707 if ! grep -q ${option} mailcow.conf; then
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100708 echo "Adding new option \"${option}\" to mailcow.conf"
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200709 echo '# Additional server names for mailcow UI' >> mailcow.conf
710 echo '#' >> mailcow.conf
711 echo '# Specify alternative addresses for the mailcow UI to respond to' >> mailcow.conf
712 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
713 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
714 echo '# You can understand this as server_name directive in Nginx.' >> mailcow.conf
715 echo '# Comma separated list without spaces! Example: ADDITIONAL_SERVER_NAMES=a.b.c,d.e.f' >> mailcow.conf
716 echo 'ADDITIONAL_SERVER_NAMES=' >> mailcow.conf
717 fi
718 elif [[ ${option} == "ACME_CONTACT" ]]; then
719 if ! grep -q ${option} mailcow.conf; then
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100720 echo "Adding new option \"${option}\" to mailcow.conf"
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200721 echo '# Lets Encrypt registration contact information' >> mailcow.conf
722 echo '# Optional: Leave empty for none' >> mailcow.conf
723 echo '# This value is only used on first order!' >> mailcow.conf
724 echo '# Setting it at a later point will require the following steps:' >> mailcow.conf
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100725 echo '# https://docs.mailcow.email/troubleshooting/debug-reset_tls/' >> mailcow.conf
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200726 echo 'ACME_CONTACT=' >> mailcow.conf
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100727 fi
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100728 elif [[ ${option} == "WEBAUTHN_ONLY_TRUSTED_VENDORS" ]]; then
729 if ! grep -q ${option} mailcow.conf; then
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100730 echo "Adding new option \"${option}\" to mailcow.conf"
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100731 echo "# WebAuthn device manufacturer verification" >> mailcow.conf
732 echo '# After setting WEBAUTHN_ONLY_TRUSTED_VENDORS=y only devices from trusted manufacturers are allowed' >> mailcow.conf
733 echo '# root certificates can be placed for validation under mailcow-dockerized/data/web/inc/lib/WebAuthn/rootCertificates' >> mailcow.conf
734 echo 'WEBAUTHN_ONLY_TRUSTED_VENDORS=n' >> mailcow.conf
735 fi
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100736 elif [[ ${option} == "SPAMHAUS_DQS_KEY" ]]; then
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +0100737 if ! grep -q ${option} mailcow.conf; then
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100738 echo "Adding new option \"${option}\" to mailcow.conf"
739 echo "# Spamhaus Data Query Service Key" >> mailcow.conf
740 echo '# Optional: Leave empty for none' >> mailcow.conf
741 echo '# Enter your key here if you are using a blocked ASN (OVH, AWS, Cloudflare e.g) for the unregistered Spamhaus Blocklist.' >> mailcow.conf
742 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
743 echo '# Otherwise it will work as usual.' >> mailcow.conf
744 echo 'SPAMHAUS_DQS_KEY=' >> mailcow.conf
745 fi
746 elif [[ ${option} == "WATCHDOG_VERBOSE" ]]; then
747 if ! grep -q ${option} mailcow.conf; then
748 echo "Adding new option \"${option}\" to mailcow.conf"
Matthias Andreas Benkardb4b5cc12021-12-28 18:02:04 +0100749 echo '# Enable watchdog verbose logging' >> mailcow.conf
750 echo 'WATCHDOG_VERBOSE=n' >> mailcow.conf
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100751 fi
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100752 elif [[ ${option} == "SKIP_UNBOUND_HEALTHCHECK" ]]; then
753 if ! grep -q ${option} mailcow.conf; then
754 echo "Adding new option \"${option}\" to mailcow.conf"
755 echo '# Skip Unbound (DNS Resolver) Healthchecks (NOT Recommended!) - y/n' >> mailcow.conf
756 echo 'SKIP_UNBOUND_HEALTHCHECK=n' >> mailcow.conf
757 fi
758 elif [[ ${option} == "DISABLE_NETFILTER_ISOLATION_RULE" ]]; then
759 if ! grep -q ${option} mailcow.conf; then
760 echo "Adding new option \"${option}\" to mailcow.conf"
761 echo '# Prevent netfilter from setting an iptables/nftables rule to isolate the mailcow docker network - y/n' >> mailcow.conf
762 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
763 echo 'DISABLE_NETFILTER_ISOLATION_RULE=n' >> mailcow.conf
764 fi
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100765 elif ! grep -q ${option} mailcow.conf; then
766 echo "Adding new option \"${option}\" to mailcow.conf"
767 echo "${option}=n" >> mailcow.conf
768 fi
769done
770
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100771if [[( ${SKIP_PING_CHECK} == "y")]]; then
772echo -e "\e[32mSkipping Ping Check...\e[0m"
773
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100774else
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100775 echo -en "Checking internet connection... "
776 if ! check_online_status; then
777 echo -e "\e[31mfailed\e[0m"
778 exit 1
779 else
780 echo -e "\e[32mOK\e[0m"
781 fi
782fi
783
784if ! [ $NEW_BRANCH ]; then
785 echo -e "\e[33mDetecting which build your mailcow runs on...\e[0m"
786 sleep 1
787 if [ ${BRANCH} == "master" ]; then
788 echo -e "\e[32mYou are receiving stable updates (master).\e[0m"
789 echo -e "\e[33mTo change that run the update.sh Script one time with the --nightly parameter to switch to nightly builds.\e[0m"
790
791 elif [ ${BRANCH} == "nightly" ]; then
792 echo -e "\e[31mYou are receiving unstable updates (nightly). These are for testing purposes only!!!\e[0m"
793 sleep 1
794 echo -e "\e[33mTo change that run the update.sh Script one time with the --stable parameter to switch to stable builds.\e[0m"
795
796 else
797 echo -e "\e[33mYou are receiving updates from a unsupported branch.\e[0m"
798 sleep 1
799 echo -e "\e[33mThe mailcow stack might still work but it is recommended to switch to the master branch (stable builds).\e[0m"
800 echo -e "\e[33mTo change that run the update.sh Script one time with the --stable parameter to switch to stable builds.\e[0m"
801 fi
802elif [ $FORCE ]; then
803 echo -e "\e[31mYou are running in forced mode!\e[0m"
804 echo -e "\e[31mA Branch Switch can only be performed manually (monitored).\e[0m"
805 echo -e "\e[31mPlease rerun the update.sh Script without the --force/-f parameter.\e[0m"
806 sleep 1
807elif [ $NEW_BRANCH == "master" ] && [ $CURRENT_BRANCH != "master" ]; then
808 echo -e "\e[33mYou are about to switch your mailcow Updates to the stable (master) branch.\e[0m"
809 sleep 1
810 echo -e "\e[33mBefore you do: Please take a backup of all components to ensure that no Data is lost...\e[0m"
811 sleep 1
812 echo -e "\e[31mWARNING: Please see on GitHub or ask in the communitys if a switch to master is stable or not.
813 In some rear cases a Update back to master can destroy your mailcow configuration in case of Database Upgrades etc.
814 Normally a upgrade back to master should be safe during each full release.
815 Check GitHub for Database Changes and Update only if there similar to the full release!\e[0m"
816 read -r -p "Are you sure you that want to continue upgrading to the stable (master) branch? [y/N] " response
817 if [[ ! "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
818 echo "OK. If you prepared yourself for that please run the update.sh Script with the --stable parameter again to trigger this process here."
819 exit 0
820 fi
821 BRANCH=$NEW_BRANCH
822 DIFF_DIRECTORY=update_diffs
823 DIFF_FILE=${DIFF_DIRECTORY}/diff_before_upgrade_to_master_$(date +"%Y-%m-%d-%H-%M-%S")
824 mv diff_before_upgrade* ${DIFF_DIRECTORY}/ 2> /dev/null
825 if ! git diff-index --quiet HEAD; then
826 echo -e "\e[32mSaving diff to ${DIFF_FILE}...\e[0m"
827 mkdir -p ${DIFF_DIRECTORY}
828 git diff ${BRANCH} --stat > ${DIFF_FILE}
829 git diff ${BRANCH} >> ${DIFF_FILE}
830 fi
831 echo -e "\e[32mSwitching Branch to ${BRANCH}...\e[0m"
832 git fetch origin
833 git checkout -f ${BRANCH}
834
835elif [ $NEW_BRANCH == "nightly" ] && [ $CURRENT_BRANCH != "nightly" ]; then
836 echo -e "\e[33mYou are about to switch your mailcow Updates to the unstable (nightly) branch.\e[0m"
837 sleep 1
838 echo -e "\e[33mBefore you do: Please take a backup of all components to ensure that no Data is lost...\e[0m"
839 sleep 1
840 echo -e "\e[31mWARNING: A switch to nightly is possible any time. But a switch back (to master) isn't.\e[0m"
841 read -r -p "Are you sure you that want to continue upgrading to the unstable (nightly) branch? [y/N] " response
842 if [[ ! "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
843 echo "OK. If you prepared yourself for that please run the update.sh Script with the --nightly parameter again to trigger this process here."
844 exit 0
845 fi
846 BRANCH=$NEW_BRANCH
847 DIFF_DIRECTORY=update_diffs
848 DIFF_FILE=${DIFF_DIRECTORY}/diff_before_upgrade_to_nightly_$(date +"%Y-%m-%d-%H-%M-%S")
849 mv diff_before_upgrade* ${DIFF_DIRECTORY}/ 2> /dev/null
850 if ! git diff-index --quiet HEAD; then
851 echo -e "\e[32mSaving diff to ${DIFF_FILE}...\e[0m"
852 mkdir -p ${DIFF_DIRECTORY}
853 git diff ${BRANCH} --stat > ${DIFF_FILE}
854 git diff ${BRANCH} >> ${DIFF_FILE}
855 fi
856 git fetch origin
857 git checkout -f ${BRANCH}
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100858fi
859
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100860if [ ! $DEV ]; then
861 echo -e "\e[32mChecking for newer update script...\e[0m"
862 SHA1_1=$(sha1sum update.sh)
863 git fetch origin #${BRANCH}
864 git checkout origin/${BRANCH} update.sh
865 SHA1_2=$(sha1sum update.sh)
866 if [[ ${SHA1_1} != ${SHA1_2} ]]; then
867 echo "update.sh changed, please run this script again, exiting."
868 chmod +x update.sh
869 exit 2
870 fi
Matthias Andreas Benkardb7a13512023-11-18 16:44:25 +0100871fi
872
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100873if [ ! $FORCE ]; then
874 read -r -p "Are you sure you want to update mailcow: dockerized? All containers will be stopped. [y/N] " response
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200875 if [[ ! "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100876 echo "OK, exiting."
877 exit 0
878 fi
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200879 migrate_docker_nat
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100880fi
881
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100882remove_obsolete_nginx_ports
883
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100884echo -e "\e[32mValidating docker-compose stack configuration...\e[0m"
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100885sed -i 's/HTTPS_BIND:-:/HTTPS_BIND:-/g' docker-compose.yml
886sed -i 's/HTTP_BIND:-:/HTTP_BIND:-/g' docker-compose.yml
887if ! $COMPOSE_COMMAND config -q; then
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100888 echo -e "\e[31m\nOh no, something went wrong. Please check the error message above.\e[0m"
889 exit 1
890fi
891
892echo -e "\e[32mChecking for conflicting bridges...\e[0m"
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100893MAILCOW_BRIDGE=$($COMPOSE_COMMAND config | grep -i com.docker.network.bridge.name | cut -d':' -f2)
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100894while read NAT_ID; do
895 iptables -t nat -D POSTROUTING $NAT_ID
896done < <(iptables -L -vn -t nat --line-numbers | grep $IPV4_NETWORK | grep -E 'MASQUERADE.*all' | grep -v ${MAILCOW_BRIDGE} | cut -d' ' -f1)
897
898DIFF_DIRECTORY=update_diffs
899DIFF_FILE=${DIFF_DIRECTORY}/diff_before_update_$(date +"%Y-%m-%d-%H-%M-%S")
900mv diff_before_update* ${DIFF_DIRECTORY}/ 2> /dev/null
901if ! git diff-index --quiet HEAD; then
902 echo -e "\e[32mSaving diff to ${DIFF_FILE}...\e[0m"
903 mkdir -p ${DIFF_DIRECTORY}
904 git diff --stat > ${DIFF_FILE}
905 git diff >> ${DIFF_FILE}
906fi
907
908echo -e "\e[32mPrefetching images...\e[0m"
909prefetch_images
910
911echo -e "\e[32mStopping mailcow...\e[0m"
912sleep 2
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100913MAILCOW_CONTAINERS=($($COMPOSE_COMMAND ps -q))
914$COMPOSE_COMMAND down
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100915echo -e "\e[32mChecking for remaining containers...\e[0m"
916sleep 2
917for container in "${MAILCOW_CONTAINERS[@]}"; do
918 docker rm -f "$container" 2> /dev/null
919done
920
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +0200921[[ -f data/conf/nginx/ZZZ-ejabberd.conf ]] && rm data/conf/nginx/ZZZ-ejabberd.conf
922
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100923
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100924# Silently fixing remote url from andryyy to mailcow
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100925# git remote set-url origin https://github.com/mailcow/mailcow-dockerized
926
927DEFAULT_REPO=https://github.com/mailcow/mailcow-dockerized
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100928CURRENT_REPO=$(git config --get remote.origin.url)
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100929if [ "$CURRENT_REPO" != "$DEFAULT_REPO" ]; then
930 echo "The Repository currently used is not the default Mailcow Repository."
931 echo "Currently Repository: $CURRENT_REPO"
932 echo "Default Repository: $DEFAULT_REPO"
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100933 if [ ! $FORCE ]; then
934 read -r -p "Should it be changed back to default? [y/N] " repo_response
935 if [[ "$repo_response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
936 git remote set-url origin $DEFAULT_REPO
937 fi
938 else
939 echo "Running in forced mode... setting Repo to default!"
940 git remote set-url origin $DEFAULT_REPO
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100941 fi
942fi
943
Matthias Andreas Benkard9dabdab2024-03-06 13:12:09 +0100944if [ ! $DEV ]; then
945 echo -e "\e[32mCommitting current status...\e[0m"
946 [[ -z "$(git config user.name)" ]] && git config user.name moo
947 [[ -z "$(git config user.email)" ]] && git config user.email moo@cow.moo
948 [[ ! -z $(git ls-files data/conf/rspamd/override.d/worker-controller-password.inc) ]] && git rm data/conf/rspamd/override.d/worker-controller-password.inc
949 git add -u
950 git commit -am "Before update on ${DATE}" > /dev/null
951 echo -e "\e[32mFetching updated code from remote...\e[0m"
952 git fetch origin #${BRANCH}
953 echo -e "\e[32mMerging local with remote code (recursive, strategy: \"${MERGE_STRATEGY:-theirs}\", options: \"patience\"...\e[0m"
954 git config merge.defaultToUpstream true
955 git merge -X${MERGE_STRATEGY:-theirs} -Xpatience -m "After update on ${DATE}"
956 # Need to use a variable to not pass return codes of if checks
957 MERGE_RETURN=$?
958 if [[ ${MERGE_RETURN} == 128 ]]; then
959 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"
960 exit 1
961 elif [[ ${MERGE_RETURN} == 1 ]]; then
962 echo -e "\e[93mPotenial conflict, trying to fix...\e[0m"
963 git status --porcelain | grep -E "UD|DU" | awk '{print $2}' | xargs rm -v
964 git add -A
965 git commit -m "After update on ${DATE}" > /dev/null
966 git checkout .
967 echo -e "\e[32mRemoved and recreated files if necessary.\e[0m"
968 elif [[ ${MERGE_RETURN} != 0 ]]; then
969 echo -e "\e[31m\nOh no, something went wrong. Please check the error message above.\e[0m"
970 echo
971 echo "Run $COMPOSE_COMMAND up -d to restart your stack without updates or try again after fixing the mentioned errors."
972 exit 1
973 fi
974elif [ $DEV ]; then
975 echo -e "\e[33mDEVELOPER MODE: Not creating a git diff and commiting it to prevent development stuff within a backup diff...\e[0m"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100976fi
977
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100978echo -e "\e[32mFetching new images, if any...\e[0m"
979sleep 2
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +0100980$COMPOSE_COMMAND pull
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100981
982# Fix missing SSL, does not overwrite existing files
983[[ ! -d data/assets/ssl ]] && mkdir -p data/assets/ssl
984cp -n -d data/assets/ssl-example/*.pem data/assets/ssl/
985
986echo -e "Checking IPv6 settings... "
987if grep -q 'SYSCTL_IPV6_DISABLED=1' mailcow.conf; then
988 echo
989 echo '!! IMPORTANT !!'
990 echo
991 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".'
Matthias Andreas Benkardd63fe562023-11-18 13:18:30 +0100992 echo "This setting will only be active after a complete shutdown of mailcow by running $COMPOSE_COMMAND down followed by $COMPOSE_COMMAND up -d."
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +0100993 echo
994 echo '!! IMPORTANT !!'
995 echo
996 read -p "Press any key to continue..." < /dev/tty
997fi
998
999# Checking for old project name bug
1000sed -i --follow-symlinks 's#COMPOSEPROJECT_NAME#COMPOSE_PROJECT_NAME#g' mailcow.conf
1001
1002# Fix Rspamd maps
1003if [ -f data/conf/rspamd/custom/global_from_blacklist.map ]; then
1004 mv data/conf/rspamd/custom/global_from_blacklist.map data/conf/rspamd/custom/global_smtp_from_blacklist.map
1005fi
1006if [ -f data/conf/rspamd/custom/global_from_whitelist.map ]; then
1007 mv data/conf/rspamd/custom/global_from_whitelist.map data/conf/rspamd/custom/global_smtp_from_whitelist.map
1008fi
1009
1010# Fix deprecated metrics.conf
1011if [ -f "data/conf/rspamd/local.d/metrics.conf" ]; then
1012 if [ ! -z "$(git diff --name-only origin/master data/conf/rspamd/local.d/metrics.conf)" ]; then
1013 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."
1014 echo "The deprecated configuration file metrics.conf will be moved to metrics.conf_deprecated after updating mailcow."
1015 fi
1016 mv data/conf/rspamd/local.d/metrics.conf data/conf/rspamd/local.d/metrics.conf_deprecated
1017fi
1018
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001019# Set app_info.inc.php
1020if [ ${BRANCH} == "master" ]; then
1021 mailcow_git_version=$(git describe --tags `git rev-list --tags --max-count=1`)
1022elif [ ${BRANCH} == "nightly" ]; then
1023 mailcow_git_version=$(git rev-parse --short $(git rev-parse @{upstream}))
1024 mailcow_last_git_version=""
1025else
1026 mailcow_git_version=$(git rev-parse --short HEAD)
1027 mailcow_last_git_version=""
1028fi
1029
1030mailcow_git_commit=$(git rev-parse origin/${BRANCH})
1031mailcow_git_commit_date=$(git log -1 --format=%ci @{upstream} )
1032
1033if [ $? -eq 0 ]; then
1034 echo '<?php' > data/web/inc/app_info.inc.php
1035 echo ' $MAILCOW_GIT_VERSION="'$mailcow_git_version'";' >> data/web/inc/app_info.inc.php
1036 echo ' $MAILCOW_LAST_GIT_VERSION="";' >> data/web/inc/app_info.inc.php
1037 echo ' $MAILCOW_GIT_OWNER="mailcow";' >> data/web/inc/app_info.inc.php
1038 echo ' $MAILCOW_GIT_REPO="mailcow-dockerized";' >> data/web/inc/app_info.inc.php
1039 echo ' $MAILCOW_GIT_URL="https://github.com/mailcow/mailcow-dockerized";' >> data/web/inc/app_info.inc.php
1040 echo ' $MAILCOW_GIT_COMMIT="'$mailcow_git_commit'";' >> data/web/inc/app_info.inc.php
1041 echo ' $MAILCOW_GIT_COMMIT_DATE="'$mailcow_git_commit_date'";' >> data/web/inc/app_info.inc.php
1042 echo ' $MAILCOW_BRANCH="'$BRANCH'";' >> data/web/inc/app_info.inc.php
1043 echo ' $MAILCOW_UPDATEDAT='$(date +%s)';' >> data/web/inc/app_info.inc.php
1044 echo '?>' >> data/web/inc/app_info.inc.php
1045else
1046 echo '<?php' > data/web/inc/app_info.inc.php
1047 echo ' $MAILCOW_GIT_VERSION="'$mailcow_git_version'";' >> data/web/inc/app_info.inc.php
1048 echo ' $MAILCOW_LAST_GIT_VERSION="";' >> data/web/inc/app_info.inc.php
1049 echo ' $MAILCOW_GIT_OWNER="mailcow";' >> data/web/inc/app_info.inc.php
1050 echo ' $MAILCOW_GIT_REPO="mailcow-dockerized";' >> data/web/inc/app_info.inc.php
1051 echo ' $MAILCOW_GIT_URL="https://github.com/mailcow/mailcow-dockerized";' >> data/web/inc/app_info.inc.php
1052 echo ' $MAILCOW_GIT_COMMIT="";' >> data/web/inc/app_info.inc.php
1053 echo ' $MAILCOW_GIT_COMMIT_DATE="";' >> data/web/inc/app_info.inc.php
1054 echo ' $MAILCOW_BRANCH="'$BRANCH'";' >> data/web/inc/app_info.inc.php
1055 echo ' $MAILCOW_UPDATEDAT='$(date +%s)';' >> data/web/inc/app_info.inc.php
1056 echo '?>' >> data/web/inc/app_info.inc.php
1057 echo -e "\e[33mCannot determine current git repository version...\e[0m"
1058fi
1059
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001060if [[ ${SKIP_START} == "y" ]]; then
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001061 echo -e "\e[33mNot starting mailcow, please run \"$COMPOSE_COMMAND up -d --remove-orphans\" to start mailcow.\e[0m"
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001062else
1063 echo -e "\e[32mStarting mailcow...\e[0m"
1064 sleep 2
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001065 $COMPOSE_COMMAND up -d --remove-orphans
Matthias Andreas Benkard4edeb9f2021-01-02 15:32:21 +01001066fi
1067
1068echo -e "\e[32mCollecting garbage...\e[0m"
1069docker_garbage
1070
Matthias Andreas Benkard8f915942021-08-16 10:57:25 +02001071# Run post-update-hook
1072if [ -f "${SCRIPT_DIR}/post_update_hook.sh" ]; then
1073 bash "${SCRIPT_DIR}/post_update_hook.sh"
1074fi
1075
Matthias Andreas Benkard3c18a082022-12-27 17:32:58 +01001076# echo "In case you encounter any problem, hard-reset to a state before updating mailcow:"
1077# echo
1078# git reflog --color=always | grep "Before update on "
1079# echo
Matthias Andreas Benkardb7a13512023-11-18 16:44:25 +01001080# echo "Use \"git reset --hard hash-on-the-left\" and run $COMPOSE_COMMAND up -d afterwards."