#!/bin/bash
#==============================================================
#  Name:  lerfhome
#
#  Rem:   This script launches the LCLS2 LERF EPICS Home Screen.
# 
#  Usage: lerfhome
#
#  Auth: J. Rock, adopting from Stephen&Stephen's lclshome  
#  Rev:   dd-mmm-yyyy,  Whoever    (user):
#
#--------------------------------------------------------------

CMD="edm"
ACCLIST="laci softegr"

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}/lerf/lerf_main.edl ] ; then
    echo "ERROR: cannot find lerf_main.edl"
    exit 1
fi 

#export EDMFILTERS=$TOOLS/edm/config/homeFilter
export EDMFILTERS=/usr/local/lcls/tools/edm/config/homeFilter
export EDMDATAFILES=.:$EDM/install:$TOOLS/edm/display/lerf:$TOOLS/edm/display/lcls2:$EDMDATAFILES

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

${cmdpath} -eolc ${mode} -m "EVGLOCA=SYS2,SYS=SYS2" lerf_main

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

exit 0

