#!/bin/sh
##
# This is a sample script for the activation of the
# prototype $PROTOTYPE and it contains proposals for the 
# definition of all needed environment variables.
#
# Version 1.1, (06/03/98, ajw)


#----------- Invocation Parameters -----------------
#
#  StartProto [ -s Settings ] [ -g HostGraph ] [ Project ]
#
usage="Call: $0 [ -s Settings ] [ -g HostGraph ] [ Project ]"
#
# 
# Variables optionally influenced by parameters
# ---------------------------------------------
#
#   Project   = Project parameter = name of a project's graph pool.
#               ( default:  $PROJECT if set else "DemoProto" )
#   Settings  = Name of the directory holding the settings configuration
#               changes in the "Global Settings" window of the prototype.
#               The default "NoSetting" does not allow to reuse settings 
#               of former prototype sessions.
#   HostGraph = Allows to create or reopen host graphs by name.
#               ( default: "${PROJECT}HostGraph" )


#----------- Defaults for script parameters -----------------
#
# Assume that PROGRESROOT AND DATAROOT are properly set in the environment
# if they should be different from the default values.
# Recall that the values for PROGRESROOT and DATAROOT are 
# $HOME and $HOME/progresdata, resp.

# Set PROJECT according to your pool.
# Name of the current project subdirectory
# Default value = "DemoProto"
PROJECT=${PROJECT:-DemoProto}

# Set HOSTGRAPH to your host graph name (may be non existing).
HOSTGRAPH=ProtoHostGraph

# Set SETTINGS to a directory (may be nonexisting) which
# should be used to store view specific settings. This allows to
# use different settings on the same generated prototype.
# The value NoSettings (default) suppresses this functionality.
SETTINGS=NoSettings


#
# Parse Command-Line Parameters
#
while getopts hs:g: arg
do
  case $arg in
    s) SETTINGS=$OPTARG;;
    g) HOSTGRAPH=$OPTARG;;
    h|\?) echo $usage; exit 1;;
  esac
done  

#
# Get the Projectname
#
shift `expr $OPTIND - 1`
if [ $# -gt 1 ]
then
  echo "More than one project name given!"
  echo $usage
  exit 10
else
  PROJECT=${1:-$PROJECT}
fi  

export PROJECT HOSTGRAPH SETTINGS


# Determine which operating system version the host has
osver=`uname -a`
case $osver in
SunOS*5.*)    # Solaris 2.x
        PLATFORM=sol2
        OSVERSION=SOL2
        OSDYNLIBEXT=so;;
SunOS*4.1.*)  # SunOS 4.1.x
        PLATFORM=sunos4
        OSVERSION=SUNOS4
        OSDYNLIBEXT=so.0.0;;
Linux*2.*.*)  # Linux 2.x.x
        PLATFORM=linuxlibc6
        OSVERSION=LINUXLIBC6
        OSDYNLIBEXT=so;;	
*)      echo 'unknown os version' ;;  
esac
export PLATFORM OSVERSION OSDYNLIBEXT
 
GENDIR=${GENDIR:-`pwd`}
export GENDIR

## Adapt PROTOTYPE to your application (the same as in your makefile).
## Expecting file ${PROTOTYPE} ./bin/${OSVERSION}
PROTOTYPE=Proto
export PROTOTYPE

if [ ! -f ./bin/${OSVERSION}/${PROTOTYPE} ]
then
  echo "File ./bin/${OSVERSION}/${PROTOTYPE} not found."
  exit 1
elif [ ! -x ./bin/${OSVERSION}/${PROTOTYPE} ]
then
  echo "File ./bin/${OSVERSION}/${PROTOTYPE} is not executable."
  exit 1
fi

# Definition of the virtual memory size available for caching
# databases (in kB). An optimal value is larger than the size
# of all concurrently open documents (graphs) and must be
# smaller than the workstation's available swap space.
# Default value = 2000
GRASALLOC=2000
export GRASALLOC

#
# Name of a temporarily existing directory for DBMS (on the
# workstation's local disk whenever possible)
# Default value = "/var/tmp/$USER$PROJECT"
#
# ATTENTION: do not delete this directoy or its contents
#            after system crashes. The underlying DBMS
#            uses the log-files within this directory to
#            recover the most recently consistent state
#            of the project database. In rare cases, 
#            recovery may not work. Then delete both
#            the directories $TMPGRAS and $GRAS, create
#            a new project database, and recreate all
#            documents by parsing the files in $IPSENBACKUP
#            (see below).

TMPGRAS=${NewTmp:-/var/tmp}/$USER$PROJECT
export TMPGRAS


if [ ! -d $TMPGRAS ]
then
  echo "Creating a new temporary directory $TMPGRAS ..."
  mkdir -p $TMPGRAS
fi
  
#
#----------- Installation specific variables --------------
#
#            PLEASE CHECK THE FOLLOWING LINES
#

# Definition of the PROGRES environment's root directory
# i.e. the root of the directory which contains all
# installed PROGRES files. $HOME or $HOME/progres might
# be a reasonable value if PROGRES has an own account
# or is a subdirectory of the current account.
 
PROGRESROOT=${PROGRESROOT:-$HOME}
export PROGRESROOT

# IMPORTLIB indicates where the library of the imported types and functions
# can be found. Note that this library is not os-independent.
IMPORTLIB=${IMPORTLIB:-$PROGRESROOT/import/lib/$OSVERSION/libImportedFunctions.$OSDYNLIBEXT}
export IMPORTLIB

# Path to the installation of Tcl/Tk
TK_LIBRARY=$PROGRESROOT/lib/${OSVERSION}/tk8.0
TCL_LIBRARY=$PROGRESROOT/lib/${OSVERSION}/tcl8.0
TIX_LIBRARY=$PROGRESROOT/lib/${OSVERSION}/tix4.1
export TK_LIBRARY TCL_LIBRARY TIX_LIBRARY

# BEGIN  TCL_PATH 
TCL_PATH=$PROGRESROOT/browser
export TCL_PATH
# END  TCL_PATH 

# Initialize additional environment variables

LD_LIBRARY_PATH="$PROGRESROOT/import/lib/$OSVERSION:$PROGRESROOT/lib/$OSVERSION:$PROGRESROOT/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH


. $PROGRESROOT/bin/InitEnvVars


#
#--------- The following lines should not be changed ------
#

# Preventing program halt in case of undefined
# environment variable DISPLAY (default value
# is local machine)

DISPLAY=${DISPLAY:-$HOST":0.0"}
export DISPLAY

# Definition of environment variables for the
# graph browser EDGE (university of Karlsruhe)
# with various extensions (dynamic linking of
# application specific proceduresm etc.)

# Definition of the browser's root directory

GRASBROWSERLOADPATH=$PROGRESROOT/browser
export GRASBROWSERLOADPATH

# Definition of a list of library directories
# used for dynamic linking purposes.

GRASBROWSERLIBPATH=$PROGRESROOT
export GRASBROWSERLIBPATH

# Definition of a single directory, where node icons for
# our graph browser EDGE (browser) may be stored.
# Default icons are stored in $PROGRESROOT/browser/etc
# (list of directories not yet supported).
 
EDGE_ICON_PATH=${EDGE_ICON_PATH:-$DATAROOT/icons}
export EDGE_ICON_PATH

if [ ! -d $EDGE_ICON_PATH ]
then
  # directory doesn't exist
  echo "Creating a link to the icon directory ..."
  ln -s $PROGRESROOT/browser/etc $EDGE_ICON_PATH
fi

# definition of the root directory for all project databases.
GRAS=$DATAROOT/gras
export GRAS

# directory doesn't exist
if [ ! -d $GRAS ]
then
  echo "Creating a new DBMS directory ..."
  mkdir $GRAS
fi

# Set path to exception messages
IPSENMESSAGES=$PROGRESROOT/data/messages
export IPSENMESSAGES

# Startup Sequence for Ganimed
$PROGRESROOT/bin/StartGanimed

echo "Starting prototype ..."
./bin/${OSVERSION}/$PROTOTYPE  $PROJECT $HOSTGRAPH $SETTINGS

