From 283abc9d8fb357a9f83f8343fda4bc9372cb3832 Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Sat, 2 May 2020 13:15:15 +0200 Subject: [PATCH] Completed error function --- scripts/base.sh | 13 +++++++++++++ scripts/client/setup.sh | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/base.sh b/scripts/base.sh index 668d9e7..734a4b4 100644 --- a/scripts/base.sh +++ b/scripts/base.sh @@ -56,6 +56,19 @@ success(){ message "${COLOR_GREEN}" "SUCCESS" "$1"; } +error(){ + message "${COLOR_RED}" "ERROR" "$1 -> Leaving program." + if declare -f "destructor" > /dev/null + then + info "Calling destructor..." + destructor + else + warning "No destructor defined." + info "Can be that this script left some waste." + fi + exit 1; +} + HEADER(){ echo echo "${COLOR_YELLOW}The" diff --git a/scripts/client/setup.sh b/scripts/client/setup.sh index bd06519..2c9ecde 100644 --- a/scripts/client/setup.sh +++ b/scripts/client/setup.sh @@ -4,14 +4,14 @@ # @author Kevin Veen-Birkenbach [aka. Frantz] # # shellcheck source=/dev/null # Deactivate SC1090 + source "$(dirname "$(readlink -f "${0}")")/../base.sh" || (echo "Loading base.sh failed." && exit 1) SYSTEM_MEMORY_KB="$(grep MemTotal /proc/meminfo | awk '{print $2}')" info "Start setup of customized core software..." info "Copying templates to home folder..." -exit -cp -rfv "$TEMPLATE_PATH/." "$HOME" -echo "Synchronising packages..." -sudo pacman -Syyu +cp -rfv "$TEMPLATE_PATH/." "$HOME" || error "Copy templates failed." +info "Synchronising packages..." +sudo pacman -Syyu || error "Package syncronisation failed." FSTAB_SWAP_ENTRY="/swapfile none swap defaults 0 0" SWAP_FILE="/swapfile" FSTAB_FILE="/etc/fstab"