From 4121c146dfb25f59488bfcb31ac3764c24030250 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 10 Mar 2024 20:17:41 +0100 Subject: [PATCH] chore: simplify and fix indents for postremove (#12849) --- packaging/scripts/postremove.sh | 69 +++++++++++++-------------------- 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/packaging/scripts/postremove.sh b/packaging/scripts/postremove.sh index 6ef3b8cef..57e207b9c 100644 --- a/packaging/scripts/postremove.sh +++ b/packaging/scripts/postremove.sh @@ -18,51 +18,38 @@ if [ "$1" = "purge" ]; then fi fi - - - -# if interactive: Call /usr/bin/evcc checkconfig and check the return code (newer version) +# if interactive: call `/usr/bin/evcc checkconfig` and check the return code (newer version) # if return code is 0, do nothing # else: Ask user if he wants to keep the old version (working) or the new version (not working) # Remember the choice with /tmp/.evccrollback and fail new-postrm failed-upgrade old-version new-version to initiate dpkg's rollback -if [ "$1" = "upgrade" ]; then - INTERACTIVE=0 - # is shell script interactive? - if [ -t 0 ]; then - INTERACTIVE=1 - else - INTERACTIVE=0 - fi +if [ "$1" = "upgrade" ] && [ -t 0 ]; then + if ! /usr/bin/evcc checkconfig > /dev/null; then + echo "--------------------------------------------------------------------------------" + echo "ERROR: your configuration is not compatible with the new version:" + /usr/bin/evcc checkconfig --log error || true + echo "Please consult the release notes: https://github.com/evcc-io/evcc/releases" + echo "--------------------------------------------------------------------------------" - if [ $INTERACTIVE -eq 1 ]; then - if ! /usr/bin/evcc checkconfig > /dev/null; then - echo "--------------------------------------------------------------------------------" - echo "ERROR: your evcc configuration is not compatible with the new version. Please consider reading the release notes: https://github.com/evcc-io/evcc/releases" - echo "checkconfig Output:" - /usr/bin/evcc checkconfig || true - echo "--------------------------------------------------------------------------------" - - while true; do - echo "Do you want to keep your old (working) evcc version? [Y/n]: " - read choice - case "$choice" in - n*|N*|"") - echo "We will keep the new version. Your evcc configuration stays untouched!" - break - ;; - y*|Y*) - echo "The old version will be restored. Your evcc configuration stays untouched! Following errors are intended:" - touch /tmp/.evccrollback - exit 1 - break - ;; - *) - ;; - esac - done - fi - fi -fi + while true; do + echo "Do you want to keep your old (working) version? [Y/n]: " + read choice + case "$choice" in + n*|N*|"") + echo "We will keep the new version. Your configuration stays untouched!" + break + ;; + y*|Y*) + echo "The old version will be restored. Your configuration stays untouched! Following errors are intended:" + touch /tmp/.evccrollback + exit 1 + break + ;; + *) + ;; + esac + done + fi +fi # if upgrade goal fails, new-postrm failed-upgrade old-version new-version is called. It should fail to initiate rollback if [ "$1" = "failed-upgrade" ]; then