#!/bin/sh
#
# cod4_lnxded startup script
#

# Function to find the real directory a program resides in.
# Feb. 17, 2000 - Sam Lantinga, Loki Entertainment Software
FindPath()
{
    fullpath="`echo $1 | grep /`"
    if [ "$fullpath" = "" ]; then
        oIFS="$IFS"
        IFS=:
        for path in $PATH
        do if [ -x "$path/$1" ]; then
               if [ "$path" = "" ]; then
                   path="."
               fi
               fullpath="$path/$1"
               break
           fi
        done
        IFS="$oIFS"
    fi
    if [ "$fullpath" = "" ]; then
        fullpath="$1"
    fi

    # Is the sed/ls magic portable?
    if [ -L "$fullpath" ]; then
        #fullpath="`ls -l "$fullpath" | awk '{print $11}'`"
        fullpath=`ls -l "$fullpath" |sed -e 's/.* -> //' |sed -e 's/\*//'`
    fi
    dirname $fullpath
}

# Set the home if not already set.
if [ "${COD4_DATA_PATH}" = "" ]; then
    COD4_DATA_PATH="`FindPath $0`/"
fi

LD_LIBRARY_PATH=.:${COD4_DATA_PATH}:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH

# Let's boogie!
if [ -x "${COD4_DATA_PATH}/cod4_lnxded-bin" ]
then
	cd "${COD4_DATA_PATH}/"
	exec "./cod4_lnxded-bin" $*
fi
echo "Couldn't run Call of Duty 4 server (cod4_lnxded-bin). Is COD4_DATA_PATH set?"
exit 1

# end of cod4_lnxded ...

