#!/bin/sh

DPSELF=nexuiz
# "server" or "client"
DPROLE=client
# darkplaces or darkplaces-server
DPBINARY=darkplaces

ENGINE="/usr/games/${DPBINARY}"

DEBUGGER="$NEXUIZ_DEBUGGER"

OPTIONS="-nexuiz -basedir /usr/share/games/nexuiz"

QUIET=0

EXCUSE="\
Nexuiz Classic ${DPROLE} wrapper for Debian\n\
\n\
Usage: ${DPSELF} [OPTION]...\n\
\n\
 -h, --help\t\tDisplay this help\n\
 <engine option>\tPass options to the engine\n\
 +<console command>\tPass commands to the engine\n"

while [ "$1" != "" ]; do
  case "$1" in
    -h|--help)
      echo ${EXCUSE}
      exit 0
      ;;
    *)
      break
      ;;
  esac
  shift
done

if test "z$QUIET" = z1; then
  exec >/dev/null 2>&1;
fi

if test -n "$NEXUIZ_BACKTRACE"; then
  exec gdb -return-child-result -batch -ex run -ex 'thread apply all bt full' -ex kill -ex quit --args ${ENGINE} ${OPTIONS} "$@"
else
  exec ${DEBUGGER} ${ENGINE} ${OPTIONS} "$@"
fi
