From 74baf20feb0bf993afd400828ff85d5c0947331f Mon Sep 17 00:00:00 2001 From: DerLinkman Date: Tue, 7 Jun 2022 14:45:19 +0200 Subject: [PATCH] Optimized if-else arguments and outputs --- generate_config.sh | 10 +++++----- helper-scripts/_cold-standby.sh | 21 +++++++++++---------- helper-scripts/backup_and_restore.sh | 9 +++++---- update.sh | 11 ++++++----- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/generate_config.sh b/generate_config.sh index 0b01b8033..601d8ca27 100755 --- a/generate_config.sh +++ b/generate_config.sh @@ -30,12 +30,12 @@ for bin in openssl curl docker git awk sha1sum; do done echo "checking docker compose version..."; -if docker --help | grep compose; then - echo '' +if docker compose >/dev/null 2>&1; then + echo -e "\e[32mFound Compose v2!\e[0m" elif docker-compose version --short | grep -m1 "^1" > /dev/null 2>&1; then - echo -e "\e[31mWARN: Your machine is using Docker-Compose v1!\e[0m" - echo -e "\e[31mmailcow will drop the Docker-Compose v1 Support in December 2022\e[0m" - echo -e "\e[31mPlease consider a upgrade to Docker-Compose v2.\e[0m" + echo -e "\e[33mWARN: Your machine is using Docker-Compose v1!\e[0m" + echo -e "\e[33mmailcow will drop the Docker-Compose v1 Support in December 2022\e[0m" + echo -e "\e[33mPlease consider a upgrade to Docker-Compose v2.\e[0m" echo echo echo -e "\e[33mContinuing...\e[0m" diff --git a/helper-scripts/_cold-standby.sh b/helper-scripts/_cold-standby.sh index a1e2f165c..ca2056059 100755 --- a/helper-scripts/_cold-standby.sh +++ b/helper-scripts/_cold-standby.sh @@ -86,12 +86,12 @@ function preflight_local_checks() { echo "checking docker compose version..."; - if docker --help | grep compose; then - echo '' + if docker compose >/dev/null 2>&1; then + echo -e "\e[32mFound Compose v2 on local machine!\e[0m" elif docker-compose version --short | grep -m1 "^1" > /dev/null 2>&1; then - echo -e "\e[31mWARN: Your machine is using Docker-Compose v1!\e[0m" - echo -e "\e[31mmailcow will drop the Docker-Compose v1 Support in December 2022\e[0m" - echo -e "\e[31mPlease consider a upgrade to Docker-Compose v2.\e[0m" + echo -e "\e[33mWARN: Your machine is using Docker-Compose v1!\e[0m" + echo -e "\e[33mmailcow will drop the Docker-Compose v1 Support in December 2022\e[0m" + echo -e "\e[33mPlease consider a upgrade to Docker-Compose v2.\e[0m" echo echo echo -e "\e[33mContinuing...\e[0m" @@ -144,16 +144,17 @@ function preflight_remote_checks() { -i "${REMOTE_SSH_KEY}" \ ${REMOTE_SSH_HOST} \ -p ${REMOTE_SSH_PORT} \ - -t docker --help | grep compose; then + -t 'docker compose' >/dev/null 2>&1; then + echo -e "\e[32mFound Compose v2 on remote!\e[0m" COMPOSE_COMMAND="docker compose" elif ssh -q -o StrictHostKeyChecking=no \ -i "${REMOTE_SSH_KEY}" \ ${REMOTE_SSH_HOST} \ -p ${REMOTE_SSH_PORT} \ - 'docker-compose version --short' | grep -m1 "^1" > /dev/null 2>&1; then - echo -e "\e[31mWARN: The remote is using Docker-Compose v1!\e[0m" - echo -e "\e[31mmailcow will drop the Docker-Compose v1 Support in December 2022\e[0m" - echo -e "\e[31mPlease consider a upgrade to Docker-Compose v2 on remote.\e[0m" + -t 'docker-compose version --short' | grep -m1 "^1" > /dev/null 2>&1; then + echo -e "\e[33mWARN: The remote is using Docker-Compose v1!\e[0m" + echo -e "\e[33mmailcow will drop the Docker-Compose v1 Support in December 2022\e[0m" + echo -e "\e[33mPlease consider a upgrade to Docker-Compose v2 on remote.\e[0m" echo echo echo -e "\e[33mContinuing...\e[0m" diff --git a/helper-scripts/backup_and_restore.sh b/helper-scripts/backup_and_restore.sh index dd0c22123..b89c19d48 100755 --- a/helper-scripts/backup_and_restore.sh +++ b/helper-scripts/backup_and_restore.sh @@ -77,12 +77,13 @@ else fi echo "checking docker compose version..."; -if docker --help | grep compose; then +if docker compose >/dev/null 2>&1; then + echo -e "\e[32mFound Compose v2!\e[0m" COMPOSE_COMMAND="docker compose" elif docker-compose version --short | grep -m1 "^1" > /dev/null 2>&1; then - echo -e "\e[31mWARN: Your machine is using Docker-Compose v1!\e[0m" - echo -e "\e[31mmailcow will drop the Docker-Compose v1 Support in December 2022\e[0m" - echo -e "\e[31mPlease consider a upgrade to Docker-Compose v2.\e[0m" + echo -e "\e[33mWARN: Your machine is using Docker-Compose v1!\e[0m" + echo -e "\e[33mmailcow will drop the Docker-Compose v1 Support in December 2022\e[0m" + echo -e "\e[33mPlease consider a upgrade to Docker-Compose v2.\e[0m" echo echo echo -e "\e[33mContinuing...\e[0m" diff --git a/update.sh b/update.sh index f23999ae4..6d01edba5 100755 --- a/update.sh +++ b/update.sh @@ -46,12 +46,13 @@ done echo "checking docker compose version..."; -if docker --help | grep compose; then +if docker compose >/dev/null 2>&1; then + echo -e "\e[32mFound Compose v2!\e[0m" COMPOSE_COMMAND="docker compose" elif docker-compose version --short | grep -m1 "^1" > /dev/null 2>&1; then - echo -e "\e[31mWARN: Your machine is using Docker-Compose v1!\e[0m" - echo -e "\e[31mmailcow will drop the Docker-Compose v1 Support in December 2022\e[0m" - echo -e "\e[31mPlease consider a upgrade to Docker-Compose v2.\e[0m" + echo -e "\e[33mWARN: Your machine is using Docker-Compose v1!\e[0m" + echo -e "\e[33mmailcow will drop the Docker-Compose v1 Support in December 2022\e[0m" + echo -e "\e[33mPlease consider a upgrade to Docker-Compose v2.\e[0m" echo echo echo -e "\e[33mContinuing...\e[0m" @@ -738,4 +739,4 @@ fi #echo #git reflog --color=always | grep "Before update on " #echo -#echo "Use \"git reset --hard hash-on-the-left\" and run ${COMPOSE_COMMAND} up -d afterwards." +#echo "Use \"git reset --hard hash-on-the-left\" and run ${COMPOSE_COMMAND} up -d afterwards." \ No newline at end of file