#! /bin/bash

##############################################################################
#
#    file                 : torcs
#    created              : Sat Sep 11 20:20:04 CEST 1999
#    copyright            : (C) 1999 by Eric Espie                         
#    email                : torcs@free.fr   
#    version              : $Id: torcs.in,v 1.8 2003/03/29 14:32:47 torcs Exp $                                  
#
##############################################################################
#
#   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.
#
##############################################################################

DEFAULT_RUNTIME=/usr/share/games/torcs

LOCAL_CONF=$HOME/.torcs

prefix=/usr
exec_prefix=/usr

[ -f "$DEFAULT_RUNTIME/playavi.sh" ] && sh $DEFAULT_RUNTIME/playavi.sh > /dev/null 2>&1

if [ -d $DEFAULT_RUNTIME ]
then
    if [ ! -d $LOCAL_CONF ]
    then
	rm -rf $LOCAL_CONF
	mkdir -p $LOCAL_CONF
	echo "$LOCAL_CONF created, copying/linking game data"
    fi
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib
    cd $DEFAULT_RUNTIME
    if [ -f ./setup_linux.sh ]
    then
	/bin/bash ./setup_linux.sh $LOCAL_CONF
	if [ $? -ne 0 ]
	then
	    exit 1
	fi
    else
	echo "$DEFAULT_RUNTIME/setup_linux.sh file does not exist, check your installation"
	exit 1
    fi
    ./torcs -l $LOCAL_CONF $*
    exit 0
fi

echo "TORCS location not found"
	
	
