#!/bin/bash
########################################################################
#
#
# filename:	playWxSkywarn
#
# description:	This script will play if skywarn spotters will be needed
#                based upon getWxSkywarn script. 
#
# $Id: playWxSkywarn 31 2009-01-05 02:52:02Z  $
########################################################################

# Load config file

if [ -f ${CUSTOM}/wx_scripts.conf ] ; then
    source ${CUSTOM}/wx_scripts.conf
else
    echo "Missing ${CUSTOM}/wx_scripts.conf file, aborting..."
    exit 1
fi

if [ $ACTIVE_PLAY = "FALSE" ] ; then
    if [ -f ${LOCAL}/active ] ; then
       echo "${0##*/}: ERROR - Node is busy, must be idle to run."
       exit 1
    fi
fi

if [ $ACTIVE_PLAY = "FALSE" ] ; then
    touch ${LOCAL}/active
fi

# multiple zone support.
# if ZONE  not an argument, then use what is defined in configure file.
if [ "$1" = "" ] ; then
    ZONE=$ZONE
else
    ZONE=$1
fi

# if argument is not a directory, abort and do nothing. send error
if [ ! -d /home/irlp/audio/custom/wx/skywarn/$ZONE ] ; then
    # msg to log file.
    log "ZONE directory $ZONE is not present, aborting..." 
    exit 1
fi

if [ -f ${CUSTOM}/custom_wavplay ] ; then
    ${CUSTOM}/custom_wavplay custom/wx/skywarn/$ZONE/spotter &> /dev/null 2>&1
else
    ${SCRIPT}/wavplay custom/wx/skywarn/$ZONE/spotter &> /dev/null 2>&1
fi

if [ $ACTIVE_PLAY = "FALSE" ] ; then
    rm ${LOCAL}/active
fi

exit 0
