#!/bin/sh
#
# Termination 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


probe="$PROGRESROOT/bin/$OSVERSION/ganimed -b"
ga=`$probe`
if [ $? -eq 1 ]
then
  $PROGRESROOT/bin/$OSVERSION/ganimed -T

  if [ -d $GRAS ]
  then
    rm -rf $GRAS
  else
    echo "Ganimed lost data directory!"
  fi

else
  echo "Ganimed not running ..."
fi
