fix: handle unexpected script termination

This commit is contained in:
GenZmeY 2021-02-08 23:31:59 +03:00
parent 25b1183585
commit 1322774da2

22
make.sh
View File

@ -3,6 +3,9 @@
# Requirements: git-bash # Requirements: git-bash
# https://git-scm.com/download/win # https://git-scm.com/download/win
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
function winpath2unix () # $1: win path function winpath2unix () # $1: win path
{ {
echo "$*" | \ echo "$*" | \
@ -39,6 +42,12 @@ function show_help ()
echo " -h, --help" echo " -h, --help"
} }
function cleanup()
{
trap - SIGINT SIGTERM ERR EXIT
restore_kfeditorconf
}
function get_latest_multini () function get_latest_multini ()
{ {
local ApiUrl="https://api.github.com/repos/GenZmeY/multini/releases/latest" local ApiUrl="https://api.github.com/repos/GenZmeY/multini/releases/latest"
@ -56,7 +65,9 @@ function backup_kfeditorconf ()
function restore_kfeditorconf () function restore_kfeditorconf ()
{ {
if [[ -f "$KFEditorConfBackup" ]]; then
mv -f "$KFEditorConfBackup" "$KFEditorConf" mv -f "$KFEditorConfBackup" "$KFEditorConf"
fi
} }
function setup_modpackages () function setup_modpackages ()
@ -66,6 +77,11 @@ function setup_modpackages ()
multini --set "$KFEditorConf" 'ModPackages' 'ModPackagesInPath' "$(unixpath2win "$MutSource")" multini --set "$KFEditorConf" 'ModPackages' 'ModPackagesInPath' "$(unixpath2win "$MutSource")"
} }
function compiled ()
{
test -f "$MutStructScript/ServerExt.u" && test -f "$MutStructScript/ServerExtMut.u"
}
function compile () function compile ()
{ {
if ! command -v multini &> /dev/null; then if ! command -v multini &> /dev/null; then
@ -88,8 +104,7 @@ function compile ()
local PID="$!" local PID="$!"
while ps -p "$PID" &> /dev/null while ps -p "$PID" &> /dev/null
do do
if [[ -e "$MutStructScript/ServerExt.u" ]] && if compiled ; then
[[ -e "$MutStructScript/ServerExtMut.u" ]]; then
kill "$PID"; break kill "$PID"; break
fi fi
sleep 2 sleep 2
@ -107,8 +122,7 @@ function brew ()
function brew_unpublished () function brew_unpublished ()
{ {
rm -rf "$MutPublish" rm -rf "$MutPublish"
if ! [[ -e "$MutStructScript/ServerExt.u" ]] || if ! compiled ; then
! [[ -e "$MutStructScript/ServerExtMut.u" ]]; then
compile compile
fi fi
cp -rf "$MutUnpublish" "$MutPublish" cp -rf "$MutUnpublish" "$MutPublish"