From 904a144c2b8cf849082abcfbfc13b9e0f30a9ff9 Mon Sep 17 00:00:00 2001 From: Charadon Date: Fri, 23 Sep 2022 19:19:30 -0400 Subject: Added trap to automatically remove tmpfiles, and also made it so it tries to put the tmpfiles in the current directory first --- src/launch.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/launch.sh b/src/launch.sh index 01f56c2..467bd26 100644 --- a/src/launch.sh +++ b/src/launch.sh @@ -2,6 +2,7 @@ # Launch script for unix systems, loads bundled libraries if there are any. EXIT_STATUS=0 +TMPDIR=${TMPDIR:-/tmp} failed() { zenity --error --text="The program appears to not have closed correctly. Please check output.log to see details." @@ -9,7 +10,6 @@ failed() { } run_game() { - cd "$(dirname "$0")" || return 1 PAYLOAD_LINE="$(awk '/^__PAYLOAD_BEGINS__/ { print NR + 1; exit 0; }' "$0")" || return 1 tail -n +"${PAYLOAD_LINE}" "$0" | xz -d > "$TMPFILE" || return 1 chmod +x "$TMPFILE" || return 1 @@ -17,13 +17,17 @@ run_game() { return 0 } -TMPDIR=/tmp -TMPFILE="$(mktemp /tmp/Pong-XXXXXXXXXXXXXXXXXXXXX)" +cd "$(dirname "$0")" || exit 1 +trap '{ rm -rf "$TMPFILE"; }' EXIT +if ! TMPFILE="./$(mktemp .Pong-XXXXXX)"; +then + echo "Can't extract Pong binary to current directory. Trying $TMPDIR" + TMPFILE="$(mktemp "$TMPDIR"/Pong-XXXXXX)" +fi if ! run_game; then failed fi -rm "$TMPFILE" exit "$EXIT_STATUS" __PAYLOAD_BEGINS__ -- cgit 1.4.1-2-gfad0