#!/usr/local/bin/bash
#
# Gootag specified files
#
# $Id: geotag,v 1.12 2025/07/04 02:20:18 grog Exp $
#
if [ "$PHONE" = "" ]; then
  if [ "$1" != "" ]; then
    ME=$1
  else
    ME=`whoami`
  fi
  if [ "$ME" = "yvonne" ]; then
    export PHONE=fossil
  else
    export PHONE=albo
  fi
fi
TRACKLOG=/src/GPS/Tracklogs/Phones/GPSLogger/$PHONE
MYDIR=`pwd`
GPSLOG=$TRACKLOG/`basename $MYDIR`.gpx
echo GPSLOG $GPSLOG
if [ $# -eq 0 ]; then
  echo "Usage:"
  echo ""
  echo "$0 [-t tagfile] files..."
  echo "   tagfile defaults to the first found of:"
  echo "   $TRACKLOG/`basename $MYDIR`.gpx"
  echo "   orig/gpslog"
  echo "   orig/hirse.gpslog"
  echo "   orig/enzian.gpslog"
  echo "   orig/taskumatti.gpslog"
  exit
fi
if [ "$1" = "-t" ]; then
    GPSLOG=$2			# with no error checking
    shift 2
fi
# This is really for backwards compatibility.
if [ ! -e "$GPSLOG" ]; then
  for i in albo hirse fossil enzian taskumatti; do
    G=orig/$i.gpslog
    if [ -e "$G" ]; then
      GPSLOG=$G
      break
    fi
  done
fi
if [ ! -e "$GPSLOG" ]; then
    echo "Can't find a GPS log file"
    exit 1
fi
echo exiftool -geotag=$GPSLOG $*
exiftool -geotag=$GPSLOG $*
exiftime $*			# set modification timestamps again
for i in $*; do
    echo rm ${i}_original
    rm ${i}_original
done
espeak "geo tagging done!"
