#!/usr/local/bin/bash
# $Id: exifcopy,v 1.8 2025/07/12 03:09:12 grog Exp $
# Usage:
#
# exifcopy [-r]  src dest
# Copy complete EXIF data from src to dest.
# If -r is set, reset the orientation to normal.
#
# src is literal, the script doesn't try to outguess.
# See exifcopy for guesswork.
ECHO=
# Debug
# ECHO=echo
if [ "$1" = '-r' ]; then   # kill rotation
  ROT='-orientation='
  shift
fi
if [ $# -lt 2 ]; then
  echo Usage: $0 src dst ...
  exit 1
fi
BASENAME=`basename $1 .ORF`
SRC=$1
while :; do
  shift
  if [ "$1" = "" ]; then
    exit
  elif [ "$1" = "$SRC" ]; then
    echo "Skipping copy to source file"
  fi
  BASENAME=`basename $SRC`
  if [ "${BASENAME:0:1}" = "A" ]; then # remove existing Exif data
    echo exiftool -all= $1
    exiftool -all= $1
  fi
  echo exiftool -overwrite_original_in_place -TagsFromFile $SRC '-all>all' -title=$BASENAME $ROT $1
  $ECHO exiftool -overwrite_original_in_place -TagsFromFile $SRC '-all>all' -title=$BASENAME $ROT $1
  $ECHO touch -r $SRC $1
done
