#!/bin/bash
# Site.profile.pre
# 	extends Site.profile for more verbosity
# 	and for variables EPICS_MODULES and EPICS_SNCSEQ_HOME 
# 	to be sourced before Site.profile(.main) is sourced 
# by p.zumbruch, p.zumbruch@gsi.de

# some helper function
defaultSourcedHelperScript=~epics/bin/fcn_addtopath.bash
if [ -f $sourcedHelperScript ]; 
then 
   source $sourcedHelperScript; 
elif [ -f $defaultSourcedHelperScript ]
then
   source $defaultSourcedHelperScript
else 
   echo $scriptname: cannot find script \"$sourcedHelperScript\" \(nor default:\"$defaultSourcedHelperScript\"\) ... exiting; 
   return -1; 
fi
unset defaultSourcedHelperScript

if [ -z $epicshome ]; 
then 
	epicshome=$(eval echo ~epics/EPICS); 
	echo set \$epicshome to defaultvalue $epicshome; 
fi
if [ -z $baseDir ]; 
then 
	baseDir=$epicshome/base-3.14.10; 
	echo set \$baseDir to defaultvalue $baseDir; 
fi

verbose=
while [ $# -gt 0 ]
do
  Option=$1
  case $Option in
    -v ) verbose=TRUE
      	shift 
      	;;
  esac
done

unset EPICS_HOME EPICS_BASE EPICS_EXTENSIONS EPICS_MODULES ORBITSCREENHOME EPICS_SNCSEQ_HOME

### settings

# home
export EPICS_HOME=$epicshome
type -t ifVerboseEcho | grep -q function | ifVerboseEcho EPICS_HOME

# MY_EPICS_BASE needed by Site.profile(.main)
export EPICS_BASE=$baseDir
type -t ifVerboseEcho | grep -q function | ifVerboseEcho EPICS_BASE
export MY_EPICS_BASE=$baseDir
type -t ifVerboseEcho | grep -q function | ifVerboseEcho MY_EPICS_BASE

# extensions
export EPICS_EXTENSIONS=${EPICS_HOME}/extensions
type -t ifVerboseEcho | grep -q function | ifVerboseEcho EPICS_EXTENSIONS
# modules
export EPICS_MODULES=${EPICS_HOME}/modules
type -t ifVerboseEcho | grep -q function | ifVerboseEcho EPICS_MODULES
# postscript printer 
if [ -z "$PSPRINTER" ]
then
	export PSPRINTER=lp
	type -t ifVerboseEcho | grep -q function | ifVerboseEcho PSPRINTER
fi

#medm display path
export EPICS_DISPLAY_PATH=$EPICS_EXTENSIONS/src/medm
type -t ifVerboseEcho | grep -q function | ifVerboseEcho EPICS_DISPLAY_PATH

#orbit screen home
export ORBITSCREENHOME=$EPICS_EXTENSIONS/src/orbitscreen
type -t ifVerboseEcho | grep -q function | ifVerboseEcho ORBITSCREENHOME

#archiver settings
export EPICS_AR_PORT=7002
type -t ifVerboseEcho | grep -q function | ifVerboseEcho EPICS_AR_PORT

#sequencer
export EPICS_SNCSEQ_HOME=${EPICS_MODULES}/seq
type -t ifVerboseEcho | grep -q function | ifVerboseEcho EPICS_SNCSEQ_HOME

