#!/bin/bash
#==============================================================
#  Name:  facethome
#
#  Rem:   This script launches FACET EPICS Home Screen.
# 
#  Usage: lclshome
#
#  Auth:  07-Mar-2011, Arturo Alarcon   (alarcon)
#  Rev:   
# ------------------------------------------------------------
#
#--------------------------------------------------------------
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

#export EDMFILTERS=$TOOLS/edm/config/homeFilter
export EDMFILTERS=/usr/local/facet/tools/edm/config/homeFilter

export EDMDATAFILES=.:..:$EDMUSERS:$EDM/facet:$EDM/mgnt:$EDM/slc:$EDM/event:$EDM/vac:${EDM}/pps:${EDM}/bcs:${EDM}/mps:${EDM}/prof:${EDM}/mc:${EDM}/ws:${EDM}/watr:${EDM}/temp:${EDM}/alh:${EDM}/blm:${EDM}/toroid:${EDM}/misc:${EDM}/fbck:${EDM}/cud:${EDM}/cf:${EDM}/knob:${EDM}/autosave:${EDM}/camac:${EDM}/exp:${EDM}/rf:${EDM}/install:${EDM}/klys

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

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

exit 0
