#!/usr/local/bin/bash                                 
#*************************************************************************
# Copyright (c) 2002 The University of Chicago, as Operator of Argonne
#     National Laboratory.
# Copyright (c) 2002 The Regents of the University of California, as
#     Operator of Los Alamos National Laboratory.
# EPICS BASE Versions 3.13.7
# and higher are distributed subject to a Software License Agreement found
# in file LICENSE that is included with this distribution. 
#*************************************************************************
#  Site-specific EPICS environment settings
#
#  sites should modify these definitions

# extended for verbosity
# and for variables EPICS_MODULES and EPICS_SNCSEQ_HOME 
# 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

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.8.2; 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

EPICS_HOME=$epicshome
export EPICS_HOME

ifVerboseEcho EPICS_HOME

# Location of epics base
if [ -z "${EPICS_BASE}" ] ; then
	EPICS_BASE=$baseDir
fi
export EPICS_BASE
ifVerboseEcho EPICS_BASE

# Location of epics extensions (medm, msi, etc.)
if [ -z "${EPICS_EXTENSIONS}" ] ; then
	EPICS_EXTENSIONS=${EPICS_HOME}/extensions
fi
ifVerboseEcho EPICS_EXTENSIONS

# Location of epics extensions (medm, msi, etc.)
if [ -z "${EPICS_MODULES}" ] ; then
	EPICS_MODULES=${EPICS_HOME}/modules
fi
ifVerboseEcho EPICS_MODULES

# Postscript printer definition needed by some extensions (eg medm, dp, dm, ...)
if [ -z "${PSPRINTER}" ] ; then
    export PSPRINTER=lp
fi
ifVerboseEcho PSPRINTER

#Needed only by the idl and ezcaIDL extensions.
export EPICS_EXTENSIONS

# Needed only by medm extension
#export EPICS_DISPLAY_PATH=/path/to/adl/files
export EPICS_DISPLAY_PATH=${EPICS_EXTENSIONS}/medm/adl
ifVerboseEcho EPICS_DISPLAY_PATH

# Needed only by orbitscreen extension
if [ -z "${ORBITSCREENHOME}" ] ; then
	export "ORBITSCREENHOME=${EPICS_EXTENSIONS/src/orbitscreen}"
fi
ifVerboseEcho ORBITSCREENHOME

# Needed only by adt extension
#if [ -z "${ADTHOME}" ] ; then
#	ADTHOME=
#	export ADTHOME
#fi

# Needed only by ar extension (archiver)
EPICS_AR_PORT=7002
export EPICS_AR_PORT
ifVerboseEcho EPICS_AR_PORT

# Needed for java extensions
if [ -z "${CLASSPATH}" ] ; then
	CLASSPATH="${EPICS_EXTENSIONS}/javalib"
else
        addToPathEnd ${EPICS_EXTENSIONS}/javalib CLASSPATH
fi
export CLASSPATH

# Allow private versions of extensions without a bin subdir
if [ -n "${EPICS_EXTENSIONS_PVT}" ] ; then
	addToPath "{EPICS_EXTENSIONS_PVT}"
fi

# Needed for seq/snc module (sequencer)
if [ -z "${EPICS_SNCSEQ_HOME}" ] ; then
        export EPICS_SNCSEQ_HOME=${EPICS_MODULES}/seq
fi
ifVerboseEcho EPICS_SNCSEQ_HOME

#---------------------------------------------------------------
# Start of set R3.14 environment variables
#
EPICS_HOST_ARCH=`"${EPICS_BASE}"/startup/EpicsHostArch.pl`
export EPICS_HOST_ARCH
ifVerboseEcho EPICS_HOST_ARCH

# Allow private versions of base
if [ -n "${EPICS_BASE_PVT}" ] ; then
	if [ -d "${EPICS_BASE_PVT}/bin/${EPICS_HOST_ARCH}" ]; then
 	   addToPath "${EPICS_BASE_PVT}/bin/${EPICS_HOST_ARCH}"
	fi
fi

# Allow private versions of extensions
if [ -n "${EPICS_EXTENSIONS_PVT}" ] ; then
	if [ -d "${EPICS_EXTENSIONS_PVT}/bin/${EPICS_HOST_ARCH}" ]; then
 	   addToPath "${EPICS_EXTENSIONS_PVT}/bin/${EPICS_HOST_ARCH}"
	fi
fi
addToPath "${EPICS_EXTENSIONS}/bin/${EPICS_HOST_ARCH}"

# End of set R3.14 environment variables

#---------------------------------------------------------------
#
## Start of set pre R3.14 environment variables
#
## Time service:
## EPICS_TS_MIN_WEST the local time difference from GMT.
#EPICS_TS_MIN_WEST=360
#export EPICS_TS_MIN_WEST
#
#HOST_ARCH=`"${MY_EPICS_BASE}"/startup/HostArch`
#export HOST_ARCH
#
## Allow private versions of base
#if [ -n "${EPICS_BASE_PVT}" ] ; then
#	if [ -d "${EPICS_BASE_PVT}/bin/${HOST_ARCH}" ]; then
#		PATH="${PATH}:${EPICS_BASE_PVT}/bin/${HOST_ARCH}"
#	fi
#fi
#
## Allow private versions of extensions
#if [ -n "${EPICS_EXTENSIONS_PVT}" ] ; then
#	if [ -d "${EPICS_EXTENSIONS_PVT}/bin/${HOST_ARCH}" ]; then
#		PATH="${PATH}:${EPICS_EXTENSIONS_PVT}/bin/${HOST_ARCH}"
#	fi
#fi
#
#PATH="${PATH}:${EPICS_EXTENSIONS}/lib/${HOST_ARCH}"
#
# End of set pre R3.14 environment variables

#---------------------------------------------------------------
unset defaultSourcedHelperScript
