#!/bin/ksh -p
#
# ident "@(#)bbstartd.sh	1.11 02/06/06 SMI"
#
# Copyright 2000-2002 Sun Microsystems, Inc.  All rights reserved.
#
# this script runs as a per user service deamon outside
# the chroot env to up/down load user data on behalf of
# the user and to restart the browser.
# parameters: $1 - door path

. $BBROOT/etc/opt/SUNWbb/blackbox.rc 

PATH=$BBPATH/bin:/bin

DOOR=$1
DISPLAY=$BBDISPLAY; export DISPLAY

export LC_ALL=$BB_KIOSK_LANG
export LANG=$BB_KIOSK_LANG

eat_options () {

	arglist=""
	for a in $*; do
                [[ $a != -* ]] && arglist="$arglist $a"
        done
	echo $arglist
}

while [ -f $BBLOCKPATH/$BBUSER.lock ]; do

	cmd=""
        arglist=""   
	read args < $DOOR
	if [ "$args" = "" ]; then
		continue;
	fi
	[[ $args != -* ]] && { 
		set $args
	
		if [ -z $cmd ]; then
			cmd=$1
			shift
		fi
		case $cmd in
			"prtdlg")
				if [ -x $BBPATH/bin/bblp ]; then
					$BBPATH/bin/bblp -r $BBROOTPATH/$1 &
				fi
				;;
			"prtlist")
				if [ -x $BBPATH/bin/bblp ]; then
					$BBPATH/bin/bblp -l &
				fi
				;;
			"createsummary")
				if [ -x $BBPATH/monitoring/bin/bbcreatesummary ]; then
					$BBPATH/monitoring/bin/bbcreatesummary &
				fi
				;;
			"browser")  
				if [ -x $BBPATH/bin/bbstartbrowser ]; then  
					$BBPATH/bin/bblock -n \
        					$BROWSER_LOCK \
        					$BBPATH/bin/bbstartbrowser &         
				fi
				;;
			"rm")
				args=`eat_options $*`
				for f in "$args"; do
					dname=`dirname $f`
                                	if [ $dname = "/tmp" -o \
				     	     $dname = "/var/tmp" -o \
				     	     $dname = "/home/$BBUSER/tmp" ]; then
						rm -f $BBROOTPATH/$f
					fi
				done
				;;
			"remote")
                        	if [ -x $BBPATH/bin/bbremotebrowser ]; then
                                	$BBPATH/bin/bbremotebrowser $2 &
                        	fi
                        	;;
			"exit")
				if [ -x $BBPATH/bin/bbexitwebtop ]; then
					$BBPATH/bin/bbexitwebtop 
				else
					echo "can't find: bbexitwebtop"
				fi
				;; 
			*) 
				;;
		esac
	}
done
