#!/bin/sh

# Play audio script for ClockChimes

# Copyright 2018 - Stu Miller - Colorado, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# version text
VERSION="\
  clockchimes-0.3
  Copyright 2018 - Stu Miller - Colorado, USA
  All rights reserved."
# END version text

# conf help
CONF_HELP="\
  --conf        configure $CONF_FILE, 4 arguments required
                  1) chime name: (e.g. westminster, whittington)
                  2) play chime: yes/no
                  3) play strike: yes/no
                  4) volume factor: (e.g. 0.8, 1.2)
                EXAMPLE: clockchimes --conf westminster yes yes 0.8
                NOTE: --conf must run as root user"
# END conf help

# cron help
CRON_HELP="\
  --cron        update $CRON_FILE
                NOTE: --cron must run as root user"
# END cron help

# test help
TEST_HELP="\
  --test        test configuration, 2 arguments required
                  1) hour: integer from 0 to 24 (e.g. 1, 01, ... 12, ... 24) 
                  2) minute: integer from 0 to 45 (i.e. 0, 00, 15, 30, 45) 
                EXAMPLE: clockchimes --test 06 00
                NOTE: only minutes 00, 15, 30 or 45 produce sounds"
# END test help

# help text
HELP="\
Play clock chimes and hour strikes.
Usage: $0 [OPTION]

$CONF_HELP

$CRON_HELP

  --help        display this help and exit

  --run         used by cron job & test, see --test for manual operation

$TEST_HELP

  --version     display version information and exit

Report bugs to <slackbuilds@go4it2day.com>."
# END help text

# prefix volume factor & sound directory
PRE_SOUND="-v "${CONTROL[3]}" "$SOUND_DIR

# conf file
CONF_FILE="${CONF_DIR}clockchimes.conf"

# cron file
CRON_FILE="${CRON_DIR}clockchimes"

# cron text
CRON_TXT="
# clockchimes
0,15,30,45 * * * * ${SCRIPT_DIR}clockchimes --run 1> /dev/null"
# END cron text

# system minute
MINUTE=$(date +"%M")

# system hour, 12 hour clock
HOUR=$(date +"%I")

# loop counter, strip leading "0" from system hour
LOOP=$((10#$HOUR))
