#! /bin/bash -norc
#==============================================================
#
#  Abs:  enables alarming for specified branch of the
#        alarm handler tree
#
#  Name: enableALHGroup.bash
#
#  Args:  alh group name
#
#  Usage: called from command line
#         group name can be found by clicking the "G"uidance
#         button on the alarm handler gui
#
# $1 = epicsSetup script location
# $2 = top-level config file
#--------------------------------------------------------------
#
if [ $# -lt 2 ]; then
   # this should go in the outer script now
   echo "========================================================"
   echo "Please specify a group name."
   echo "Group names can be found in the ALH gui Guidance window:"
   echo "Click the G button adjacent to the group."
   echo "========================================================"
   exit
fi

export accFacility=$1
export groupName=$2

#echo fac is $accFacility
#echo group is $groupName
#printenv EPICS_CA_ADDR_LIST
#printenv EPICS_BASE
#printenv ALHCONFIGFILES

if [ "$accFacility" = "LCLS" ]; then
   echo LCLS
   export topConfig=LCLS_All.alhConfig
   if [ -d /afs/slac/g/lcls ]; then
       source /afs/slac/g/lcls/epics/setup/epicsSetup.bash
   else
       source  /usr/local/lcls/epics/setup/epicsSetup.bash
   fi
elif [ "$accFacility" = "FACET" ]; then
   echo FACET
   export topConfig=FACET_All.alhConfig
   source  /usr/local/facet/epics/setup/epicsSetup_facet.bash
elif [ "$accFacility" = "XTA" ]; then
   echo XTA
   export topConfig=XTA_All.alhConfig
   source  /afs/slac/g/acctest/epics/setup/epicsReset_acctest.bash
elif [ "$accFacility" = "SPEAR" ]; then
   echo SPEAR
   export topConfig=system.alhConfig
#  inherit the environment for SPEAR:
#  source /afs/slac/g/spear/epics/epicsReset
#  export ALHCONFIGFILES=/afs/slac/g/spear/epics/app/alh/config-spear
else
   echo valid accelerator facility not entered
   echo please specify one of these for your first parameter:
   echo LCLS, SPEAR, FACET, XTA
   exit
fi

#echo "ENABLING alarming for group $groupName - enter Y to continue, anything else to cancel."
#set reply = $<
   export reply="Y"
if [ $reply = "Y" ]; then
   echo "ENABLING alarming for group $groupName..."

   # go to the alh config directory to load config tree
   export here=`pwd`
   #pwd
   cd $ALHCONFIGFILES
   #pwd
   changeGroupFORCEPVs.pl $groupName 0 $ALHCONFIGFILES/$topConfig "default"
   cd $here
   #pwd

   echo "...done"
else
   echo "CANCELLING"
fi

# end of script
