#!/bin/sh
# bin/rmiclient -- an ITISSL program
# ITISSL - a Java 2 implementation for  Sun's reference SSL API  using SSLeay
# Copyright (C) 1999 Andrei Popovici (apopovic@iti.informatik.tu-darmstadt.de)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

# $Id: java-wrapper.sh,v 1.2 1999/02/21 14:13:34 apopovic Exp $
#----------------------------------------------------------------------

#
# itissl startup wrapper for class
#    de.tu_darmstadt.sp.example.RMIClient
#
# (history at end)


usage()
{
  cat <<EOF

   `basename $0` [<options>] [<class opts>] [<args>]

Options are:

   -R <rmi-url>			RMI-Registry to connect to
   -D <prop>=<value>		define system property
   -d				allow attaching jdb
   -L				log RMI calls to stderr
   -J <opt>			pass option to Java VM
   -h				show usage

If set, the value of environment variable RMIREGISTRY will be
interpreted as option -R.
EOF
}

## --------------------------------------------------
## determine location of class files and libraries
## --------------------------------------------------

bindir=`dirname $0`
if [ -d "$bindir/../classes" ];
    then

    # iti or distribution, uninstalled
    CLASSPATH="${CLASSPATH+$CLASSPATH:}$bindir/../classes";
    LD_LIBRARY_PATH="${LD_LIBRARY_PATH+$LD_LIBRARY_PATH:}$bindir/../lib";


    else
  # iti or distribution, installed

    if [ -d $bindir/../config ]
    then
        #iti package
	CLASSPATH="${CLASSPATH+$CLASSPATH:}$bindir/../lib/itissl/lib/itissl.jar";
        LD_LIBRARY_PATH="${LD_LIBRARY_PATH+$LD_LIBRARY_PATH:}$bindir/../jni/${SYS_PLATFORM}/native_threads:$bindir/../jni/${SYS_PLATFORM}/green_threads";
    # else
        #ext package
	# do nothing, we're an extension..
    fi;

fi

export CLASSPATH
export LD_LIBRARY_PATH

## --------------------------------------------------
## parse our own options..
## --------------------------------------------------


unset java_args
unset sum

java=java


# parse options

while [ $# -gt 0 ]
do

  case "$1" in

    -R)
	java_args="$java_args -Diti.spooler.registry=$2"
	shift
	;;

    -D)
	java_args="$java_args -D$2"
	shift
	;;

    -D*)
	java_args="$java_args $1"
	;;

    -J)
	java_args="$java_args $2"
	shift
	;;

    -J*)
	java_args="$java_args `expr $1 : '-J\(.*\)'`"
	;;

    -L)
	java_args="$java_args -Djava.rmi.server.logCalls=true"
	;;

    -d)
	java="java_g -debug"
	;;

    -sum)
        sum="-sum";
	;;

    -h)
        # do not exit here, allow class to show more usage info
	usage
	break
	;;

    *)
	break
	;;
  esac

  shift
done

## --------------------------------------------------
## Determine location for certs and keys
## --------------------------------------------------

PATH="${PATH+$PATH:}$bindir:$bindir/../utils"
export PATH

CERT_FILE=`sfindcerts -cert`
export CERT_FILE

KEY_FILE=`sfindcerts -key`
export KEY_FILE

CA_FILE=`sfindcerts -ca $sum`
export CA_FILE

if [ $sum ]
then
    trap "rm -f $CA_FILE" 0 1 2 3 15
fi


## --------------------------------------------------
## Call java application
## --------------------------------------------------
# set registry, if specified
test "$rmiregistry" && java_args="$java_args $rmiregistry"

# run Java interpreter on main class file
exec $java $java_args de.tu_darmstadt.sp.example.RMIClient ${1+"$@"}


#======================================================================
#
# $Log: java-wrapper.sh,v $
# Revision 1.2  1999/02/21 14:13:34  apopovic
# sh syntax bug fixed
#
# Revision 1.1  1999/02/01 14:01:00  apopovic
# Intial Revision
#
#
