diff options
author | Charadon <dev@iotib.net> | 2022-09-23 19:19:30 -0400 |
---|---|---|
committer | Charadon <dev@iotib.net> | 2022-09-23 19:19:30 -0400 |
commit | 904a144c2b8cf849082abcfbfc13b9e0f30a9ff9 (patch) | |
tree | e1600640a348d313d5322d36ea075c7a908de065 /src/launch.sh | |
parent | 30048da167dd864e30296b5f27e3676a302669a3 (diff) | |
download | Pong-C-904a144c2b8cf849082abcfbfc13b9e0f30a9ff9.tar.gz |
Added trap to automatically remove tmpfiles, and also made it so it tries to put the tmpfiles in the current directory first
Diffstat (limited to 'src/launch.sh')
-rw-r--r-- | src/launch.sh | 12 |
1 files changed, 8 insertions, 4 deletions
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__ |