#!/bin/bash

#######################################
# MODIFICATIONS TO WAVPLAY SCRIPT TO STOP IT KEYING OVER QSO'S.
# COSCHECK ONLY WAITS 30 SECONDS, THEN KEYS ANYWAY.
#
# Customised to locate audio files in ~/audio/custom
#######################################
#
# Modified for Debian version of sox.  30-12-2020 VK2YLD
#

#Plays WAV files with check for COS, key, .5 second delay, unkey

# Make sure we are user repeater!!!
if [ `/usr/bin/whoami` != "repeater" ] ; then
  echo This program must be run as user REPEATER!
  exit 1
fi

# Make sure we have sourced the environment file
if [ "$RUN_ENV" != "TRUE" ] ; then
  echo "You must source the environment file first. Do this by running:"
  echo ". /home/irlp/custom/environment"
  exit 1
fi

if [ "$#" = "0" ] ; then exit 1; fi

# echo " called with the following.. "$@     # DEBUG....

AUDIO=/home/irlp/audio/custom

#Converts audio to nice congruent audio, without gaps, if there is more
#than one argument in the script.

  while [ -n "$1" ];do
    WAVFILES="$WAVFILES $AUDIO/$1.wav"
    shift
  done

# echo "Files are..- "$WAVFILES             # DEBUG....

/usr/bin/sox $WAVFILES -e floating-point $RUN/wavefile.wav

$BIN/coscheck
$BIN/coscheck
$BIN/coscheck
$BIN/coscheck
$BIN/coscheck
$BIN/coscheck
$BIN/coscheck
$BIN/coscheck
$BIN/coscheck
$BIN/coscheck
$BIN/key

sleep 0.5

/usr/bin/aplay $RUN/wavefile.wav  >/dev/null 2>&1

sleep 0.5

$BIN/unkey

rm -f $RUN/wavefile.wav

exit 0

