#!/bin/sh
#---------------------------------------------------------
#
# This script contains reasonable default definitions for
# all environment variables which are needed in different
# scripts.
#
#---------------------------------------------------------
 
# 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
 
# Definition of the user's root directory for all user specific
# data (project databases, setup files etc.).
 
DATAROOT=${DATAROOT:-$HOME/progresdata}
export DATAROOT
 
if [ ! -d $DATAROOT ]
then
  # directory doesn't exist
  echo "Creating a new data directory ..."
  mkdir -p $DATAROOT
fi
 
# Extension of program search path. 
 
PATH="$PROGRESROOT/bin:$PROGRESROOT/bin/$OSVERSION:$PROGRESROOT/browser/bin/$OSVERSION:$PATH"
export PATH
 
# definition of a postscript printer's name
# which will be used for printing graphs ...
 
PRINTER=${PRINTER:-postscript}
export PRINTER

# 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=${GRASALLOC:-2000}
export GRASALLOC

# Create version tag for private database control server.
 
# Function to get the user's UID, because this
# function is not available in bourne shell
# UID variable is already set in Linux sh. 
 
getUID() {
tfs=$IFS
IFS='(='
set - `id`
IFS=$tfs
unset tfs
UID=$2
export UID
}

# Determine UID only if not already set.
if [ x$UID = x ]
then
  getUID
fi
 
# Set environment variables for Ganimed
 
GANIMEDVERSION=${GANIMEDVERSION:-$UID}
export GANIMEDVERSION
# (no longer necessary, any GRAS client uses from now on the
# same GANIMED process with an implicitly defined version
# number 3).

# Directory for database log messages (crash messages etc.).
 
LOGDIR=${LOGDIR:-$DATAROOT/logs}
export LOGDIR
 
if [ ! -d $LOGDIR ]
then
  # directory doesn't exist
  echo "Creating a new log directory ..."
  mkdir -p $LOGDIR
fi

# Directory with list of allowed workstations.
 
# Creation of a directory which may contain
# a file of all machines (hosts) on which
# PROGRES and its underlying database system
# GRAS are allowed to start processes.
 
GHOSTDIR=${GHOSTDIR:-$DATAROOT/etc}
export GHOSTDIR
 
if [ ! -d $GHOSTDIR ]
then
  # directory doesn't exist
#  echo "Creating etc directory for (g)hosts file ..."
  cp -r $PROGRESROOT/etc  $DATAROOT
fi
 
#if [ -f $GHOSTDIR/ghosts ]
#then
#  echo "Using trusted host information in"
#  echo "      $GHOSTDIR/ghosts"
#fi

