#!/bin/bash +x

#get all pictures and video from camera and delete files from camera
gphoto2 -P
echo ""

#Set variables
JPGS="*.JPG"
AVIS="*.AVI"
BASE=/home/matt/Projects/365

# Creating folders and moving AVI files
if [ -f $AVIS ] ; then 
  for file in $AVIS
    do
      mv $file "$BASE"
  done
fi

# Creating folders and moving JPG files

for file in $JPGS
do
  DTE=$(exif "$file" | grep Date | head -n1 | cut -f2 -d'|' | cut -f1 -d' ' | tr ':' -)
  if [ ! -d "$BASE/$DTE" ] ; then
	echo "Creating folder $BASE/$DTE" && mkdir "$BASE/$DTE"
  fi
  echo "Moving $file to $BASE/$DTE"
  mv "$file" "$BASE/$DTE"/
done


#open folder for picture review
nautilus --browser "$BASE"

echo -n "Remove pictures from camera? "
read yesorno
case $yesorno in 
	y | yes ) gphoto2 -RD; echo "removed pictures from camera"
	;;
	* ) echo "did not remove pictures"
esac

echo "Operation Completed"
