| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 3 | ############## Begin Function Section ############## |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 4 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 5 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 6 | MAILCOW_CONF="${SCRIPT_DIR}/mailcow.conf" |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 7 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 8 | # Ensure the script is run from the directory that contains mailcow.conf |
| 9 | if [ ! -f "${PWD}/mailcow.conf" ]; then |
| 10 | if [ -f "${SCRIPT_DIR}/mailcow.conf" ]; then |
| 11 | echo -e "\e[33mPlease run this script directly from the mailcow installation directory:\e[0m" |
| 12 | echo -e " \e[36mcd ${SCRIPT_DIR} && ./update.sh\e[0m" |
| 13 | exit 1 |
| Matthias Andreas Benkard | 8f91594 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 14 | else |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 15 | echo -e "\e[31mmailcow.conf not found in current directory or script directory (\e[36m${SCRIPT_DIR}\e[31m).\e[0m" |
| 16 | echo -e "\e[33mRun this script directly from your mailcow installation directory.\e[0m" |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 17 | exit 1 |
| 18 | fi |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 19 | fi |
| 20 | BRANCH="$(cd "${SCRIPT_DIR}" && git rev-parse --abbrev-ref HEAD)" |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 21 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 22 | # Check for --dev flag early to skip _modules update |
| 23 | for arg in "$@"; do |
| 24 | if [[ "$arg" == "--dev" || "$arg" == "-d" ]]; then |
| 25 | echo -e "\e[32mRunning in Developer mode...\e[0m" |
| 26 | DEV=y |
| 27 | break |
| 28 | fi |
| 29 | done |
| 30 | |
| 31 | MODULE_DIR="${SCRIPT_DIR}/_modules" |
| 32 | |
| 33 | if [ ! "$DEV" ]; then |
| 34 | # Calculate hash before fetch |
| 35 | if [[ -d "${MODULE_DIR}" && -n "$(ls -A "${MODULE_DIR}" 2>/dev/null)" ]]; then |
| 36 | MODULES_HASH_BEFORE=$(find "${MODULE_DIR}" -type f -exec sha256sum {} \; 2>/dev/null | sort | sha256sum | awk '{print $1}') |
| 37 | else |
| 38 | MODULES_HASH_BEFORE="EMPTY" |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 39 | fi |
| 40 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 41 | echo -e "\e[33mFetching latest _modules from origin/${BRANCH}…\e[0m" |
| 42 | git fetch origin "${BRANCH}" |
| 43 | git checkout "origin/${BRANCH}" -- _modules |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 44 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 45 | if [[ ! -d "${MODULE_DIR}" || -z "$(ls -A "${MODULE_DIR}")" ]]; then |
| 46 | echo -e "\e[31mError: _modules is still missing or empty after fetch!\e[0m" |
| 47 | exit 2 |
| 48 | fi |
| 49 | |
| 50 | # Calculate hash after fetch |
| 51 | MODULES_HASH_AFTER=$(find "${MODULE_DIR}" -type f -exec sha256sum {} \; 2>/dev/null | sort | sha256sum | awk '{print $1}') |
| 52 | |
| 53 | # Check if modules changed |
| 54 | if [[ "${MODULES_HASH_BEFORE}" != "${MODULES_HASH_AFTER}" ]]; then |
| 55 | echo -e "\e[33m_modules have been updated. Please restart the update script.\e[0m" |
| 56 | exit 2 |
| 57 | fi |
| 58 | else |
| 59 | echo -e "\e[33mDeveloper mode: Skipping _modules update from git\e[0m" |
| 60 | if [[ ! -d "${MODULE_DIR}" || -z "$(ls -A "${MODULE_DIR}")" ]]; then |
| 61 | echo -e "\e[31mError: _modules directory is missing or empty!\e[0m" |
| 62 | exit 2 |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 63 | fi |
| 64 | fi |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 65 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 66 | source _modules/scripts/core.sh |
| 67 | source _modules/scripts/ipv6_controller.sh |
| 68 | source _modules/scripts/new_options.sh |
| 69 | source _modules/scripts/migrate_options.sh |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 70 | |
| 71 | ############## End Function Section ############## |
| 72 | |
| 73 | # Check permissions |
| 74 | if [ "$(id -u)" -ne "0" ]; then |
| 75 | echo "You need to be root" |
| 76 | exit 1 |
| 77 | fi |
| 78 | |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 79 | # Run pre-update-hook |
| 80 | if [ -f "${SCRIPT_DIR}/pre_update_hook.sh" ]; then |
| 81 | bash "${SCRIPT_DIR}/pre_update_hook.sh" |
| 82 | fi |
| 83 | |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 84 | # Exit on error and pipefail |
| 85 | set -o pipefail |
| 86 | |
| 87 | # Setting high dc timeout |
| 88 | export COMPOSE_HTTP_TIMEOUT=600 |
| 89 | |
| 90 | # Add /opt/bin to PATH |
| 91 | PATH=$PATH:/opt/bin |
| 92 | |
| 93 | umask 0022 |
| 94 | |
| 95 | # Unset COMPOSE_COMMAND and DOCKER_COMPOSE_VERSION Variable to be on the newest state. |
| 96 | unset COMPOSE_COMMAND |
| 97 | unset DOCKER_COMPOSE_VERSION |
| 98 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 99 | get_installed_tools |
| 100 | |
| 101 | get_docker_version |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 102 | |
| 103 | export LC_ALL=C |
| 104 | DATE=$(date +%Y-%m-%d_%H_%M_%S) |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 105 | BRANCH="$(cd "${SCRIPT_DIR}"; git rev-parse --abbrev-ref HEAD)" |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 106 | |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 107 | while (($#)); do |
| 108 | case "${1}" in |
| 109 | --check|-c) |
| 110 | echo "Checking remote code for updates..." |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 111 | LATEST_REV=$(git ls-remote --exit-code --refs --quiet https://github.com/mailcow/mailcow-dockerized "${BRANCH}" | cut -f1) |
| 112 | if [ "$?" -ne 0 ]; then |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 113 | echo "A problem occurred while trying to fetch the latest revision from github." |
| 114 | exit 99 |
| 115 | fi |
| 116 | if [[ -z $(git log HEAD --pretty=format:"%H" | grep "${LATEST_REV}") ]]; then |
| Matthias Andreas Benkard | 8f91594 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 117 | echo -e "Updated code is available.\nThe changes can be found here: https://github.com/mailcow/mailcow-dockerized/commits/master" |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 118 | git log --date=short --pretty=format:"%ad - %s" "$(git rev-parse --short HEAD)"..origin/master |
| 119 | exit 0 |
| 120 | else |
| 121 | echo "No updates available." |
| 122 | exit 3 |
| 123 | fi |
| 124 | ;; |
| 125 | --check-tags) |
| 126 | echo "Checking remote tags for updates..." |
| 127 | LATEST_TAG_REV=$(git ls-remote --exit-code --quiet --tags origin | tail -1 | cut -f1) |
| 128 | if [ "$?" -ne 0 ]; then |
| 129 | echo "A problem occurred while trying to fetch the latest tag from github." |
| 130 | exit 99 |
| 131 | fi |
| 132 | if [[ -z $(git log HEAD --pretty=format:"%H" | grep "${LATEST_TAG_REV}") ]]; then |
| 133 | echo -e "New tag is available.\nThe changes can be found here: https://github.com/mailcow/mailcow-dockerized/releases/latest" |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 134 | exit 0 |
| 135 | else |
| 136 | echo "No updates available." |
| 137 | exit 3 |
| 138 | fi |
| 139 | ;; |
| 140 | --ours) |
| 141 | MERGE_STRATEGY=ours |
| 142 | ;; |
| 143 | --skip-start) |
| 144 | SKIP_START=y |
| 145 | ;; |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 146 | --skip-ping-check) |
| 147 | SKIP_PING_CHECK=y |
| 148 | ;; |
| 149 | --stable) |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 150 | CURRENT_BRANCH="$(cd "${SCRIPT_DIR}"; git rev-parse --abbrev-ref HEAD)" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 151 | NEW_BRANCH="master" |
| 152 | ;; |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 153 | --gc) |
| 154 | echo -e "\e[32mCollecting garbage...\e[0m" |
| 155 | docker_garbage |
| 156 | exit 0 |
| 157 | ;; |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 158 | --nightly) |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 159 | CURRENT_BRANCH="$(cd "${SCRIPT_DIR}"; git rev-parse --abbrev-ref HEAD)" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 160 | NEW_BRANCH="nightly" |
| 161 | ;; |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 162 | --prefetch) |
| 163 | echo -e "\e[32mPrefetching images...\e[0m" |
| 164 | prefetch_images |
| 165 | exit 0 |
| 166 | ;; |
| 167 | -f|--force) |
| Matthias Andreas Benkard | b4b5cc1 | 2021-12-28 18:02:04 +0100 | [diff] [blame] | 168 | echo -e "\e[32mRunning in forced mode...\e[0m" |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 169 | FORCE=y |
| 170 | ;; |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 171 | -d|--dev) |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 172 | # Already handled at the top of the script before _modules update |
| 173 | ;; |
| 174 | --legacy) |
| 175 | CURRENT_BRANCH="$(cd "${SCRIPT_DIR}"; git rev-parse --abbrev-ref HEAD)" |
| 176 | NEW_BRANCH="legacy" |
| Matthias Andreas Benkard | b7a1351 | 2023-11-18 16:44:25 +0100 | [diff] [blame] | 177 | ;; |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 178 | --help|-h) |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 179 | echo './update.sh [-c|--check, --check-tags, --ours, --gc, --nightly, --prefetch, --skip-start, --skip-ping-check, --stable, --legacy, -f|--force, -d|--dev, -h|--help] |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 180 | |
| 181 | -c|--check - Check for updates and exit (exit codes => 0: update available, 3: no updates) |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 182 | --check-tags - Check for newer tags and exit (exit codes => 0: newer tag available, 3: no newer tag) |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 183 | --ours - Use merge strategy option "ours" to solve conflicts in favor of non-mailcow code (local changes over remote changes), not recommended! |
| 184 | --gc - Run garbage collector to delete old image tags |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 185 | --nightly - Switch your mailcow updates to the unstable (nightly) branch. FOR TESTING PURPOSES ONLY!!!! |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 186 | --prefetch - Only prefetch new images and exit (useful to prepare updates) |
| 187 | --skip-start - Do not start mailcow after update |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 188 | --skip-ping-check - Skip ICMP Check to public DNS resolvers (Use it only if you'\''ve blocked any ICMP Connections to your mailcow machine) |
| 189 | --stable - Switch your mailcow updates to the stable (master) branch. Default unless you changed it with --nightly or --legacy. |
| 190 | --legacy - Switch your mailcow updates to the legacy branch. The legacy branch will only receive security updates until February 2026. |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 191 | -f|--force - Force update, do not ask questions |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 192 | -d|--dev - Enables Developer Mode (No Checkout of update.sh for tests) |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 193 | ' |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 194 | exit 0 |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 195 | esac |
| 196 | shift |
| 197 | done |
| 198 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 199 | [[ ! -f mailcow.conf ]] && { echo -e "\e[31mmailcow.conf is missing! Is mailcow installed?\e[0m"; exit 1;} |
| 200 | |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 201 | chmod 600 mailcow.conf |
| 202 | source mailcow.conf |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 203 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 204 | get_compose_type |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 205 | |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 206 | DOTS=${MAILCOW_HOSTNAME//[^.]}; |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 207 | if [ ${#DOTS} -lt 1 ]; then |
| 208 | echo -e "\e[31mMAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) is not a FQDN!\e[0m" |
| 209 | sleep 1 |
| 210 | echo "Please change it to a FQDN and redeploy the stack with $COMPOSE_COMMAND up -d" |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 211 | exit 1 |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 212 | elif [[ "${MAILCOW_HOSTNAME: -1}" == "." ]]; then |
| 213 | echo "MAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) is ending with a dot. This is not a valid FQDN!" |
| 214 | exit 1 |
| 215 | elif [ ${#DOTS} -eq 1 ]; then |
| 216 | echo -e "\e[33mMAILCOW_HOSTNAME (${MAILCOW_HOSTNAME}) does not contain a Subdomain. This is not fully tested and may cause issues.\e[0m" |
| 217 | echo "Find more information about why this message exists here: https://github.com/mailcow/mailcow-dockerized/issues/1572" |
| 218 | read -r -p "Do you want to proceed anyway? [y/N] " response |
| 219 | if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 220 | echo "OK. Proceeding." |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 221 | else |
| 222 | echo "OK. Exiting." |
| 223 | exit 1 |
| 224 | fi |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 225 | fi |
| 226 | |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 227 | detect_bad_asn |
| 228 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 229 | if [[ ("${SKIP_PING_CHECK}" == "y") ]]; then |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 230 | echo -e "\e[32mSkipping Ping Check...\e[0m" |
| 231 | |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 232 | else |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 233 | echo -en "Checking internet connection... " |
| 234 | if ! check_online_status; then |
| 235 | echo -e "\e[31mfailed\e[0m" |
| 236 | exit 1 |
| 237 | else |
| 238 | echo -e "\e[32mOK\e[0m" |
| 239 | fi |
| 240 | fi |
| 241 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 242 | if ! [ "$NEW_BRANCH" ]; then |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 243 | echo -e "\e[33mDetecting which build your mailcow runs on...\e[0m" |
| 244 | sleep 1 |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 245 | if [ "${BRANCH}" == "master" ]; then |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 246 | echo -e "\e[32mYou are receiving stable updates (master).\e[0m" |
| 247 | echo -e "\e[33mTo change that run the update.sh Script one time with the --nightly parameter to switch to nightly builds.\e[0m" |
| 248 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 249 | elif [ "${BRANCH}" == "nightly" ]; then |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 250 | echo -e "\e[31mYou are receiving unstable updates (nightly). These are for testing purposes only!!!\e[0m" |
| 251 | sleep 1 |
| 252 | echo -e "\e[33mTo change that run the update.sh Script one time with the --stable parameter to switch to stable builds.\e[0m" |
| 253 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 254 | elif [ "${BRANCH}" == "legacy" ]; then |
| 255 | echo -e "\e[31mYou are receiving legacy updates. The legacy branch will only receive security updates until February 2026.\e[0m" |
| 256 | sleep 1 |
| 257 | echo -e "\e[33mTo change that run the update.sh Script one time with the --stable parameter to switch to stable builds.\e[0m" |
| 258 | |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 259 | else |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 260 | echo -e "\e[33mYou are receiving updates from an unsupported branch.\e[0m" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 261 | sleep 1 |
| 262 | echo -e "\e[33mThe mailcow stack might still work but it is recommended to switch to the master branch (stable builds).\e[0m" |
| 263 | echo -e "\e[33mTo change that run the update.sh Script one time with the --stable parameter to switch to stable builds.\e[0m" |
| 264 | fi |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 265 | elif [ "$FORCE" ]; then |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 266 | echo -e "\e[31mYou are running in forced mode!\e[0m" |
| 267 | echo -e "\e[31mA Branch Switch can only be performed manually (monitored).\e[0m" |
| 268 | echo -e "\e[31mPlease rerun the update.sh Script without the --force/-f parameter.\e[0m" |
| 269 | sleep 1 |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 270 | elif [ "$NEW_BRANCH" == "master" ] && [ "$CURRENT_BRANCH" != "master" ]; then |
| 271 | echo -e "\e[33mYou are about to switch your mailcow updates to the stable (master) branch.\e[0m" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 272 | sleep 1 |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 273 | echo -e "\e[33mBefore you do: Please take a backup of all components to ensure that no data is lost...\e[0m" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 274 | sleep 1 |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 275 | echo -e "\e[31mWARNING: Please see on GitHub or ask in the community if a switch to master is stable or not. |
| 276 | In some rear cases an update back to master can destroy your mailcow configuration such as database upgrade, etc. |
| 277 | Normally an upgrade back to master should be safe during each full release. |
| 278 | Check GitHub for Database changes and update only if there similar to the full release!\e[0m" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 279 | read -r -p "Are you sure you that want to continue upgrading to the stable (master) branch? [y/N] " response |
| 280 | if [[ ! "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then |
| 281 | echo "OK. If you prepared yourself for that please run the update.sh Script with the --stable parameter again to trigger this process here." |
| 282 | exit 0 |
| 283 | fi |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 284 | BRANCH="$NEW_BRANCH" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 285 | DIFF_DIRECTORY=update_diffs |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 286 | DIFF_FILE="${DIFF_DIRECTORY}/diff_before_upgrade_to_master_$(date +"%Y-%m-%d-%H-%M-%S")" |
| 287 | mv diff_before_upgrade* "${DIFF_DIRECTORY}/" 2> /dev/null |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 288 | if ! git diff-index --quiet HEAD; then |
| 289 | echo -e "\e[32mSaving diff to ${DIFF_FILE}...\e[0m" |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 290 | mkdir -p "${DIFF_DIRECTORY}" |
| 291 | git diff "${BRANCH}" --stat > "${DIFF_FILE}" |
| 292 | git diff "${BRANCH}" >> "${DIFF_FILE}" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 293 | fi |
| 294 | echo -e "\e[32mSwitching Branch to ${BRANCH}...\e[0m" |
| 295 | git fetch origin |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 296 | git checkout -f "${BRANCH}" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 297 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 298 | elif [ "$NEW_BRANCH" == "nightly" ] && [ "$CURRENT_BRANCH" != "nightly" ]; then |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 299 | echo -e "\e[33mYou are about to switch your mailcow Updates to the unstable (nightly) branch.\e[0m" |
| 300 | sleep 1 |
| 301 | echo -e "\e[33mBefore you do: Please take a backup of all components to ensure that no Data is lost...\e[0m" |
| 302 | sleep 1 |
| 303 | echo -e "\e[31mWARNING: A switch to nightly is possible any time. But a switch back (to master) isn't.\e[0m" |
| 304 | read -r -p "Are you sure you that want to continue upgrading to the unstable (nightly) branch? [y/N] " response |
| 305 | if [[ ! "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then |
| 306 | echo "OK. If you prepared yourself for that please run the update.sh Script with the --nightly parameter again to trigger this process here." |
| 307 | exit 0 |
| 308 | fi |
| 309 | BRANCH=$NEW_BRANCH |
| 310 | DIFF_DIRECTORY=update_diffs |
| 311 | DIFF_FILE=${DIFF_DIRECTORY}/diff_before_upgrade_to_nightly_$(date +"%Y-%m-%d-%H-%M-%S") |
| 312 | mv diff_before_upgrade* ${DIFF_DIRECTORY}/ 2> /dev/null |
| 313 | if ! git diff-index --quiet HEAD; then |
| 314 | echo -e "\e[32mSaving diff to ${DIFF_FILE}...\e[0m" |
| 315 | mkdir -p ${DIFF_DIRECTORY} |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 316 | git diff "${BRANCH}" --stat > "${DIFF_FILE}" |
| 317 | git diff "${BRANCH}" >> "${DIFF_FILE}" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 318 | fi |
| 319 | git fetch origin |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 320 | git checkout -f "${BRANCH}" |
| 321 | elif [ "$NEW_BRANCH" == "legacy" ] && [ "$CURRENT_BRANCH" != "legacy" ]; then |
| 322 | echo -e "\e[33mYou are about to switch your mailcow Updates to the legacy branch.\e[0m" |
| 323 | sleep 1 |
| 324 | echo -e "\e[33mBefore you do: Please take a backup of all components to ensure that no Data is lost...\e[0m" |
| 325 | sleep 1 |
| 326 | echo -e "\e[31mWARNING: A switch to stable or nightly is possible any time.\e[0m" |
| 327 | read -r -p "Are you sure you want to continue upgrading to the legacy branch? [y/N] " response |
| 328 | if [[ ! "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then |
| 329 | echo "OK. If you prepared yourself for that please run the update.sh Script with the --legacy parameter again to trigger this process here." |
| 330 | exit 0 |
| 331 | fi |
| 332 | BRANCH=$NEW_BRANCH |
| 333 | DIFF_DIRECTORY=update_diffs |
| 334 | DIFF_FILE=${DIFF_DIRECTORY}/diff_before_upgrade_to_legacy_$(date +"%Y-%m-%d-%H-%M-%S") |
| 335 | mv diff_before_upgrade* ${DIFF_DIRECTORY}/ 2> /dev/null |
| 336 | if ! git diff-index --quiet HEAD; then |
| 337 | echo -e "\e[32mSaving diff to ${DIFF_FILE}...\e[0m" |
| 338 | mkdir -p ${DIFF_DIRECTORY} |
| 339 | git diff "${BRANCH}" --stat > "${DIFF_FILE}" |
| 340 | git diff "${BRANCH}" >> "${DIFF_FILE}" |
| 341 | fi |
| 342 | git fetch origin |
| 343 | git checkout -f "${BRANCH}" |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 344 | fi |
| 345 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 346 | if [ ! "$DEV" ]; then |
| 347 | EXIT_COUNT=0 |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 348 | echo -e "\e[32mChecking for newer update script...\e[0m" |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 349 | SHA1_1="$(sha1sum update.sh)" |
| 350 | git fetch origin |
| 351 | git checkout "origin/${BRANCH}" -- update.sh |
| 352 | SHA1_2="$(sha1sum update.sh)" |
| 353 | if [[ "${SHA1_1}" != "${SHA1_2}" ]]; then |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 354 | chmod +x update.sh |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 355 | EXIT_COUNT+=1 |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 356 | fi |
| Matthias Andreas Benkard | b7a1351 | 2023-11-18 16:44:25 +0100 | [diff] [blame] | 357 | fi |
| 358 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 359 | if [ ! "$FORCE" ]; then |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 360 | read -r -p "Are you sure you want to update mailcow: dockerized? All containers will be stopped. [y/N] " response |
| Matthias Andreas Benkard | 8f91594 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 361 | if [[ ! "${response}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 362 | echo "OK, exiting." |
| 363 | exit 0 |
| 364 | fi |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 365 | detect_major_update |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 366 | fi |
| 367 | |
| 368 | echo -e "\e[32mValidating docker-compose stack configuration...\e[0m" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 369 | sed -i 's/HTTPS_BIND:-:/HTTPS_BIND:-/g' docker-compose.yml |
| 370 | sed -i 's/HTTP_BIND:-:/HTTP_BIND:-/g' docker-compose.yml |
| 371 | if ! $COMPOSE_COMMAND config -q; then |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 372 | echo -e "\e[31m\nOh no, something went wrong. Please check the error message above.\e[0m" |
| 373 | exit 1 |
| 374 | fi |
| 375 | |
| 376 | echo -e "\e[32mChecking for conflicting bridges...\e[0m" |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 377 | MAILCOW_BRIDGE=$($COMPOSE_COMMAND config | grep -i com.docker.network.bridge.name | cut -d':' -f2) |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 378 | while read NAT_ID; do |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 379 | iptables -t nat -D POSTROUTING "$NAT_ID" |
| 380 | done < <(iptables -L -vn -t nat --line-numbers | grep "$IPV4_NETWORK" | grep -E 'MASQUERADE.*all' | grep -v "${MAILCOW_BRIDGE}" | cut -d' ' -f1) |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 381 | |
| 382 | DIFF_DIRECTORY=update_diffs |
| 383 | DIFF_FILE=${DIFF_DIRECTORY}/diff_before_update_$(date +"%Y-%m-%d-%H-%M-%S") |
| 384 | mv diff_before_update* ${DIFF_DIRECTORY}/ 2> /dev/null |
| 385 | if ! git diff-index --quiet HEAD; then |
| 386 | echo -e "\e[32mSaving diff to ${DIFF_FILE}...\e[0m" |
| 387 | mkdir -p ${DIFF_DIRECTORY} |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 388 | git diff --stat > "${DIFF_FILE}" |
| 389 | git diff >> "${DIFF_FILE}" |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 390 | fi |
| 391 | |
| 392 | echo -e "\e[32mPrefetching images...\e[0m" |
| 393 | prefetch_images |
| 394 | |
| 395 | echo -e "\e[32mStopping mailcow...\e[0m" |
| 396 | sleep 2 |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 397 | MAILCOW_CONTAINERS=($($COMPOSE_COMMAND ps -q)) |
| 398 | $COMPOSE_COMMAND down |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 399 | echo -e "\e[32mChecking for remaining containers...\e[0m" |
| 400 | sleep 2 |
| 401 | for container in "${MAILCOW_CONTAINERS[@]}"; do |
| 402 | docker rm -f "$container" 2> /dev/null |
| 403 | done |
| 404 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 405 | configure_ipv6 |
| 406 | |
| Matthias Andreas Benkard | 8f91594 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 407 | [[ -f data/conf/nginx/ZZZ-ejabberd.conf ]] && rm data/conf/nginx/ZZZ-ejabberd.conf |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 408 | migrate_config_options |
| 409 | adapt_new_options |
| Matthias Andreas Benkard | 8f91594 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 410 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 411 | if [ ! "$DEV" ]; then |
| 412 | DEFAULT_REPO="https://github.com/mailcow/mailcow-dockerized" |
| 413 | CURRENT_REPO=$(git config --get remote.origin.url) |
| 414 | if [ "$CURRENT_REPO" != "$DEFAULT_REPO" ]; then |
| 415 | echo "The Repository currently used is not the default mailcow Repository." |
| 416 | echo "Currently Repository: $CURRENT_REPO" |
| 417 | echo "Default Repository: $DEFAULT_REPO" |
| 418 | if [ ! "$FORCE" ]; then |
| 419 | read -r -p "Should it be changed back to default? [y/N] " repo_response |
| 420 | if [[ "$repo_response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then |
| 421 | git remote set-url origin $DEFAULT_REPO |
| 422 | fi |
| 423 | else |
| 424 | echo "Running in forced mode... setting Repo to default!" |
| 425 | git remote set-url origin $DEFAULT_REPO |
| Matthias Andreas Benkard | 9dabdab | 2024-03-06 13:12:09 +0100 | [diff] [blame] | 426 | fi |
| Matthias Andreas Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 427 | fi |
| 428 | fi |
| 429 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 430 | if [ ! "$DEV" ]; then |
| Matthias Andreas Benkard | 9dabdab | 2024-03-06 13:12:09 +0100 | [diff] [blame] | 431 | echo -e "\e[32mCommitting current status...\e[0m" |
| 432 | [[ -z "$(git config user.name)" ]] && git config user.name moo |
| 433 | [[ -z "$(git config user.email)" ]] && git config user.email moo@cow.moo |
| 434 | [[ ! -z $(git ls-files data/conf/rspamd/override.d/worker-controller-password.inc) ]] && git rm data/conf/rspamd/override.d/worker-controller-password.inc |
| 435 | git add -u |
| 436 | git commit -am "Before update on ${DATE}" > /dev/null |
| 437 | echo -e "\e[32mFetching updated code from remote...\e[0m" |
| 438 | git fetch origin #${BRANCH} |
| 439 | echo -e "\e[32mMerging local with remote code (recursive, strategy: \"${MERGE_STRATEGY:-theirs}\", options: \"patience\"...\e[0m" |
| 440 | git config merge.defaultToUpstream true |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 441 | git merge -X"${MERGE_STRATEGY:-theirs}" -Xpatience -m "After update on ${DATE}" |
| Matthias Andreas Benkard | 9dabdab | 2024-03-06 13:12:09 +0100 | [diff] [blame] | 442 | # Need to use a variable to not pass return codes of if checks |
| 443 | MERGE_RETURN=$? |
| 444 | if [[ ${MERGE_RETURN} == 128 ]]; then |
| 445 | 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" |
| 446 | exit 1 |
| 447 | elif [[ ${MERGE_RETURN} == 1 ]]; then |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 448 | echo -e "\e[93mPotential conflict, trying to fix...\e[0m" |
| Matthias Andreas Benkard | 9dabdab | 2024-03-06 13:12:09 +0100 | [diff] [blame] | 449 | git status --porcelain | grep -E "UD|DU" | awk '{print $2}' | xargs rm -v |
| 450 | git add -A |
| 451 | git commit -m "After update on ${DATE}" > /dev/null |
| 452 | git checkout . |
| 453 | echo -e "\e[32mRemoved and recreated files if necessary.\e[0m" |
| 454 | elif [[ ${MERGE_RETURN} != 0 ]]; then |
| 455 | echo -e "\e[31m\nOh no, something went wrong. Please check the error message above.\e[0m" |
| 456 | echo |
| 457 | echo "Run $COMPOSE_COMMAND up -d to restart your stack without updates or try again after fixing the mentioned errors." |
| 458 | exit 1 |
| 459 | fi |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 460 | else |
| Matthias Andreas Benkard | 9dabdab | 2024-03-06 13:12:09 +0100 | [diff] [blame] | 461 | 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 Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 462 | fi |
| 463 | |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 464 | echo -e "\e[32mFetching new images, if any...\e[0m" |
| 465 | sleep 2 |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 466 | $COMPOSE_COMMAND pull |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 467 | |
| 468 | # Fix missing SSL, does not overwrite existing files |
| 469 | [[ ! -d data/assets/ssl ]] && mkdir -p data/assets/ssl |
| 470 | cp -n -d data/assets/ssl-example/*.pem data/assets/ssl/ |
| 471 | |
| 472 | echo -e "Checking IPv6 settings... " |
| 473 | if grep -q 'SYSCTL_IPV6_DISABLED=1' mailcow.conf; then |
| 474 | echo |
| 475 | echo '!! IMPORTANT !!' |
| 476 | echo |
| 477 | 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 Benkard | d63fe56 | 2023-11-18 13:18:30 +0100 | [diff] [blame] | 478 | 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 Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 479 | echo |
| 480 | echo '!! IMPORTANT !!' |
| 481 | echo |
| 482 | read -p "Press any key to continue..." < /dev/tty |
| 483 | fi |
| 484 | |
| 485 | # Checking for old project name bug |
| 486 | sed -i --follow-symlinks 's#COMPOSEPROJECT_NAME#COMPOSE_PROJECT_NAME#g' mailcow.conf |
| 487 | |
| 488 | # Fix Rspamd maps |
| 489 | if [ -f data/conf/rspamd/custom/global_from_blacklist.map ]; then |
| 490 | mv data/conf/rspamd/custom/global_from_blacklist.map data/conf/rspamd/custom/global_smtp_from_blacklist.map |
| 491 | fi |
| 492 | if [ -f data/conf/rspamd/custom/global_from_whitelist.map ]; then |
| 493 | mv data/conf/rspamd/custom/global_from_whitelist.map data/conf/rspamd/custom/global_smtp_from_whitelist.map |
| 494 | fi |
| 495 | |
| 496 | # Fix deprecated metrics.conf |
| 497 | if [ -f "data/conf/rspamd/local.d/metrics.conf" ]; then |
| 498 | if [ ! -z "$(git diff --name-only origin/master data/conf/rspamd/local.d/metrics.conf)" ]; then |
| 499 | 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." |
| 500 | echo "The deprecated configuration file metrics.conf will be moved to metrics.conf_deprecated after updating mailcow." |
| 501 | fi |
| 502 | mv data/conf/rspamd/local.d/metrics.conf data/conf/rspamd/local.d/metrics.conf_deprecated |
| 503 | fi |
| 504 | |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 505 | # Set app_info.inc.php |
| 506 | if [ ${BRANCH} == "master" ]; then |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 507 | mailcow_git_version=$(git describe --tags $(git rev-list --tags --max-count=1)) |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 508 | elif [ ${BRANCH} == "nightly" ]; then |
| 509 | mailcow_git_version=$(git rev-parse --short $(git rev-parse @{upstream})) |
| 510 | mailcow_last_git_version="" |
| 511 | else |
| 512 | mailcow_git_version=$(git rev-parse --short HEAD) |
| 513 | mailcow_last_git_version="" |
| 514 | fi |
| 515 | |
| Matthias Andreas Benkard | 97f1202 | 2026-10-23 08:46:40 +0200 | [diff] [blame] | 516 | mailcow_git_commit=$(git rev-parse "origin/${BRANCH}") |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 517 | mailcow_git_commit_date=$(git log -1 --format=%ci @{upstream} ) |
| 518 | |
| 519 | if [ $? -eq 0 ]; then |
| 520 | echo '<?php' > data/web/inc/app_info.inc.php |
| 521 | echo ' $MAILCOW_GIT_VERSION="'$mailcow_git_version'";' >> data/web/inc/app_info.inc.php |
| 522 | echo ' $MAILCOW_LAST_GIT_VERSION="";' >> data/web/inc/app_info.inc.php |
| 523 | echo ' $MAILCOW_GIT_OWNER="mailcow";' >> data/web/inc/app_info.inc.php |
| 524 | echo ' $MAILCOW_GIT_REPO="mailcow-dockerized";' >> data/web/inc/app_info.inc.php |
| 525 | echo ' $MAILCOW_GIT_URL="https://github.com/mailcow/mailcow-dockerized";' >> data/web/inc/app_info.inc.php |
| 526 | echo ' $MAILCOW_GIT_COMMIT="'$mailcow_git_commit'";' >> data/web/inc/app_info.inc.php |
| 527 | echo ' $MAILCOW_GIT_COMMIT_DATE="'$mailcow_git_commit_date'";' >> data/web/inc/app_info.inc.php |
| 528 | echo ' $MAILCOW_BRANCH="'$BRANCH'";' >> data/web/inc/app_info.inc.php |
| 529 | echo ' $MAILCOW_UPDATEDAT='$(date +%s)';' >> data/web/inc/app_info.inc.php |
| 530 | echo '?>' >> data/web/inc/app_info.inc.php |
| 531 | else |
| 532 | echo '<?php' > data/web/inc/app_info.inc.php |
| 533 | echo ' $MAILCOW_GIT_VERSION="'$mailcow_git_version'";' >> data/web/inc/app_info.inc.php |
| 534 | echo ' $MAILCOW_LAST_GIT_VERSION="";' >> data/web/inc/app_info.inc.php |
| 535 | echo ' $MAILCOW_GIT_OWNER="mailcow";' >> data/web/inc/app_info.inc.php |
| 536 | echo ' $MAILCOW_GIT_REPO="mailcow-dockerized";' >> data/web/inc/app_info.inc.php |
| 537 | echo ' $MAILCOW_GIT_URL="https://github.com/mailcow/mailcow-dockerized";' >> data/web/inc/app_info.inc.php |
| 538 | echo ' $MAILCOW_GIT_COMMIT="";' >> data/web/inc/app_info.inc.php |
| 539 | echo ' $MAILCOW_GIT_COMMIT_DATE="";' >> data/web/inc/app_info.inc.php |
| 540 | echo ' $MAILCOW_BRANCH="'$BRANCH'";' >> data/web/inc/app_info.inc.php |
| 541 | echo ' $MAILCOW_UPDATEDAT='$(date +%s)';' >> data/web/inc/app_info.inc.php |
| 542 | echo '?>' >> data/web/inc/app_info.inc.php |
| 543 | echo -e "\e[33mCannot determine current git repository version...\e[0m" |
| 544 | fi |
| 545 | |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 546 | if [[ ${SKIP_START} == "y" ]]; then |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 547 | echo -e "\e[33mNot starting mailcow, please run \"$COMPOSE_COMMAND up -d --remove-orphans\" to start mailcow.\e[0m" |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 548 | else |
| 549 | echo -e "\e[32mStarting mailcow...\e[0m" |
| 550 | sleep 2 |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 551 | $COMPOSE_COMMAND up -d --remove-orphans |
| Matthias Andreas Benkard | 4edeb9f | 2021-01-02 15:32:21 +0100 | [diff] [blame] | 552 | fi |
| 553 | |
| 554 | echo -e "\e[32mCollecting garbage...\e[0m" |
| 555 | docker_garbage |
| 556 | |
| Matthias Andreas Benkard | 8f91594 | 2021-08-16 10:57:25 +0200 | [diff] [blame] | 557 | # Run post-update-hook |
| 558 | if [ -f "${SCRIPT_DIR}/post_update_hook.sh" ]; then |
| 559 | bash "${SCRIPT_DIR}/post_update_hook.sh" |
| 560 | fi |
| 561 | |
| Matthias Andreas Benkard | 3c18a08 | 2022-12-27 17:32:58 +0100 | [diff] [blame] | 562 | # echo "In case you encounter any problem, hard-reset to a state before updating mailcow:" |
| 563 | # echo |
| 564 | # git reflog --color=always | grep "Before update on " |
| 565 | # echo |
| Matthias Andreas Benkard | b7a1351 | 2023-11-18 16:44:25 +0100 | [diff] [blame] | 566 | # echo "Use \"git reset --hard hash-on-the-left\" and run $COMPOSE_COMMAND up -d afterwards." |