#!/bin/sh
# Start script for rtd
#
# "@(#) $Id: rtd.in,v 1.1.1.1 2009/03/31 14:11:52 cguirao Exp $"
#
# who         when       what
# --------   ---------   ----------------------------------------------
# A.Brighton 28 Jan 06   created
# pbiereic   29/12/08    ignore error output from 'ps -x'

# Determine rtd base dir, following any symbolic links, if needed.
PRG="$0"
cwd=`pwd`
cd `dirname "$PRG"`
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"`/..
RTD_BASE=`(cd $DIR; pwd)`
cd $cwd

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

# Make sure we can find the shared libs
@LD_LIBRARY_PATH_VAR@="$RTD_BASE/lib:@BLT_LIB_DIR@:${@LD_LIBRARY_PATH_VAR@}"
export @LD_LIBRARY_PATH_VAR@

# and the Tcl packages
TCLLIBPATH="$RTD_BASE/lib"
export TCLLIBPATH

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

test -d $HOME/.rtd || mkdir $HOME/.rtd
exec wish8.4 $RTD_BASE/lib/rtd@PACKAGE_VERSION@/main.tcl ${1+"$@"} | tee $HOME/.skycat/log 2>&1

