Unify traps in bootstrap scripts to avoid confusion

This commit is contained in:
Kristóf Tóth 2018-05-02 18:16:42 +02:00
parent 9ec0132e06
commit a440c2d1cb
1 changed files with 10 additions and 2 deletions

View File

@ -18,8 +18,7 @@ LOGFILE=/tmp/bootstrap_tfw.log
run()
{
trap 'err_cleanup; showlog' ERR
trap cleanlog EXIT
trap handle_exit EXIT
: > $LOGFILE
check_dependencies
@ -37,6 +36,15 @@ run()
echo "You can build & start TFW by executing the command: ${TEST}/hack/tfw.sh start"
}
handle_exit()
{
if [[ $? -ne 0 ]]; then
err_cleanup
showlog
fi
cleanlog
}
showlog() { echo && echo "Error! Showing logs:" && cat $LOGFILE; }
cleanlog() { rm $LOGFILE; }
err_cleanup() { cd "$BASEDIR" && rm -rf "$BASEIMAGE" "$FRONTEND" "$TEST"; }