#!/bin/bash -
#===============================================================================
#
#         FILE: check_missing
#
#        USAGE: ./check_missing [start] [end]
#
#  DESCRIPTION: Looks for missing audio files in the upload area and in the
#  		upload journal on the VPS. The upload area is on the VPS at
#  		/var/IA/uploads and the journal is (currently) in
#  		~dave/IA/ias3uploads.jnl
#
#      OPTIONS: ---
# REQUIREMENTS: ---
#         BUGS: ---
#        NOTES: ---
#       AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
#      VERSION: 0.0.1
#      CREATED: 2015-06-14 13:07:23
#     REVISION: 2015-06-14 13:08:07
#
#===============================================================================

set -o nounset                              # Treat unset variables as an error

SCRIPT=${0##*/}
DIR=${0%/*}

#
# Where the tools are
#
BASEDIR="$HOME/IA"

#
# For the moment the files for uploading are in two places
#
UPLOADS="/var/IA/uploads"

#
# Where the journal is
#
JNL="$BASEDIR/ias3upload.jnl"

#
# Default episode range
#
START=${1:-1300}
END=${2:-1799}

#
# Go looking for missing stuff
#
for (( i=${START}; i<=${END}; i++ ))
do
    if [ ! -e "$UPLOADS/hpr$i.wav" ]; then
	if ! grep -q "hpr$i.wav" $JNL; then
	    echo "Missing hpr$i.wav";
	fi;
    fi;
done

exit