#!/bin/sh
#
#  This file is part of warsow Debian package.
#
#  Copyright (C) 2006 Gonéri Le Bouder
#
#  Author: Gonéri Le Bouder <goneri@rulezlan.org>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

PARAMS="+set fs_basepath /usr/share/games/warsow +set fs_usehomedir 1"
HELP="\
Warsow client wrapper\n\
This script is Debian specific, it is *NOT* part of the source distribution!\n\
Usage: warsow [OPTION] [+<internal command> <option> [<value>]] ...\n\
\n\
 -h, --help              Display this text\n\
 +<internal command> ... Pass engine commands to the binary\n"

QUIET=0

# Our options
case "$1" in
    -h|--help)
        echo -e ${HELP}
        exit 1
        ;;
    -q|--quiet)
        QUIET=1
        shift
        ;;
esac

# Find what Mesa version we're using.
MESA_VERSION=$(glxinfo | grep 'OpenGL version string:' | sed 's/OpenGL version string:\s//' | cut -d ' ' -f 3)

# Test if it's less than 7.2
VERSION_TEST=$(echo $MESA_VERSION | awk '{ if ($1 < 7.2) print "1"; else print "0" }' )

# Disable GLSL if we're using Mesa version less than 7.2
if [ $VERSION_TEST ]; then
    PARAMS="$PARAMS +set gl_ext_GLSL 0"
    if [ -z $QUIET ]; then
        echo "We're using Mesa version less than 7.2, disabling GLSL."
    fi
fi

if [ -z $QUIET ]; then
    exec /usr/lib/games/warsow/warsow_bin $PARAMS "$@" >/dev/null 2>&1
else
    exec /usr/lib/games/warsow/warsow_bin $PARAMS "$@"
fi
