#! /bin/bash -norc
#==============================================================
#
#  Abs:  disables alarming for specified branch of the
#        alarm handler tree
#
#  Name: disableALHGroup.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 is spear, lcls, facet, etc.
#--------------------------------------------------------------
#
if [ $# -lt 2 ]; then
   echo "=========================================================="
   echo "Please specify a group name."
   echo "Optionally, specify a CATER number as the second parameter"
   echo "Group names can be found in the ALH gui Guidance window:"
   echo "Click the G button adjacent to the group."
   echo "=========================================================="
   exit
fi

# set environment
export accFacility=$1

#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 $#

#   echo "DISABLING alarming for group $1 - enter Y to continue, anything else to cancel."
#   set reply = $<
export alrmGroup=$2
if [ $# -gt 2 ]; then
   export caterNum=$3
else
   export caterNum=default
fi
echo $alrmGroup
echo CATERNUM IS $caterNum

export reply="Y" 
if [ $reply = "Y" ]; then
   echo "DISABLING alarming for group $1..."
      
   # go to the alh config directory to load config tree
   export here=`pwd`
   #pwd
   cd $ALHCONFIGFILES
   #pwd
   changeGroupFORCEPVs.pl $alrmGroup 1 $ALHCONFIGFILES/$topConfig $caterNum
   cd $here
   #pwd

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

# end of script
