#!/bin/sh
#
# StartUp Sequence for Ganimed
#
#-------------------------------------------------------

# 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

# 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
 
# test whether PROGRESROOT exists and
# actually contains PROGRES-installation
# files.
 
if [ ! -f $PROGRESROOT/bin/$OSVERSION/ProgControl ]
then
  PROGRESROOT=$HOME/progres
  if [ ! -f $PROGRESROOT/bin/$OSVERSION/ProgControl ]
  then
    PROGRESROOT=/home/projects/progres
    if [ ! -f $PROGRESROOT/bin/$OSVERSION/ProgControl ]
    then
      echo "Variable PROGRESROOT has wrong value!"
      echo "Change default value in this script!"
      exit 1
    fi
  fi
fi

# Initialize additional environment variables

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

. $PROGRESROOT/bin/InitEnvVars

#-------------------------------------------------

# Directory for ganimed graph database

GRAS=$DATAROOT/gras/$OSVERSION/ganimed$UID
export GRAS

# Directory for temporary data

TMPGRAS=/var/tmp/ganimed$UID
export TMPGRAS

# Page Cache Size for Ganimed

GRASALLOC=500
export GRASALLOC

#------------------------------------------------

echo "Searching for ganimed ..."
probe="$PROGRESROOT/bin/$OSVERSION/ganimed -b > /dev/null"
ga=`$probe`
if [ $? -eq 1 ]
then
  probe="$PROGRESROOT/bin/$OSVERSION/ganimed -i"
  ga=`$probe`
else
  # remove eventually existing old garbage
  if [ -d $GRAS ]
  then
    rm -rf $GRAS
  fi
  mkdir -p $GRAS
  if [ -d $TMPGRAS ]
  then
    rm -rf $TMPGRAS
  fi
  mkdir -p $TMPGRAS

  echo "Ganimed not running, starting one ... "
  $PROGRESROOT/bin/$OSVERSION/ganimed
  ga=`$probe`
  if [ ! $? -eq 1 ]
  then
    echo "failed."
    exit 1
  fi
fi
