From 1322774da2a5cd4891a1232b4d6bf8814948954d Mon Sep 17 00:00:00 2001 From: GenZmeY Date: Mon, 8 Feb 2021 23:31:59 +0300 Subject: [PATCH] fix: handle unexpected script termination --- make.sh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/make.sh b/make.sh index 96bf776..a006329 100644 --- a/make.sh +++ b/make.sh @@ -3,6 +3,9 @@ # Requirements: git-bash # https://git-scm.com/download/win +set -Eeuo pipefail +trap cleanup SIGINT SIGTERM ERR EXIT + function winpath2unix () # $1: win path { echo "$*" | \ @@ -39,6 +42,12 @@ function show_help () echo " -h, --help" } +function cleanup() +{ + trap - SIGINT SIGTERM ERR EXIT + restore_kfeditorconf +} + function get_latest_multini () { local ApiUrl="https://api.github.com/repos/GenZmeY/multini/releases/latest" @@ -56,7 +65,9 @@ function backup_kfeditorconf () function restore_kfeditorconf () { - mv -f "$KFEditorConfBackup" "$KFEditorConf" + if [[ -f "$KFEditorConfBackup" ]]; then + mv -f "$KFEditorConfBackup" "$KFEditorConf" + fi } function setup_modpackages () @@ -66,6 +77,11 @@ function setup_modpackages () multini --set "$KFEditorConf" 'ModPackages' 'ModPackagesInPath' "$(unixpath2win "$MutSource")" } +function compiled () +{ + test -f "$MutStructScript/ServerExt.u" && test -f "$MutStructScript/ServerExtMut.u" +} + function compile () { if ! command -v multini &> /dev/null; then @@ -88,8 +104,7 @@ function compile () local PID="$!" while ps -p "$PID" &> /dev/null do - if [[ -e "$MutStructScript/ServerExt.u" ]] && - [[ -e "$MutStructScript/ServerExtMut.u" ]]; then + if compiled ; then kill "$PID"; break fi sleep 2 @@ -107,8 +122,7 @@ function brew () function brew_unpublished () { rm -rf "$MutPublish" - if ! [[ -e "$MutStructScript/ServerExt.u" ]] || - ! [[ -e "$MutStructScript/ServerExtMut.u" ]]; then + if ! compiled ; then compile fi cp -rf "$MutUnpublish" "$MutPublish"