#!/bin/sh

TARGETPATH=$PWD

if test $# -ge 2
then
  echo Error: too many arguments
fi

if test $# -eq 0 -o $# -ge 2
then 
  echo "Usage:   $0 <arg>"
  echo "where <arg> is the mountpoint of the memory stick. If not already mounted, $0 will mount it automatically."
  echo "Example: $0 /media/sda1"
  exit 1
fi


/bin/mount | /usr/bin/grep $1 > /dev/null
REMOUNT=$?

if test $REMOUNT -eq 1
then
  echo mount $1...
  /bin/mount $1
  if test $?
  then
    echo "Check /etc/fstab to make sure that your memory stick can be mounted to $1"
    exit 2
  fi
fi

echo Download pictures...
/usr/bin/find $1 -iname "*.jpg" -exec /bin/cp -avi {} $TARGETPATH \;   
# now check if we copied an flies. this is stupid performance-wise, but this
# script is for rookies after all. besides, how large can such a memory stick be
# anyway?!?
/usr/bin/find $1 -iname "*.jpg" 2>/dev/null | grep -i jpg > /dev/null
if test $? -eq 1
then
  echo No pictures found on memory stick
fi

echo Download short movies...
/usr/bin/find $1 -iname "*.mpg" -exec /bin/cp -avi {} $TARGETPATH \; 2>/dev/null
# dito
/usr/bin/find $1 -iname "*.mpg" 2>/dev/null | grep -i mpg > /dev/null
if test $? -eq 1
then
  echo No short movies found on memory stick
fi

cd $TARGETPATH

if test $REMOUNT -eq 1
then
  echo unmount $1
  /bin/umount $1
fi

exit 0

