From 6fa36fc33b4f631f59f08e6aeeadfc74afbd8e1d Mon Sep 17 00:00:00 2001 From: Fierelier Date: Tue, 10 May 2022 22:53:09 +0200 Subject: [PATCH] Add error handling to make-os scripts --- make-os | 38 +++++++++++++++++++++++++------------- make-os-proprietary | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/make-os b/make-os index e0fe996..d304ea6 100755 --- a/make-os +++ b/make-os @@ -1,14 +1,26 @@ #!/usr/bin/env bash -if [ "$1" = "" ]; then - echo "Define i386/amd64 as the first argument." - exit 1 -fi -cd "$(dirname "$(realpath -s "$BASH_SOURCE")")" -source shell -source "env-$1" -make-base "$OPUS_OUTPUT/$1" "$OPUS_OUTPUT/$1" # Base image -apply-stage "$OPUS_HOME/input/stage01" "$OPUS_OUTPUT/$1" # Packages (non-graphical) -apply-stage "$OPUS_HOME/input/stage50" "$OPUS_OUTPUT/$1" # Packages (graphical) -apply-stage "$OPUS_HOME/input/stage98" "$OPUS_OUTPUT/$1" # Default configs, etc. -apply-stage "$OPUS_HOME/input/stage99" "$OPUS_OUTPUT/$1" # Disk image preparation -make-image "$OPUS_OUTPUT/$1" "$OPUS_OUTPUT/${OPUS_NAME}-${OPUS_DIST}-${OPUS_ARCH}_$(date "+%Y.%m.%d-%H.%M.%S").img" # Disk image \ No newline at end of file +set -e +if + if [ "$1" = "" ]; then + echo "Define i386/amd64 as the first argument." + exit 1 + fi + cd "$(dirname "$(realpath -s "$BASH_SOURCE")")" + source shell + source "env-$1" + make-base "$OPUS_OUTPUT/$1" "$OPUS_OUTPUT/$1" # Base image + apply-stage "$OPUS_HOME/input/stage01" "$OPUS_OUTPUT/$1" # Packages (non-graphical) + apply-stage "$OPUS_HOME/input/stage50" "$OPUS_OUTPUT/$1" # Packages (graphical) + apply-stage "$OPUS_HOME/input/stage98" "$OPUS_OUTPUT/$1" # Default configs, etc. + apply-stage "$OPUS_HOME/input/stage99" "$OPUS_OUTPUT/$1" # Disk image preparation + make-image "$OPUS_OUTPUT/$1" "$OPUS_OUTPUT/${OPUS_NAME}-${OPUS_DIST}-${OPUS_ARCH}_$(date "+%Y.%m.%d-%H.%M.%S").img" # Disk image +then + set +e +else + set +e + echo + echo Script execution ended due to error. Cleaning up... + fchroot-end "$OPUS_OUTPUT/$1" + rm -r "$OPUS_OUTPUT/$1" + echo Script execution ended due to error. +fi \ No newline at end of file diff --git a/make-os-proprietary b/make-os-proprietary index d7c4090..cd651e1 100755 --- a/make-os-proprietary +++ b/make-os-proprietary @@ -1,16 +1,28 @@ #!/usr/bin/env bash -if [ "$1" = "" ]; then - echo "Define i386/amd64 as the first argument." - exit 1 -fi -cd "$(dirname "$(realpath -s "$BASH_SOURCE")")" -source shell -source "env-$1" -source "env-proprietary" -make-base # Base image -apply-stage "$OPUS_HOME/input/stage01" "$OPUS_OUTPUT/$1" # Packages (non-graphical) -apply-stage "$OPUS_HOME/input/stage49" "$OPUS_OUTPUT/$1" # Packages (proprietary firmware) -apply-stage "$OPUS_HOME/input/stage50" "$OPUS_OUTPUT/$1" # Packages (graphical) -apply-stage "$OPUS_HOME/input/stage98" "$OPUS_OUTPUT/$1" # Default configs, etc. -apply-stage "$OPUS_HOME/input/stage99" "$OPUS_OUTPUT/$1" # Disk image preparation -make-image "$OPUS_OUTPUT/$1" "$OPUS_OUTPUT/${OPUS_NAME}-${OPUS_DIST}-${OPUS_ARCH}_$(date "+%Y.%m.%d-%H.%M.%S").img" # Disk image \ No newline at end of file +set -e +if + if [ "$1" = "" ]; then + echo "Define i386/amd64 as the first argument." + exit 1 + fi + cd "$(dirname "$(realpath -s "$BASH_SOURCE")")" + source shell + source "env-$1" + source "env-proprietary" + make-base # Base image + apply-stage "$OPUS_HOME/input/stage01" "$OPUS_OUTPUT/$1" # Packages (non-graphical) + apply-stage "$OPUS_HOME/input/stage49" "$OPUS_OUTPUT/$1" # Packages (proprietary firmware) + apply-stage "$OPUS_HOME/input/stage50" "$OPUS_OUTPUT/$1" # Packages (graphical) + apply-stage "$OPUS_HOME/input/stage98" "$OPUS_OUTPUT/$1" # Default configs, etc. + apply-stage "$OPUS_HOME/input/stage99" "$OPUS_OUTPUT/$1" # Disk image preparation + make-image "$OPUS_OUTPUT/$1" "$OPUS_OUTPUT/${OPUS_NAME}-${OPUS_DIST}-${OPUS_ARCH}_$(date "+%Y.%m.%d-%H.%M.%S").img" # Disk image +then + set +e +else + set +e + echo + echo Script execution ended due to error. Cleaning up... + fchroot-end "$OPUS_OUTPUT/$1" + rm -r "$OPUS_OUTPUT/$1" + echo Script execution ended due to error. +fi \ No newline at end of file