#!/usr/bin/env bash
# Copyright Ken Fallon - Released into the public domain. http://creativecommons.org/publicdomain/ 
#============================================================

assets_db="assets_202410181601.csv"
total="$( wc -l assets_202410181601.csv | awk '{print $1}' )"
count=1
awk '{print $2}' "${assets_db}" | grep -E 'ogg|spx|mp3' | while read this_asset_name
do
  this_asset="/mnt/data/HPR/${this_asset_name}"
  #echo -ne "\r$(\date "+%Y-%m-%d %H:%M:%S") The scanner lid is CLOSED.                        \r"
  if [ ! -s "${this_asset}" ]
  then
    echo "ERROR: \"${this_asset}\" missing."
  else
    this_size="$( ls -al "${this_asset}" | awk '{print $5}' )"
    this_sha1sum="$( sha1sum "${this_asset}" | awk '{print $1}' )"
    if [ "$( grep -cE "${this_asset_name}.*${this_size}.*${this_sha1sum}" "${assets_db}" )" -ne 1 ]
    then
      echo "ERROR: \"${this_asset}\" incorrect properties."
    fi
  fi
  echo -ne "\rProcessing ${count} of ${total}"
  count=$((count+1))
done

exit
