Last active
August 29, 2015 14:01
-
-
Save jorgenpt/35ded51f96cddad8190d to your computer and use it in GitHub Desktop.
steam-runtime launcher script for use outside of Steam
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Path relative to the directory where the executable lives. | |
JPT_STEAM_RUNTIME_LOCATION='steam-runtime' | |
# Figure out where this script lives. | |
exedir="$(cd "$(dirname "$0")" && pwd)" | |
# If this script is named `foo.sh' or `foo', we execute `foo.bin' | |
exename="$(basename "$0" ".sh").bin" | |
if [ "$1" == "--check-program" ]; then | |
exec "$exedir/$JPT_STEAM_RUNTIME_LOCATION/scripts/check-program.sh" "$exedir/$exename" | |
fi | |
# If the steam runtime is not already configured, re-exec ourself with | |
# the steam-runtime we expect to find in $JPT_STEAM_RUNTIME_LOCATION. | |
if [ -z "$STEAM_RUNTIME" ]; then | |
if [ ! -z "$JPT_ATTEMPTED_REEXEC" ]; then | |
echo "ERROR: Reexecuted in runtime, but STEAM_RUNTIME is unset!" >&2 | |
exit 1 | |
fi | |
export JPT_ATTEMPTED_REEXEC=1 | |
exec "$exedir/$JPT_STEAM_RUNTIME_LOCATION/run.sh" "$0" "$@" | |
fi | |
# We support launching with --gdb to load the executable inside gdb, | |
# setting up the steam-runtime environment for the debugged process. | |
if [ "$1" == "--gdb" ]; then | |
shift | |
# Don't force GDB to load things from LD_LIBRARY_PATH, but instruct it to | |
# tell the inferior process that it should. | |
argsfile="$(mktemp $USER.$exename.gdb.XXXX)" | |
echo set env LD_LIBRARY_PATH=$LD_LIBRARY_PATH >> "$argsfile" | |
echo show env LD_LIBRARY_PATH >> "$argsfile" | |
unset LD_LIBRARY_PATH | |
gdb -x "$argsfile" --args "$exedir/$exename" "$@" | |
exitcode=$? | |
rm "$argsfile" | |
exit $exitcode | |
else | |
"$exedir/$exename" "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment