about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCharadon <dev@iotib.net>2022-09-23 17:26:58 -0400
committerCharadon <dev@iotib.net>2022-09-23 17:26:58 -0400
commit30048da167dd864e30296b5f27e3676a302669a3 (patch)
treee3fcd91e14f37d25406bd213819815d9c7f44e14
parentecf9374e3e75d6528afb44f013432844d5fc01dd (diff)
downloadPong-C-30048da167dd864e30296b5f27e3676a302669a3.tar.gz
Combined launch script and binary to make it easier to launch game.
-rwxr-xr-xinstall.sh10
-rw-r--r--src/launch.sh30
2 files changed, 33 insertions, 7 deletions
diff --git a/install.sh b/install.sh
index 8c61578..564e708 100755
--- a/install.sh
+++ b/install.sh
@@ -16,8 +16,14 @@ set -x
 mkdir -p $CONFIG_INSTALL_PREFIX
 cp -r resources $CONFIG_INSTALL_PREFIX/
 cp -r docs $CONFIG_INSTALL_PREFIX/
-install -m755 $CONFIG_BUILD_DIR/bin/Pong* $CONFIG_INSTALL_PREFIX/
-install -m755 src/launch.sh $CONFIG_INSTALL_PREFIX/launch_pong
+
+if [ "$(uname -s)" = "MINGW*" ];
+then
+	cp $CONFIG_BUILD_DIR/bin/Pong* $CONFIG_INSTALL_PREFIX/
+else
+	install -m755 src/launch.sh $CONFIG_INSTALL_PREFIX/Pong.run
+	cat $CONFIG_BUILD_DIR/bin/Pong* | xz -9 -c >> $CONFIG_INSTALL_PREFIX/Pong.run
+fi
 
 if [ "$CONFIG_FLATPAK" = "true" ];
 then
diff --git a/src/launch.sh b/src/launch.sh
index 7f8fd82..01f56c2 100644
--- a/src/launch.sh
+++ b/src/launch.sh
@@ -1,9 +1,29 @@
-#!/bin/sh
+#!/bin/sh -xeu
 # Launch script for unix systems, loads bundled libraries if there are any.
 
-cd "$(dirname $0)"
-DYLD_LIBRARY_PATH=libs/ LD_LIBARY_PATH=libs/ ./Pong > output.log 2>&1
-if [ ! $? = "0" ];
-then
+EXIT_STATUS=0
+
+failed() {
 	zenity --error --text="The program appears to not have closed correctly. Please check output.log to see details."
+	EXIT_STATUS=1
+}
+
+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
+	DYLD_LIBRARY_PATH=libs/ LD_LIBARY_PATH=libs/ "$TMPFILE" > output.log 2>&1 || return 1
+	return 0
+}
+
+TMPDIR=/tmp
+TMPFILE="$(mktemp /tmp/Pong-XXXXXXXXXXXXXXXXXXXXX)"
+
+if ! run_game;
+then
+	failed
 fi
+rm "$TMPFILE"
+exit "$EXIT_STATUS"
+__PAYLOAD_BEGINS__