#!/bin/bash

while [ ! -z "$1" ] ; do
export i="$1"

##echo "$i"
  case "$1" in
	*.jpg|*.Jpg|*.JPG|*.png|*.PNG)
	;;
	-r|-rename)
	rename=yes
	shift
	continue
	;;
  esac

  x=$( read a b < <( exiftool -CreateDate "$i" | cut -f2- -d: )   
	echo $( echo $a | sed 's@:@-@g' ) $b
     )
##echo $x
  case "$x" in
	""|19*)
	shift
	continue
	;;
	*)
	;;
  esac

  ##echo touch -d "$x" "$i"
  touch -d "$x" "$i"

  if [ "$rename" = "yes" ]; then
    d=$( echo $x | sed 's@-@@g' | sed 's@:@@g' | sed 's@ @-@g' )
    mv "$i" "$d"-"$i"
  fi

  shift

done

