#!/usr/local/bin/bash
# This needs bash for the trickery at the end.
# $Id: HDRmatic,v 1.8 2025/07/26 02:23:26 grog Exp $
# Rename files for Panomatix
# Use: $0 [-d work-directory] [-r] [files]
# Use all files in subdirectory C by default
# Use -r to recover files already converted
if [ "$1" = "-d" ]; then
  HDR4=$2
  shift
  shift
else
  HDR4=/Photos/6-HDR
fi
if [ "$1" = "-r" ]; then
  RECOVER=yes
  shift
fi
FILES=$*
# Do the conversion unless we're recovering a previous conversion.
if [ "$RECOVER" = "" ]; then
  rm -rf ${HDR4}
  mkdir -p ${HDR4}
  if [ "$FILES" = "" ]; then
    for i in C/*EV*; do
      if [ ! -e ${i/??EV/} ]; then 
	ln $i $HDR4
      fi
    done
  else
    ln $FILES $HDR4
  fi
  if [ $? -ne 0 ]; then
    exit 1
  fi
  echo Run Photomatix, then press return.
  espeak "Run Photomatix, then press return"
  read nothing
fi
for i in $HDR4/P*/*EV*g; do
  mv $i C/`basename ${i/+0EV*jpg/.jpeg}`
done
for i in $HDR4/P*/*EV*f; do
  mv $i C/`basename ${i/+0EV*tif/.tiff}`
done
espeak "HDR conversion done"
