From 31f222e73d0314b404f359c0d614829e6c539c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 29 Sep 2024 22:45:47 +0200 Subject: [PATCH] Add TRAP to the installer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8bc55c20..e57515d5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -25,6 +25,9 @@ set -e # When using "su" an incomplete PATH could be passed: https://github.com/pi-hole/pi-hole/issues/3209 export PATH+=':/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' +# Trap any errors, then exit +trap abort INT QUIT TERM + ######## VARIABLES ######### # For better maintainability, we store as much information that can change in variables # This allows us to make a change in one place that can propagate to all instances of the variable @@ -195,6 +198,15 @@ show_ascii_berry() { " } +abort() { + echo -e "\\n\\n ${COL_LIGHT_RED}Installation was interrupted${COL_NC}\\n" + echo -e "Pi-hole's dependencies might be already installed. If you want to remove them you can try to\\n" + echo -e "a) run 'pihole uninstall' \\n" + echo -e "b) Remove the meta-package 'pihole-meta' manually \\n" + echo -e "E.g. sudo apt-get remove pihole-meta && apt-get autoremove \\n" + exit 1 +} + is_command() { # Checks to see if the given command (passed as a string argument) exists on the system. # The function returns 0 (success) if the command exists, and 1 if it doesn't.