#!/bin/sh
#
#	Startmux - Kick off the netmux process.
#
PATH=/usr/ucb:/bin:/usr/bin:.; export PATH
#
. mux.config
#
#	Make sure there isn't already a MUX running.
#
if [ -r "$PIDFILE" ]; then
    oldpid=$(cat $PIDFILE)
    if [ "$oldpid" -gt 1 ]; then
        nmux=$(ps | grep $oldpid | grep netmux | wc -l)
        if [ "$nmux" -gt 0 ]; then
            echo "The MUX already seems to be running."
            exit 0
        fi
    fi
fi
#
#	Remove the restart db if there is one.
#
if [ -r restart.db ]; then
	rm restart.db
fi
#
#       Check if the log directory is defined and is valid. If not, use
#       the current directory.
#
if [ -z "$LOGDIR" -o ! -d "$LOGDIR" -o ! -x "$LOGDIR" ]; then
    if [ ! -z "$LOGDIR" ]; then
	echo "Log directory '$LOGDIR' is invalid, using game directory."
    fi
    LOGDIR=.
fi
#
#	Kick off MUX
#

# Linux/Solaris
LD_LIBRARY_PATH=$BIN
export LD_LIBRARY_PATH

# Mac OS X / NeXTStep / Mach
DYLD_LIBRARY_PATH=$BIN
export DYLD_LIBRARY_PATH

(nohup $BIN/netmux -c $GAMENAME.conf -p $PIDFILE -e $LOGDIR >/dev/null 2>&1 &)
