#!/bin/sh
trap '/bin/rm /tmp/core 2> /dev/null; exit 1' 0 1 2 3 15
HOST=`/bin/hostname`
RHOST=`who am i|sed -e 's/.*(//' -e 's/)//' -e 's/:.*$//' -e 's/\.[Bb]erk.*//'`
DISPLAY=$RHOST:0.0
if ps -auxww | grep sun4/picasso | grep -v grep > /dev/null
then
   echo "There is already a picasso running on this machine."
   echo "Please try another machine. For example:"
   echo '	zonker.berkeley.edu (128.32.149.52)'
   echo '	linus.berkeley.edu (128.32.149.59)'
   echo '	woodstock.berkeley.edu (128.32.149.56)'
   echo '	elmer-fudd.berkeley.edu (128.32.149.61)'
   exit 2
fi
finished=0
while [ $finished -eq 0 ]
do
    echo -n "Enter the name of your display (default is $RHOST:0.0): "
    read DPY
    if [ $DPY ]
    then 
	DISPLAY=$DPY
    else
	DISPLAY=$RHOST:0.0
    fi
    if /usr/bin/X11/xdpyinfo -display $DISPLAY > /dev/null 2>&1
    then 
	finished=1
    else
	echo "Error connecting to display \"$DISPLAY\"."
	echo "Please make sure $HOSTNAME is xhosted and re-enter."
	echo ""
    fi
done
export DISPLAY

while true
do
    echo ""
    echo "Which demo would you like to run?"
    echo "	1) Demo tool from picasso paper."
    echo "	2) CIM database browser tool."
    echo "	3) Video Poker"
    echo "	4) Mosaic"
    echo "	5) Exit"
    echo -n "> "
    read program
    case $program in
	    1) echo "(paper)" | $PICASSOHOME/bin/new-picasso ;;
	    2) echo "(cimtool)" | $PICASSOHOME/bin/new-picasso ;;
	    3) echo "(vp)" | $PICASSOHOME/bin/new-picasso ;;
	    4) echo "(mosaic)" | $PICASSOHOME/bin/new-picasso ;;
	    5) exit 0 ;;
	    *) echo "Error: please enter an option (1) - (5)"
    esac
done
