#!/bin/sh

test -e /usr/bin/exif || exit 1

set -e


echo -n "time shift in hours (without leading '+', default 0): "
read shift
if [ "$shift" == "" ]
then
	shift="0"
fi

echo -n "filename suffix (leave blank for none): "
read suffix


for i in $(ls *.[jJ][pP][gG])
do
	# date from exif tags, convert first two ':' to '-'
	# e.g. 2006:11:25 02:07:27  ->  2006-11-25 02:07:27
	exifdate=$(exif $i | grep Date | head -1 | cut -d '|' -f2 | sed 's/:/-/' | sed 's/:/-/')
	# convert date to seconds since 1970-01-01 00:00:00 UTC
	date=$(date -d "$exifdate" "+%s")
	# add/subtract time shift
	name=$(echo "$date + ($shift * 60 * 60)" | bc)
	# rename image to 'SecondsSuffix.jpg'
	mv -v "$i" "$name$suffix.jpg"
done

