#!/bin/bash
########################################################################
# filename:	playWxFor [<ZONE>]
#
# description:	This script will play the weather forecast audio files
#		that get created by the getWxFor script.
#
# history:
# script based upon kc6hur playWxRpt
# Modified by w0anm for changes see below
# $Id: playWxFor 34 2009-01-14 18:56:08Z  $
########################################################################

# 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/forecast/$ZONE ] ; then
    # msg to log file.
    log "ZONE directory /home/irlp/audio/custom/wx/forecast/$ZONE is not present, aborting..." 
    exit 1
fi

if [ -f ${CUSTOM}/custom_wavplay ] ; then
    ${CUSTOM}/custom_wavplay custom/wx/forecast/$ZONE/forecast &> /dev/null 2>&1
else
    /usr/sbin/asterisk -rx "rpt localplay 27539 /custom/wx/forecast/$ZONE/forecast" &> /dev/null 2>&1
fi

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

exit 0
