Skip to content

Instantly share code, notes, and snippets.

@mcd1992
Last active October 8, 2015 16:43
Show Gist options
  • Save mcd1992/efbf9db5fc3f2842e64c to your computer and use it in GitHub Desktop.
Save mcd1992/efbf9db5fc3f2842e64c to your computer and use it in GitHub Desktop.
Command line startup script for garrysmod on linux.
#!/bin/bash
# figure out the absolute path to the script being run a bit
# non-obvious, the ${0%/*} pulls the path out of $0, cd's into the
# specified directory, then uses $PWD to figure out where that
# directory lives - and all this in a subshell, so we don't affect
# $PWD
GAMEROOT=$(cd "${0%/*}" && echo $PWD)
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GAMEROOT/garrysmod/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.steam/bin32
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.steam/bin32/steam-runtime/i386/lib/i386-linux-gnu
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.steam/bin32/steam-runtime/i386/usr/lib/i386-linux-gnu
TARGET_LD_DEBUG=
#determine platform
UNAME=`uname`
if [ "$UNAME" == "Darwin" ]; then
# prepend our lib path to LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH="${GAMEROOT}"/bin:$DYLD_LIBRARY_PATH
elif [ "$UNAME" == "Linux" ]; then
# prepend our lib path to LD_LIBRARY_PATH
export LD_LIBRARY_PATH="${GAMEROOT}"/bin:$LD_LIBRARY_PATH
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
fi
if [ -z $GAMEEXE ]; then
if [ "$UNAME" == "Darwin" ]; then
GAMEEXE=hl2_osx
elif [ "$UNAME" == "Linux" ]; then
GAMEEXE=hl2_linux
fi
fi
ulimit -n 2048
# enable nVidia threaded optimizations
export __GL_THREADED_OPTIMIZATIONS=1
# and launch the game
cd "$GAMEROOT"
# Enable path match if we are running with loose files
if [ -f pathmatch.inf ]; then
export ENABLE_PATHMATCH=1
fi
# Do the following for strace:
# GAME_DEBUGGER="strace -f -o strace.log"
# Do the following for tcmalloc
# LD_PRELOAD=../src/thirdparty/gperftools-2.0/.libs/libtcmalloc_debug.so:$LD_PRELOAD
STATUS=42
while [ $STATUS -eq 42 ]; do
if [ "${GAME_DEBUGGER}" == "gdb" ] || [ "${GAME_DEBUGGER}" == "cgdb" ]; then
ARGSFILE=$(mktemp $USER.hl2.gdb.XXXX)
echo b main > "$ARGSFILE"
# Set the LD_PRELOAD varname in the debugger, and unset the global version. This makes it so that
# gameoverlayrenderer.so and the other preload objects aren't loaded in our debugger's process.
echo set env LD_PRELOAD=$LD_PRELOAD >> "$ARGSFILE"
echo show env LD_PRELOAD >> "$ARGSFILE"
unset LD_PRELOAD
echo set env LD_DEBUG=$TARGET_LD_DEBUG >> "$ARGSFILE"
echo run $@ >> "$ARGSFILE"
echo show args >> "$ARGSFILE"
${GAME_DEBUGGER} "${GAMEROOT}"/${GAMEEXE} -x "$ARGSFILE"
rm "$ARGSFILE"
else
${GAME_DEBUGGER} "${GAMEROOT}"/${GAMEEXE} "$@"
fi
STATUS=$?
done
exit $STATUS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment