blob: ae2d6ab14e9a645543e3f974ce37d8cfbcde8bd5 [file] [log] [blame]
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +01001#!/bin/bash
2SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3
4source ${SCRIPT_DIR}/../mailcow.conf
5
6if [ "${DOCKER_COMPOSE_VERSION}" == "standalone" ]; then
7LATEST_COMPOSE=$(curl -Ls -w %{url_effective} -o /dev/null https://github.com/docker/compose/releases/latest) # redirect to latest release
8LATEST_COMPOSE=${LATEST_COMPOSE##*/v} #get the latest version from the redirect, excluding the "v" prefix
9COMPOSE_VERSION=$(docker-compose version --short)
10if [[ "$LATEST_COMPOSE" != "$COMPOSE_VERSION" ]]; then
11 echo -e "\e[33mA new docker-compose Version is available: $LATEST_COMPOSE\e[0m"
12 echo -e "\e[33mYour Version is: $COMPOSE_VERSION\e[0m"
13else
14 echo -e "\e[32mYour docker-compose Version is up to date! Not updating it...\e[0m"
15 exit 0
16fi
17read -r -p "Do you want to update your docker-compose Version? It will automatic upgrade your docker-compose installation (recommended)? [y/N] " updatecomposeresponse
18 if [[ ! "${updatecomposeresponse}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
19 echo "OK, not updating docker-compose."
20 exit 0
21 fi
22echo -e "\e[32mFetching new docker-compose (standalone) version...\e[0m"
23echo -e "\e[32mTrying to determine GLIBC version...\e[0m"
24 if ldd --version > /dev/null; then
25 GLIBC_V=$(ldd --version | grep -E '(GLIBC|GNU libc)' | rev | cut -d ' ' -f1 | rev | cut -d '.' -f2)
26 if [ ! -z "${GLIBC_V}" ] && [ ${GLIBC_V} -gt 27 ]; then
27 DC_DL_SUFFIX=
28 else
29 DC_DL_SUFFIX=legacy
30 fi
31 else
32 DC_DL_SUFFIX=legacy
33 fi
34 sleep 1
35 if [[ $(command -v pip 2>&1) && $(pip list --local 2>&1 | grep -v DEPRECATION | grep -c docker-compose) == 1 || $(command -v pip3 2>&1) && $(pip3 list --local 2>&1 | grep -v DEPRECATION | grep -c docker-compose) == 1 ]]; then
36 echo -e "\e[33mFound a docker-compose Version installed with pip!\e[0m"
37 echo -e "\e[31mPlease uninstall the pip Version of docker-compose since it doesn't support Versions higher than 1.29.2.\e[0m"
38 sleep 2
39 echo -e "\e[33mExiting...\e[0m"
40 exit 1
41 #prevent breaking a working docker-compose installed with pip
42 elif [[ $(curl -sL -w "%{http_code}" https://github.com/docker/compose/releases/latest -o /dev/null) == "200" ]]; then
43 LATEST_COMPOSE=$(curl -Ls -w %{url_effective} -o /dev/null https://github.com/docker/compose/releases/latest) # redirect to latest release
44 LATEST_COMPOSE=${LATEST_COMPOSE##*/} #get the latest version from the redirect, inlcuding the "v" prefix
45 COMPOSE_VERSION=$(docker-compose version --short)
46 if [[ "$LATEST_COMPOSE" != "$COMPOSE_VERSION" ]]; then
47 COMPOSE_PATH=$(command -v docker-compose)
48 if [[ -w ${COMPOSE_PATH} ]]; then
49 curl -#L https://github.com/docker/compose/releases/download/${LATEST_COMPOSE}/docker-compose-$(uname -s)-$(uname -m) > $COMPOSE_PATH
50 chmod +x $COMPOSE_PATH
51 echo -e "\e[32mYour Docker Compose (standalone) has been updated to: $LATEST_COMPOSE\e[0m"
52 exit 0
53 else
54 echo -e "\e[33mWARNING: $COMPOSE_PATH is not writable, but new version $LATEST_COMPOSE is available (installed: $COMPOSE_VERSION)\e[0m"
55 exit 1
56 fi
57 fi
58 else
59 echo -e "\e[33mCannot determine latest docker-compose version, skipping...\e[0m"
60 exit 1
61 fi
62
63elif [ "${DOCKER_COMPOSE_VERSION}" == "native" ]; then
64 echo -e "\e[31mYou are using the native Docker Compose Plugin. This Script is for the standalone Docker Compose Version only.\e[0m"
65 sleep 2
66 echo -e "\e[33mNotice: You'll have to update this Compose Version via your Package Manager manually!\e[0m"
67 exit 1
68
69else
70 echo -e "\e[31mCan not read DOCKER_COMPOSE_VERSION variable from mailcow.conf! Is your mailcow up to date? Exiting...\e[0m"
71 exit 1
72fi