#!/bin/bash
#==============================================================
#  Name:  luGWSetSector
#
#  Rem:   This script sets the sector to EPICS or SLC control,
#         rebuilds the gateway configuration, and restarts the gateway
#
#         It is terribly ugly that we restart the soft ioc each
#         time. It is because the CA connections to soft iocs on
#         dev die after a short time for a prod (or semi-prod) client. 
#
#  Usage: luLaunchGWConfig <loca> <set>
#
#  Arguments: loca - Sector name, for example LI28
#             set  - 1 if setting to EPICS, 0 to SLC
#
#--------------------------------------------------------------

loca=`echo $1 | tr '[:upper:]' '[:lower:]'`

LOCA=`echo $1 | tr '[:lower:]' '[:upper:]'`

val=`echo $2`

echo Setting ${LOCA} PV Gateway mode...

caput SIOC:${LOCA}:1:CAMAC_CTRL ${val}

echo  Building PV gateway config...

luBuildGWConfig

sleep 10

echo  Restarting PV gateway...

luRestartGateway

exit 0

