#!/bin/sh

# **** Set the following items for your system ****
JDK_HOME=/usr/lib/j2se/1.4/jre
JINI_HOME=/usr/java/jini2_0_002
HOSTNAME='box1'
EXAMPLE_HOME=$JINI_HOME
#EXAMPLE_HOME=$HOME/src

# -----------------------------------------------------------------------------
# ***                           *** NOTE ***
# *** If the code contained in either phoenix-dl.jar or browser-dl.jar is 
# *** changed, then the message digest used to build the codebase for Phoenix
# *** or the Browser (respectively) when running under secure Jini ERI/jsse
# *** must be re-computed, and the (HTTPMD) codebase or Phoenix or the Browser 
# *** must be re-built using the value of that new message digest string.
# ***
# *** Note that because the ServiceStarter framework can be used to start
# *** Phoenix, that message digest can be computed (on-the-fly) in the
# *** ServiceStarter configuration file for Phoenix (start-phoenix.config).
# *** In that case, it's not necessary to take any additional steps with
# *** repsect to computing the message digest for Phoenix. But because
# *** the ServiceStarter framework cannot currently be used to stop Phoenix,
# *** nor can it be used to start the Browser, the message digest must be
# *** supplied directly to the command line when either stopping Phoenix
# *** starting the Browser. Thus, for the case where this script is used to
# *** stop Phoenix or to start the Browser, the message digest is computed
# *** as shown below in the related if-block, and then passed as an
# *** argument to the appropriate start script.
# ***
# *** Note that unlike Windows, the command language of the various unix
# *** shells allow for the execution, and automatic substitution of the
# *** results of, other commands and scripts. This capability is exploited
# *** below to automatically re-compute the message digest for Phoenix or
# *** the Browser whenever needed. But if you wish to re-compute the
# *** value of that message digest yourself, you can either execute the
# *** tool com.sun.jini.tool.ComputeDigest (which is what is done in this
# *** script), or run the script computeHttpmdCodebase, which actually
# *** re-builds the codebase containing the re-computed message digest
# *** value.
# ***
# *** Note also that both this script and the computeHttpmdCodebase script
# *** assume that the 'sha' algorithm is used, rather than the 'md5'
# *** algorithm.
# -----------------------------------------------------------------------------

PROGRAM_NAME=$0

# -----------------------------------------------------------------------------
# begin parseArgs
USAGE="usage: $PROGRAM_NAME <scriptID> [-usage] [-help] [-port port] [-dir dir] [-stop] [-debug]"

ARG_LIST="-port -dir"

# set some defaults
STOP=start
START_TYPE=oneservice
SCRIPT_BASE=notset
SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp

SERVICE_NAME=reggie
INTERFACE_NAME=Registrar
IMPL_NAME=TransientRegistrarImpl

PORT=8080
DIR_ARG=$JINI_HOME/lib

DEBUG=off

# check for usage request
for arg in $*
do
  if [ "$arg" = -usage ]
  then
    echo
    echo $USAGE
    echo
    exit
  fi
done

# check for help request
for arg in $*
do
  if [ "$arg" = -help ]
  then
    echo 
    echo $USAGE
    echo 
    echo "where <scriptID> and its options include:"
    echo " "
    echo " httpd -- start the HTTPD daemon"
    echo " "
    echo " start the Browser JRMP, Jini ERI, or secure Jini ERI/jsse"
    echo " jrmp-browser"
    echo " jeri-browser"
    echo " jsse-browser"
    echo " "
    echo " start Phoenix under JRMP, Jini ERI, or secure Jini ERI/jsse"
    echo " jrmp-phoenix"
    echo " jeri-phoenix"
    echo " jsse-phoenix"
    echo " "
    echo " start ALL services in transient or activatable mode under JRMP"
    echo " jrmp-transient"
    echo " jrmp-activatable"
    echo " "
    echo " start ALL services in transient, nonactivatable, or activatable mode under Jini ERI"
    echo " jeri-transient"
    echo " jeri-nonactivatable"
    echo " jeri-activatable"
    echo " "
    echo " start ALL services in transient, nonactivatable, or activatable mode under JSSE"
    echo " jsse-transient"
    echo " jsse-nonactivatable"
    echo " jsse-activatable"
    echo " "
    echo " ******* For Reggie *******"
    echo " "
    echo " start ONE Reggie in transient or activatable mode under JRMP"
    echo " jrmp-transient-reggie"
    echo " jrmp-activatable-reggie"
    echo " "
    echo " start ONE Reggie in transient, nonactivatable, or activatable mode under Jini ERI"
    echo " jeri-transient-reggie"
    echo " jeri-nonactivatable-reggie"
    echo " jeri-activatable-reggie"
    echo " "
    echo " start ONE Reggie in transient, nonactivatable, or activatable mode under secure Jini ERI/jsse"
    echo " jsse-transient-reggie"
    echo " jsse-nonactivatable-reggie"
    echo " jsse-activatable-reggie"
    echo " "
    echo " ******* For Mahalo *******"
    echo " "
    echo " start ONE Mahalo in transient or activatable mode under JRMP"
    echo " jrmp-transient-mahalo"
    echo " jrmp-activatable-mahalo"
    echo " "
    echo " start ONE Mahalo in transient, nonactivatable, or activatable mode under Jini ERI"
    echo " jeri-transient-mahalo"
    echo " jeri-nonactivatable-mahalo"
    echo " jeri-activatable-mahalo"
    echo " "
    echo " start ONE Mahalo in transient, nonactivatable, or activatable mode under secure Jini ERI/jsse"
    echo " jsse-transient-mahalo"
    echo " jsse-nonactivatable-mahalo"
    echo " jsse-activatable-mahalo"
    echo " "
    echo " ******* For Fiddler *******"
    echo " "
    echo " start ONE Fiddler in transient or activatable mode under JRMP"
    echo " jrmp-transient-fiddler"
    echo " jrmp-activatable-fiddler"
    echo " "
    echo " start ONE Fiddler in transient, nonactivatable, or activatable mode under Jini ERI"
    echo " jeri-transient-fiddler"
    echo " jeri-nonactivatable-fiddler"
    echo " jeri-activatable-fiddler"
    echo " "
    echo " start ONE Fiddler in transient, nonactivatable, or activatable mode under secure Jini ERI/jsse"
    echo " jsse-transient-fiddler"
    echo " jsse-nonactivatable-fiddler"
    echo " jsse-activatable-fiddler"
    echo " "
    echo " ******* For Norm *******"
    echo " "
    echo " start ONE Norm in transient or activatable mode under JRMP"
    echo " jrmp-transient-norm"
    echo " jrmp-activatable-norm"
    echo " "
    echo " start ONE Norm in transient, nonactivatable, or activatable mode under Jini ERI"
    echo " jeri-transient-norm"
    echo " jeri-nonactivatable-norm"
    echo " jeri-activatable-norm"
    echo " "
    echo " start ONE Norm in transient, nonactivatable, or activatable mode under secure Jini ERI/jsse"
    echo " jsse-transient-norm"
    echo " jsse-nonactivatable-norm"
    echo " jsse-activatable-norm"
    echo " "
    echo " ******* For Mercury *******"
    echo " "
    echo " start ONE Mercury in transient or activatable mode under JRMP"
    echo " jrmp-transient-mercury"
    echo " jrmp-activatable-mercury"
    echo " "
    echo " start ONE Mercury in transient, nonactivatable, or activatable mode under Jini ERI"
    echo " jeri-transient-mercury"
    echo " jeri-nonactivatable-mercury"
    echo " jeri-activatable-mercury"
    echo " "
    echo " start ONE Mercury in transient, nonactivatable, or activatable mode under secure Jini ERI/jsse"
    echo " jsse-transient-mercury"
    echo " jsse-nonactivatable-mercury"
    echo " jsse-activatable-mercury"
    echo " "
    echo " ******* For Outrigger *******"
    echo " "
    echo " start ONE Outrigger in transient or activatable mode under JRMP"
    echo " jrmp-transient-outrigger"
    echo " jrmp-activatable-outrigger"
    echo " "
    echo " start ONE Outrigger in transient, nonactivatable, or activatable mode under Jini ERI"
    echo " jeri-transient-outrigger"
    echo " jeri-nonactivatable-outrigger"
    echo " jeri-activatable-outrigger"
    echo " "
    echo " start ONE Outrigger in transient, nonactivatable, or activatable mode under secure Jini ERI/jsse"
    echo " jsse-transient-outrigger"
    echo " jsse-nonactivatable-outrigger"
    echo " jsse-activatable-outrigger"
    echo " "
    echo " browser-httpmd   -- compute the httpmd codebase for the Browser"
    echo " phoenix-httpmd   -- compute the httpmd codebase for Phoenix"
    echo " reggie-httpmd    -- compute the httpmd codebase for Reggie"
    echo " mahalo-httpmd    -- compute the httpmd codebase for Mahalo"
    echo " fiddler-httpmd   -- compute the httpmd codebase for Fiddler"
    echo " norm-httpmd      -- compute the httpmd codebase for Norm"
    echo " mercury-httpmd   -- compute the httpmd codebase for Mercury"
    echo " outrigger-httpmd -- compute the httpmd codebase for Outrigger"
    echo " "
    echo " ******* Additional Arguments *******"
    echo " "
    echo " -port   for httpd        - the port to listen on"
    echo "         for Browser      - the port to use in the codebase"
    echo "         for Phoenix      - the port to use in the codebase"
    echo "         for the services - the port to use in the codebase"
    echo "                            (Default = $PORT)."
    echo " -dir    for httpd        - the base directory from which to serve jar files"
    echo "                            (Default = $JINI_HOME/lib)."
    echo " -stop   for httpd        - stops the server (must also supply the -port option"
    echo "                            if the server is listening to a port other than"
    echo "                            the default)"
    echo "         for Phoenix      - stops the server and deletes its persisted state"
    echo "         for the services - destroys the shared VM in which the activatable"
    echo "                            versions of the services are running"
    echo " -debug  for the Browser  - enables security debugging in the Browser's VM"
    echo "         for Phoenix      - enables security debugging in the Phoenix VM"
    echo "         for the services - enables security debugging in the VM in which the"
    echo "                            service runs and in the ServiceStarter setup VM"
    echo "                            (which may or may not be the same VM)"
    echo " "
    exit
  fi
done

# Step through the argument list, extracting the appropriate values
while [ "$#" -gt 0 ]
do
  ARG=$1
  for f in $ARG_LIST
  do
    if [ "$ARG" = "$f" ]
    then
      shift
      break
    fi
  done
  # test for all expected single-item args
  if [ "$ARG" = -stop ]
  then
    STOP="stop"
  fi
  if [ "$ARG" = -debug ]
  then
    DEBUG="access,failure"
  fi
  if [ "$ARG" = httpd ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts
    SCRIPT_BASE=httpd
    START_TYPE=httpd
  fi

  if [ "$ARG" = jrmp-browser ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=browser
    START_TYPE=browser
  fi
  if [ "$ARG" = jeri-browser ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=browser
    START_TYPE=browser
  fi
  if [ "$ARG" = jsse-browser ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=browser
    START_TYPE=browser
  fi

  if [ "$ARG" = jrmp-phoenix ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=phoenix
    START_TYPE=phoenix
  fi
  if [ "$ARG" = jeri-phoenix ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=phoenix
    START_TYPE=phoenix
  fi
  if [ "$ARG" = jsse-phoenix ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=phoenix
    START_TYPE=phoenix
  fi

  # *** all jrmp services
  if [ "$ARG" = jrmp-activatable ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=all-activatable
    START_TYPE=allservices
  fi
  if [ "$ARG" = jrmp-nonactivatable ]
  then
    echo "*** the non-activatable mode of the services should not be run using JRMP"
    exit
  fi
  if [ "$ARG" = jrmp-transient ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=all-transient
    START_TYPE=allservices
  fi

  # *** all jeri services
  if [ "$ARG" = jeri-activatable ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=all-activatable
    START_TYPE=allservices
  fi
  if [ "$ARG" = jeri-nonactivatable ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=all-nonactivatable
    START_TYPE=allservices
  fi
  if [ "$ARG" = jeri-transient ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=all-transient
    START_TYPE=allservices
  fi

  # *** all jsse services
  if [ "$ARG" = jsse-activatable ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=all-activatable
    START_TYPE=allservices
  fi
  if [ "$ARG" = jsse-nonactivatable ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=all-nonactivatable
    START_TYPE=allservices
  fi
  if [ "$ARG" = jsse-transient ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=all-transient
    START_TYPE=allservices
  fi

  # *** Reggie jrmp
  if [ "$ARG" = jrmp-activatable-reggie ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=reggie
    INTERFACE_NAME=Registrar
    IMPL_NAME=PersistentRegistrarImpl
  fi
  if [ "$ARG" = jrmp-nonactivatable-reggie ]
  then
    echo "*** the non-activatable mode of this service should not be run using JRMP"
    exit
  fi
  if [ "$ARG" = jrmp-transient-reggie ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-transient
    SERVICE_NAME=reggie
    INTERFACE_NAME=Registrar
    IMPL_NAME=TransientRegistrarImpl
  fi
  # *** Reggie jeri
  if [ "$ARG" = jeri-activatable-reggie ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=reggie
    INTERFACE_NAME=Registrar
    IMPL_NAME=PersistentRegistrarImpl
  fi
  if [ "$ARG" = jeri-nonactivatable-reggie ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=reggie
    INTERFACE_NAME=Registrar
    IMPL_NAME=PersistentRegistrarImpl
  fi
  if [ "$ARG" = jeri-transient-reggie ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-transient
    SERVICE_NAME=reggie
    INTERFACE_NAME=Registrar
    IMPL_NAME=TransientRegistrarImpl
  fi
  # *** Reggie jsse
  if [ "$ARG" = jsse-activatable-reggie ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=reggie
    INTERFACE_NAME=Registrar
    IMPL_NAME=PersistentRegistrarImpl
  fi
  if [ "$ARG" = jsse-nonactivatable-reggie ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=reggie
    INTERFACE_NAME=Registrar
    IMPL_NAME=PersistentRegistrarImpl
  fi
  if [ "$ARG" = jsse-transient-reggie ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-transient
    SERVICE_NAME=reggie
    INTERFACE_NAME=Registrar
    IMPL_NAME=TransientRegistrarImpl
  fi

  # *** Mahalo jrmp
  if [ "$ARG" = jrmp-activatable-mahalo ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=mahalo
    INTERFACE_NAME=TxnManager
    IMPL_NAME=ActivatableMahaloImpl
  fi
  if [ "$ARG" = jrmp-nonactivatable-mahalo ]
  then
    echo "*** the non-activatable mode of this service should not be run using JRMP"
    exit
  fi
  if [ "$ARG" = jrmp-transient-mahalo ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-transient
    SERVICE_NAME=mahalo
    INTERFACE_NAME=TxnManager
    IMPL_NAME=TransientMahaloImpl
  fi
  # *** Mahalo jeri
  if [ "$ARG" = jeri-activatable-mahalo ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=mahalo
    INTERFACE_NAME=TxnManager
    IMPL_NAME=ActivatableMahaloImpl
  fi
  if [ "$ARG" = jeri-nonactivatable-mahalo ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=mahalo
    INTERFACE_NAME=TxnManager
    IMPL_NAME=NonActivatableMahaloImpl
  fi
  if [ "$ARG" = jeri-transient-mahalo ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-transient
    SERVICE_NAME=mahalo
    INTERFACE_NAME=TxnManager
    IMPL_NAME=TransientMahaloImpl
  fi
  # *** Mahalo jsse
  if [ "$ARG" = jsse-activatable-mahalo ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=mahalo
    INTERFACE_NAME=TxnManager
    IMPL_NAME=ActivatableMahaloImpl
  fi
  if [ "$ARG" = jsse-nonactivatable-mahalo ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=mahalo
    INTERFACE_NAME=TxnManager
    IMPL_NAME=NonActivatableMahaloImpl
  fi
  if [ "$ARG" = jsse-transient-mahalo ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-transient
    SERVICE_NAME=mahalo
    INTERFACE_NAME=TxnManager
    IMPL_NAME=TransientMahaloImpl
  fi

  # *** Fiddler jrmp
  if [ "$ARG" = jrmp-activatable-fiddler ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=fiddler
    INTERFACE_NAME=Fiddler
    IMPL_NAME=ActivatableFiddlerImpl
  fi
  if [ "$ARG" = jrmp-nonactivatable-fiddler ]
  then
    echo "*** the non-activatable mode of this service should not be run using JRMP"
    exit
  fi
  if [ "$ARG" = jrmp-transient-fiddler ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-transient
    SERVICE_NAME=fiddler
    INTERFACE_NAME=Fiddler
    IMPL_NAME=TransientFiddlerImpl
  fi
  # *** Fiddler jeri
  if [ "$ARG" = jeri-activatable-fiddler ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=fiddler
    INTERFACE_NAME=Fiddler
    IMPL_NAME=ActivatableFiddlerImpl
  fi
  if [ "$ARG" = jeri-nonactivatable-fiddler ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=fiddler
    INTERFACE_NAME=Fiddler
    IMPL_NAME=NonActivatableFiddlerImpl
  fi
  if [ "$ARG" = jeri-transient-fiddler ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-transient
    SERVICE_NAME=fiddler
    INTERFACE_NAME=Fiddler
    IMPL_NAME=TransientFiddlerImpl
  fi
  # *** Fiddler jsse
  if [ "$ARG" = jsse-activatable-fiddler ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=fiddler
    INTERFACE_NAME=Fiddler
    IMPL_NAME=ActivatableFiddlerImpl
  fi
  if [ "$ARG" = jsse-nonactivatable-fiddler ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=fiddler
    INTERFACE_NAME=Fiddler
    IMPL_NAME=NonActivatableFiddlerImpl
  fi
  if [ "$ARG" = jsse-transient-fiddler ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-transient
    SERVICE_NAME=fiddler
    INTERFACE_NAME=Fiddler
    IMPL_NAME=TransientFiddlerImpl
  fi

  # *** Norm jrmp
  if [ "$ARG" = jrmp-activatable-norm ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=norm
    INTERFACE_NAME=NormServer
    IMPL_NAME=ActivatableNormServerImpl
  fi
  if [ "$ARG" = jrmp-nonactivatable-norm ]
  then
    echo "*** the non-activatable mode of this service should not be run using JRMP"
    exit
  fi
  if [ "$ARG" = jrmp-transient-norm ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-transient
    SERVICE_NAME=norm
    INTERFACE_NAME=NormServer
    IMPL_NAME=TransientNormServerImpl
  fi
  # *** Norm jeri
  if [ "$ARG" = jeri-activatable-norm ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=norm
    INTERFACE_NAME=NormServer
    IMPL_NAME=ActivatableNormServerImpl
  fi
  if [ "$ARG" = jeri-nonactivatable-norm ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=norm
    INTERFACE_NAME=NormServer
    IMPL_NAME=PersistentNormServerImpl
  fi
  if [ "$ARG" = jeri-transient-norm ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-transient
    SERVICE_NAME=norm
    INTERFACE_NAME=NormServer
    IMPL_NAME=TransientNormServerImpl
  fi
  # *** Norm jsse
  if [ "$ARG" = jsse-activatable-norm ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=norm
    INTERFACE_NAME=NormServer
    IMPL_NAME=ActivatableNormServerImpl
  fi
  if [ "$ARG" = jsse-nonactivatable-norm ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=norm
    INTERFACE_NAME=NormServer
    IMPL_NAME=PersistentNormServerImpl
  fi
  if [ "$ARG" = jsse-transient-norm ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-transient
    SERVICE_NAME=norm
    INTERFACE_NAME=NormServer
    IMPL_NAME=TransientNormServerImpl
  fi

  # *** Mercury jrmp
  if [ "$ARG" = jrmp-activatable-mercury ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=mercury
    INTERFACE_NAME=MailboxBackEnd
    IMPL_NAME=ActivatableMercuryImpl
  fi
  if [ "$ARG" = jrmp-nonactivatable-mercury ]
  then
    echo "*** the non-activatable mode of this service should not be run using JRMP"
    exit
  fi
  if [ "$ARG" = jrmp-transient-mercury ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-transient
    SERVICE_NAME=mercury
    INTERFACE_NAME=MailboxBackEnd
    IMPL_NAME=TransientMercuryImpl
  fi
  # *** Mercury jeri
  if [ "$ARG" = jeri-activatable-mercury ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=mercury
    INTERFACE_NAME=MailboxBackEnd
    IMPL_NAME=ActivatableMercuryImpl
  fi
  if [ "$ARG" = jeri-nonactivatable-mercury ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=mercury
    INTERFACE_NAME=MailboxBackEnd
    IMPL_NAME=NonActivatableMercuryImpl
  fi
  if [ "$ARG" = jeri-transient-mercury ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-transient
    SERVICE_NAME=mercury
    INTERFACE_NAME=MailboxBackEnd
    IMPL_NAME=TransientMercuryImpl
  fi
  # *** Mercury jsse
  if [ "$ARG" = jsse-activatable-mercury ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=mercury
    INTERFACE_NAME=MailboxBackEnd
    IMPL_NAME=ActivatableMercuryImpl
  fi
  if [ "$ARG" = jsse-nonactivatable-mercury ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=mercury
    INTERFACE_NAME=MailboxBackEnd
    IMPL_NAME=NonActivatableMercuryImpl
  fi
  if [ "$ARG" = jsse-transient-mercury ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-transient
    SERVICE_NAME=mercury
    INTERFACE_NAME=MailboxBackEnd
    IMPL_NAME=TransientMercuryImpl
  fi

  # *** Outrigger jrmp
  if [ "$ARG" = jrmp-activatable-outrigger ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=outrigger
    INTERFACE_NAME=OutriggerServer
    IMPL_NAME=PersistentOutriggerImpl
  fi
  if [ "$ARG" = jrmp-nonactivatable-outrigger ]
  then
    echo "*** the non-activatable mode of this service should not be run using JRMP"
    exit
  fi
  if [ "$ARG" = jrmp-transient-outrigger ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jrmp
    SCRIPT_BASE=one-transient
    SERVICE_NAME=outrigger
    INTERFACE_NAME=OutriggerServer
    IMPL_NAME=TransientOutriggerImpl
  fi
  # *** Outrigger jeri
  if [ "$ARG" = jeri-activatable-outrigger ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=outrigger
    INTERFACE_NAME=OutriggerServer
    IMPL_NAME=PersistentOutriggerImpl
  fi
  if [ "$ARG" = jeri-nonactivatable-outrigger ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=outrigger
    INTERFACE_NAME=OutriggerServer
    IMPL_NAME=PersistentOutriggerImpl
  fi
  if [ "$ARG" = jeri-transient-outrigger ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jeri
    SCRIPT_BASE=one-transient
    SERVICE_NAME=outrigger
    INTERFACE_NAME=OutriggerServer
    IMPL_NAME=TransientOutriggerImpl
  fi
  # *** Outrigger jsse
  if [ "$ARG" = jsse-activatable-outrigger ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-activatable
    SERVICE_NAME=outrigger
    INTERFACE_NAME=OutriggerServer
    IMPL_NAME=PersistentOutriggerImpl
  fi
  if [ "$ARG" = jsse-nonactivatable-outrigger ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-nonactivatable
    SERVICE_NAME=outrigger
    INTERFACE_NAME=OutriggerServer
    IMPL_NAME=PersistentOutriggerImpl
  fi
  if [ "$ARG" = jsse-transient-outrigger ]
  then
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SCRIPT_BASE=one-transient
    SERVICE_NAME=outrigger
    INTERFACE_NAME=OutriggerServer
    IMPL_NAME=TransientOutriggerImpl
  fi

  # *** For computing HTTPMD ***
  if [ "$ARG" = browser-httpmd ]
  then
    STOP=compute
    START_TYPE=httpmd
    SCRIPT_BASE=httpmd
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SERVICE_NAME=browser
  fi
  if [ "$ARG" = phoenix-httpmd ]
  then
    STOP=compute
    START_TYPE=httpmd
    SCRIPT_BASE=httpmd
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SERVICE_NAME=phoenix
  fi
  if [ "$ARG" = reggie-httpmd ]
  then
    STOP=compute
    START_TYPE=httpmd
    SCRIPT_BASE=httpmd
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SERVICE_NAME=reggie
  fi
  if [ "$ARG" = mahalo-httpmd ]
  then
    STOP=compute
    START_TYPE=httpmd
    SCRIPT_BASE=httpmd
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SERVICE_NAME=mahalo
  fi
  if [ "$ARG" = fiddler-httpmd ]
  then
    STOP=compute
    START_TYPE=httpmd
    SCRIPT_BASE=httpmd
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SERVICE_NAME=fiddler
  fi
  if [ "$ARG" = norm-httpmd ]
  then
    STOP=compute
    START_TYPE=httpmd
    SCRIPT_BASE=httpmd
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SERVICE_NAME=norm
  fi
  if [ "$ARG" = mercury-httpmd ]
  then
    STOP=compute
    START_TYPE=httpmd
    SCRIPT_BASE=httpmd
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SERVICE_NAME=mercury
  fi
  if [ "$ARG" = outrigger-httpmd ]
  then
    STOP=compute
    START_TYPE=httpmd
    SCRIPT_BASE=httpmd
    SCRIPT_PATH=$EXAMPLE_HOME/example/scripts/jsse
    SERVICE_NAME=outrigger
  fi

  # if there are no args left, then exit loop
  if [ "$#" -eq 0 ]
  then
    break
  fi

  # test for all expected double-item args
  if [ "$ARG" = -port ]
  then
    PORT=$1
  fi
  if [ "$ARG" = -dir ]
  then
    DIR_ARG=$1
  fi

  shift
done
#end parseArgs

if [ "$SCRIPT_BASE" = notset ]
then
  echo "$USAGE"
  echo "*** a <scriptID> must be entered, check the argument list"
  exit
fi

# set the args to pass based on what's being run
if [ "$START_TYPE" = httpd ]
then
  EXE_ARGS="$JDK_HOME $JINI_HOME $PORT $DIR_ARG"
fi
if [ "$START_TYPE" = browser ]
then
  BROWSER_MESSAGE_DIGEST_COMMAND="$JDK_HOME/bin/java \
  -cp $JINI_HOME/lib/tools.jar:$JINI_HOME/lib/jsk-platform.jar \
  com.sun.jini.tool.ComputeDigest \
  $JINI_HOME/lib/browser-dl.jar \
  sha"
  BROWSER_MESSAGE_DIGEST=`$BROWSER_MESSAGE_DIGEST_COMMAND`
  # ********************************************************
  EXE_ARGS="$JDK_HOME $JINI_HOME $EXAMPLE_HOME $HOSTNAME $PORT $DEBUG $BROWSER_MESSAGE_DIGEST"
fi
if [ "$START_TYPE" = phoenix ]
then
  PHOENIX_MESSAGE_DIGEST_COMMAND="$JDK_HOME/bin/java \
  -cp $JINI_HOME/lib/tools.jar:$JINI_HOME/lib/jsk-platform.jar \
  com.sun.jini.tool.ComputeDigest \
  $JINI_HOME/lib/phoenix-dl.jar \
  sha"
  PHOENIX_MESSAGE_DIGEST=`$PHOENIX_MESSAGE_DIGEST_COMMAND`
  # ********************************************************
  EXE_ARGS="$JDK_HOME $JINI_HOME $EXAMPLE_HOME $HOSTNAME $PORT $DEBUG $PHOENIX_MESSAGE_DIGEST"
fi
if [ "$START_TYPE" = allservices ]
then
  EXE_ARGS="$JDK_HOME $JINI_HOME $EXAMPLE_HOME $HOSTNAME $PORT $DEBUG"
fi
if [ "$START_TYPE" = oneservice ]
then
  EXE_ARGS="$JDK_HOME $JINI_HOME $EXAMPLE_HOME $HOSTNAME $PORT $SERVICE_NAME $INTERFACE_NAME $IMPL_NAME $DEBUG"
fi
if [ "$START_TYPE" = httpmd ]
then
  EXE_ARGS="$JDK_HOME $JINI_HOME $EXAMPLE_HOME $HOSTNAME $PORT $SERVICE_NAME $DEBUG"
fi

# build the command to execute
SCRIPT="$SCRIPT_PATH/$STOP-$SCRIPT_BASE $EXE_ARGS"
echo " "
# run the command
$SCRIPT

