#! /bin/sh
#------------------------------------------------------------------------------
#
#	This shellscript takes the name of a graph pool directory
#	and offers a number of operations for inspecting, manipulating,
#	and recovering graph pools and graphs within this directory.
#    
#       $1 = PoolDir  = $GRAS (default value)
#
#------------------------------------------------------------------------------
 
# 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

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

TMPGRAS=${TMPGRAS:-/tmp/pool}$$
export TMPGRAS
if [ -d $TMPGRAS ]
then
  rm -r $TMPGRAS
fi
mkdir -p $TMPGRAS

GRAS=${1:-${GRAS:-${DATAROOT:-$HOME/progresdata}/gras/$OSVERSION}}
export GRAS

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

if [ ${GRAS:-""} = "" ]
then
  echo ""
  echo "USAGE: TestPoolDir [ pooldir ]"
  echo "       "'$'"GRAS = pooldir must exist"
  echo ""
elif [ ! -d $GRAS ]
then
  echo ""
  echo "ERROR: pooldir $GRAS not existent"
  echo ""
else
  $PROGRESROOT/bin/StartGanimed
  $PROGRESROOT/bin/$OSVERSION/AGTest
fi

rm -rf $TMPGRAS
