#!/bin/bash
#==============================================================
#  Name:  facethome
#
#  Rem:   This script launches FACET EPICS Home Screen.
# 
#  Usage: lclshome
#
#  Auth:  07-Mar-2011, Arturo Alarcon   (alarcon)
#  Rev:   
# ------------------------------------------------------------
#         05-Mar-2013, Jingchen Zhou (jingchen)
#         Removed EDMDATAFILES to use the definition 
#         in $TOOLS/edm/config/setup_facet.sh 
#
#         10-Feb-2015, Garth Brown (gwbrown)
#         Don't set prod environment veriables for dev
#--------------------------------------------------------------
CMD="edm"
ACCLIST="flaci fphysics facclegr feoicdesk flinac 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/facet/epics/setup/epicsReset.bash
    . ~/.bashrc
fi

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

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

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

if [ ! -d /afs/slac/g/lcls ]; then
   #export EDMFILTERS=$TOOLS/edm/config/homeFilter
   export EDMFILTERS=/usr/local/facet/tools/edm/config/homeFilter

   # for edm putlogging
   export EDMCLEAREPICSDEFAULT=1
   export EDMPUTLOGGER=/usr/local/facet/tools/edm/config/edmPutLogging/writeToMsgLog.py
   export EDMPVOBJECTS=/usr/local/facet/tools/edm/config/edmPutLogging
else
   echo ON DEV: no putlogging, or border
   . /afs/slac/g/lcls/tools/script/ENVS_facet.bash
   # Dev environmet is typically lcls based, so add the facet specific edm directory
   export EDMDATAFILES=.:${EDM}/facet:${EDMDATAFILES}:${EDM}/exp
fi

${cmdpath} -eolc ${mode} -m "EVGLOCA=SYS1,SYS=SYS1" facet_main

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

exit 0
