#!/bin/bash -f
function usage {
echo "
   isLCLS emits 0 or 1 on stdout depending on whether you are on any LCLS
   network. 1 = LCLS network; 0 = not on an LCLS network. Note LCLS-CA 
   is one of the LCLS networks. 
 
   Usage: isLCLS [-h]

   Options: -h prints this help.

   Arguments: There are presently no available arguments.

   Examples:
 
      [physics@lcls-srv01 /home/softegr/greg]$ isLCLS
      1

      [lcls-prod02]:greg/tmp/lem> isLCLS
      0
"
# ===================================================================
#   Auth: 11-Aug-2010, Greg White (greg@slac.stanford.edu)
#   Rev: 
# ===================================================================
}
# Process options
while getopts h opt
do
   case "$opt" in
       h) usage; exit 0 ;;
       *) echo "Unknown Arguments, see isLCLS -h"; exit 1;;
   esac
done
shift $((OPTIND-1))

# SLAC LCLS is defined by 172.27.*.*. See cando. 
SLAC_LCLS='172\.27\.'

# Acquire the ethernet 0 interface address, grep it for the IPv4 address
# (this is why it's 'inet addr' not just 'inet'. Cut out the IP address,
# which follows the first ':'.
hostinet4add=`/sbin/ifconfig eth0 | awk '/inet addr/ {print $2}' | cut -d ':' -f 2`

# Invert the result of the eqrep, since egrep will emit 0 
# if there *was* a match, and 1 if there was not a match. 
echo $hostinet4add | egrep "$SLAC_LCLS" >/dev/null ; expr $? == 0
