#!/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 18 2008-04-02 21:17:04Z kovacs $
########################################################################
CUSTOM="/scripts/wx"
# 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_FOR=$ZONE
else
    ZONE_FOR=$1
fi

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

sudo /usr/sbin/asterisk -rx "rpt localplay 2090 /audio/wx/forecast/$ZONE_FOR/forecast" 


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

exit 0
