/ hl.sh
hl.sh
1 #!/bin/bash 2 3 # figure out the absolute path to the script being run a bit 4 # non-obvious, the ${0%/*} pulls the path out of $0, cd's into the 5 # specified directory, then uses $PWD to figure out where that 6 # directory lives - and all this in a subshell, so we don't affect 7 # $PWD 8 9 GAMEROOT=$(cd "${0%/*}" && echo $PWD) 10 11 #determine platform 12 UNAME=`uname` 13 if [ "$UNAME" == "Darwin" ]; then 14 # Workaround OS X El Capitan 10.11 System Integrity Protection (SIP) which does not allow 15 # DYLD_INSERT_LIBRARIES to be set for system processes. 16 if [ "$STEAM_DYLD_INSERT_LIBRARIES" != "" ] && [ "$DYLD_INSERT_LIBRARIES" == "" ]; then 17 export DYLD_INSERT_LIBRARIES="$STEAM_DYLD_INSERT_LIBRARIES" 18 fi 19 # prepend our lib path to LD_LIBRARY_PATH 20 export DYLD_LIBRARY_PATH="${GAMEROOT}":$DYLD_LIBRARY_PATH 21 elif [ "$UNAME" == "Linux" ]; then 22 # prepend our lib path to LD_LIBRARY_PATH 23 export LD_LIBRARY_PATH="${GAMEROOT}":$LD_LIBRARY_PATH 24 fi 25 26 if [ -z $GAMEEXE ]; then 27 if [ "$UNAME" == "Darwin" ]; then 28 GAMEEXE=hl_osx 29 elif [ "$UNAME" == "Linux" ]; then 30 GAMEEXE=hl_linux 31 fi 32 fi 33 34 ulimit -n 2048 35 36 # and launch the game 37 cd "$GAMEROOT" 38 39 STATUS=42 40 while [ $STATUS -eq 42 ]; do 41 if [ "${DEBUGGER}" == "gdb" ] || [ "${DEBUGGER}" == "cgdb" ]; then 42 ARGSFILE=$(mktemp $USER.hl.gdb.XXXX) 43 44 # Set the LD_PRELOAD varname in the debugger, and unset the global version. 45 : "${LD_PRELOAD=}" 46 if [ "$LD_PRELOAD" ]; then 47 echo set env LD_PRELOAD=$LD_PRELOAD >> "$ARGSFILE" 48 echo show env LD_PRELOAD >> "$ARGSFILE" 49 unset LD_PRELOAD 50 fi 51 52 # Ditto with LD_LIBRARY_PATH, avoids this below: 53 # gdb: /home/plagman/src/valve/Steam/main/client/ubuntu12_32/steam-runtime/pinned_libs_64/libcurl.so.4: version `CURL_OPENSSL_4' not found (required by /usr/lib/libdebuginfod.so.1) 54 : "${LD_LIBRARY_PATH=}" 55 if [ "$LD_LIBRARY_PATH" ]; then 56 echo set env LD_LIBRARY_PATH=$LD_LIBRARY_PATH >> "$ARGSFILE" 57 echo show env LD_LIBRARY_PATH >> "$ARGSFILE" 58 unset LD_LIBRARY_PATH 59 fi 60 61 echo set print pretty on >> "$ARGSFILE" 62 echo set breakpoint pending on >> "$ARGSFILE" 63 echo set confirm off >> "$ARGSFILE" 64 65 # Append your own args file with optional DEBUGGER_ARGS ("-x /home/<me>/myargs.gdb") 66 : "${DEBUGGER_ARGS=}" 67 echo "gdb/cgdb launch:" 68 echo $DEBUGGER -x "$ARGSFILE" $DEBUGGER_ARGS --args "${GAMEROOT}/${GAMEEXE}" "$@" 69 70 $DEBUGGER -x "$ARGSFILE" $DEBUGGER_ARGS --args "${GAMEROOT}/${GAMEEXE}" "$@" 71 72 rm "$ARGSFILE" 73 elif [ "${DEBUGGER}" == "lldb" ]; then 74 ARGSFILE=$(mktemp $USER.hl.lldb.XXXX) 75 echo "b main" > "$ARGSFILE" 76 echo "env DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH" > "$ARGSFILE" 77 ${DEBUGGER} -s "$ARGSFILE" -- "${GAMEROOT}"/${GAMEEXE} "$@" 78 rm $ARGSFILE 79 else 80 ${DEBUGGER} "${GAMEROOT}"/${GAMEEXE} "$@" 81 fi 82 STATUS=$? 83 done 84 exit $STATUS