#!/bin/sh
# Start script for skycat
#
# "@(#) $Id: skycat.in,v 1.1.1.1 2009/03/31 14:11:52 cguirao Exp $"
#
# who         when       what
# --------   ---------   ----------------------------------------------
# A.Brighton 28 Jan 06   created

# Determine skycat base dir, following any symbolic links, if needed.
PRG="$0"
while [ -h "$PRG" ]; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '/.*' > /dev/null; then
        PRG="$link"
    else
        PRG=`dirname "$PRG"`/"$link"
    fi
done
DIR=`dirname "$PRG"`/..
SKYCAT_BASE=`(cd $DIR; pwd)`

# If we're NOT ssh'd in
if [ ! "${SSH_TTY}" ]; then
    # make sure X is running (on Mac OS X)
    if [ `uname` = "Darwin" ] ; then
	if [ "`ps -x | awk '{print $5}' | grep X11`" = "" ]; then
	    for i in /Applications/Utilities $HOME/Desktop ; do
		if [ -e $i/X11.app ] ; then
		    open $i/X11.app &
		    break
		fi
	    done
	fi
    fi
    # Make sure DISPLAY is set
    if [ x${DISPLAY} = x ]; then
	export DISPLAY=:0
    fi
fi

# Make sure we can find the Tcl packages
TCLLIBPATH="/usr/lib/skycat /usr/share/skycat"
export TCLLIBPATH

# Make sure we start the correct wish binary
PATH=$SKYCAT_BASE/bin:$PATH
export PATH

test -d $HOME/.skycat || mkdir $HOME/.skycat
echo "`date`: Starting skycat with: $0 ${1+"$@"}" > $HOME/.skycat/log
exec wish8.6 /usr/share/skycat/skycat3.1.2/main.tcl ${1+"$@"} | tee -a $HOME/.skycat/log 2>&1

