#!/bin/bash
#
# exifstamp 
#
# Reads EXIF data of photo and changes date/time of file to be same as the shooting date/time.
# Depends on "exiftool" package.
# GPL3.  Author: Arto Jääskeläinen.
#
# v1.0	3.10.2014/Arto	Initial version
#
#################################################################################################################

if ! [ $(which exiftool) ]; then 
echo "Error: Please install \"exiftool\" first (Ubuntu: \"sudo apt-get install libimage-exiftool-perl\" )."
exit 1
fi

for file in ./*.[jJ][pP][gG]; do
	exif_date=$(exiftool "-DateTimeOriginal" "$file" | grep : | cut -d ':' -f2-6 |tr -d ': ' |sed 's/..$/.&/')
	if [ "$exif_date" != "" ] && [ ${#exif_date} = 15 ]; then 
		touch -t $exif_date "$file"
		if [ $? ]; then echo "$file  $exif_date  ok"; else echo "$file failed"; fi
	fi
done


