#!/bin/bash
#==============================================================
#  Name:  lclshome
#
#  Rem:   This script launches Stephen&Stephen's LCLS EPICS Home Screen.
# 
#  Usage: lclshome
#
#  Auth:  07-Dec-2006, Jingchen Zhou   (jingchen)
#  Rev:   dd-mmm-yyyy,  Whoever    (user):
#         08-Dec-2006, Jingchen Zhou (jingchen)
#         - added OS check
#         23-Mar-2007, Jingchen Zhou (jingchen)
#         - set up the LCLS environment if not
#         27-Mar-2007, Jingchen Zhou (jingchen)
#         - set edm as noedit mode if used by production accounts
#         18-Jun-2008, Jingchen Zhou (jingchen)
#         - updated the account list for the CA network 
#--------------------------------------------------------------

# ==============================================
# Let's override the original lclshome and 
# run a newer version of edm
# ==============================================
export EPICS_EXTENSIONS_VER=Beta
export EDM=""
# ==============================================

CMD="edm"
ACCLIST="laci physics acclegr eoicdesk linac mccops1 lclsops1 lclsops2 lclsops3 lclsops4 lclsops5"

if [ `uname -s` != "Linux" ] ; then
    echo "Please run $0 on a public Linux machine"
    exit 1
fi

if [ -z "${EDM}" ] ; then
#    . /usr/local/lcls/epics/setup/epicsReset.bash
    . ~/.bashrc
fi

cmdpath=`which ${CMD}`
if [ ! -x "${cmdpath}" ] ; then
    echo "ERROR: cannot find ${CMD}"
    exit 1
fi

if [ ! -f ${EDM}/lcls/lcls_main.edl ] ; then
    echo "ERROR: cannot find lcls_main.edl"
    exit 1
fi 

USER=`whoami` 
INLIST=`echo ${ACCLIST} | grep ${USER}`
mode="-x"
if [ -n "${INLIST}" ]; then  
    mode="-x -noedit"
fi


export EDMFILES=$TOOLS/edm/config-Beta
export EDMOBJECTS=$EDMFILES
export EDMPVOBJECTS=$EDMFILES
export EDMFILTERS=$EDMFILES
export EDMACTIONS=$EDMFILES

#add path to beta display that override production displays
#export EDMDATAFILES=/usr/local/lcls/tools/edm/display/Beta:/usr/local/lcls/tools/edm/display/Beta/lcls:$EDMDATAFILES
#add path to Beta X-Ray and XTOD displays
#export EDMDATAFILES=$EDMDATAFILES:/usr/local/lcls/tools/edm/display/x-ray:/usr/local/lcls/tools/edm/display/x-ray/xtod

${cmdpath} -eolc ${mode} lcls_main

if [ $? -ne 0 ]; then
    echo "ERROR: $0 failed" 
    exit 1
fi

exit 0

