From 5957edc76b28b8331a2b01264fefce256dd06337 Mon Sep 17 00:00:00 2001 From: Vishnu Narayanan Date: Tue, 23 Aug 2022 18:56:39 +0530 Subject: [PATCH] feat: abort cwctl upgrade if custom code changes detected (#5329) * feat: abort cwctl upgrade if custom code changes detected * fix: cwctl exit handler on upgrade * chore: update cwctl version --- VERSION_CW | 2 +- deployment/setup_20.04.sh | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/VERSION_CW b/VERSION_CW index e70b4523a..ccbccc3dc 100644 --- a/VERSION_CW +++ b/VERSION_CW @@ -1 +1 @@ -2.6.0 +2.2.0 diff --git a/deployment/setup_20.04.sh b/deployment/setup_20.04.sh index d14fcac3f..4e86478c7 100644 --- a/deployment/setup_20.04.sh +++ b/deployment/setup_20.04.sh @@ -2,7 +2,7 @@ # Description: Install and manage a Chatwoot installation. # OS: Ubuntu 20.04 LTS -# Script Version: 2.1.0 +# Script Version: 2.2.0 # Run this script as root set -eu -o errexit -o pipefail -o noclobber -o nounset @@ -19,7 +19,7 @@ fi # option --output/-o requires 1 argument LONGOPTS=console,debug,help,install,Install:,logs:,restart,ssl,upgrade,webserver,version OPTIONS=cdhiI:l:rsuwv -CWCTL_VERSION="2.1.0" +CWCTL_VERSION="2.2.0" pg_pass=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 15 ; echo '') # if user does not specify an option @@ -128,7 +128,7 @@ trap exit_handler EXIT # None ############################################################################## function exit_handler() { - if [ "$?" -ne 0 ]; then + if [ "$?" -ne 0 ] && [ "$u" == "n" ]; then echo -en "\nSome error has occured. Check '/var/log/chatwoot-setup.log' for details.\n" exit 1 fi @@ -686,6 +686,28 @@ function ssl() { ssl_success_message } +############################################################################## +# Abort upgrade if custom code changes detected(-u/--upgrade) +# Globals: +# None +# Arguments: +# None +# Outputs: +# None +############################################################################## +function upgrade_prereq() { + sudo -i -u chatwoot << "EOF" + cd chatwoot + git update-index --refresh + git diff-index --quiet HEAD -- + if [ "$?" -eq 1 ]; then + echo "Custom code changes detected. Aborting update." + echo "Please proceed to update manually." + exit 1 + fi +EOF +} + ############################################################################## # Upgrade an existing installation to latest stable version(-u/--upgrade) # Globals: @@ -699,6 +721,7 @@ function upgrade() { get_cw_version echo "Upgrading Chatwoot to v$CW_VERSION" sleep 3 + upgrade_prereq sudo -i -u chatwoot << "EOF" # Navigate to the Chatwoot directory