#!/bin/sh
# Shell script that starts up Jini

# Author:  Christopher Hylands
# Version: $Id: startjini,v 1.13 2005/02/28 20:53:33 cxh Exp $
#
# Copyright (c) 2000-2005 The Regents of the University of California.
# 	All Rights Reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in all
# copies of this software.
#
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
# FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
# ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
# THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
# PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
# CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
# ENHANCEMENTS, OR MODIFICATIONS.
#
# 						PT_COPYRIGHT_VERSION_2
# 						COPYRIGHTENDKEY

# Usage: startjini <JINI_DIR> <TMP_DIR>
# where the JINI_DIR argument is optional, and defaults to
# $PTII/vendors/sun/jini/jini1_0_1
# TMP_DIR argument is also optional, and should be c:\\tmp\\ under
# windows.  TMP_DIR should have the appropriate trailing directory
# separator, either / or \\

# Sometimes we seem to need to have d: in the PTII variable?
#PTII=d:/users/cxh/ptII


JINI_DIR_EXT=vendors/sun/jini/jini1_0_1

if [ $# -eq 1 ]; then
    JINI_DIR=$1
else
    JINI_DIR=$PTII/$JINI_DIR_EXT
fi

if [ ! -d $JINI_DIR ]; then
    echo "$0: '$JINI_DIR' does not exist or is not a directory?"
fi

# The httpd port to use.
PORT=4444

# Choose a temporary directory.
if [ $# -eq 2 ]; then
    TMP_DIR=$2
else
    case "${OSTYPE-no}" in
	cygwin*)
	    # On the PC, we need to have a drive path to make this directory
	    # absolute
	    dirs="c:\\tmp\\ c:\\temp\\ d:\\tmp\\ d:\\temp\\"
	    for TMP_DIR in $dirs
	    do
		if [ -d $TMP_DIR ]; then
		    echo "TMP_DIR = '$TMP_DIR'"
		    break
		fi
    	    done
	    ;;
	*)
	    TMP_DIR="/tmp/"
	    ;;
	esac
fi

# Be sure that the policy.all file exists
POLICY=$PTII/bin/policy.all
if [ ! -f $POLICY ]; then
    echo "$0: Warning, can't find '$POLICY'"
    exit 4
fi


echo "Starting httpd"
# You can add -verbose to the line below
# Deleted "-trees" to allow all subdirectories
java -jar $JINI_DIR/lib/tools.jar -port $PORT -dir $PTII -verbose &

sleep 2

echo "Starting rmid"
rm -rf ${TMP_DIR}rmid_log
rmid -log ${TMP_DIR}rmid_log -J-Djava.security.policy=$POLICY &

sleep 2

echo "Starting reggie"
rm -rf ${TMP_DIR}reggie_log
java -jar $JINI_DIR/lib/reggie.jar http://`hostname`:$PORT/$JINI_DIR_EXT/lib/reggie-dl.jar  $POLICY ${TMP_DIR}/reggie_log public &

sleep 2

echo "Starting txn"
rm -rf ${TMP_DIR}txn_log
java -jar -Djava.security.policy=$POLICY  -Dcom.sun.jini.mahalo.managerName=TransactionManager  $JINI_DIR/lib/mahalo.jar http://`hostname`:$PORT/$JINI_DIR_EXT/lib/mahalo-dl.jar   $POLICY ${TMP_DIR}txn_log public &

sleep 2

echo "Starting outrigger"
java -jar -Djava.security.policy=$PTII/bin/policy.all \
     -Djava.rmi.server.codebase=http://`hostname`:$PORT/$JINI_DIR_EXT/lib/outrigger-dl.jar \
     -Dcom.sun.jini.outrigger.spaceName=JavaSpaces \
     $JINI_DIR/lib/transient-outrigger.jar public &

# Just so that the output start to appear before we actually exit
sleep 5

echo "Ok, done"
