#! /bin/bash

# Downloads pictures from a digital camera using gphoto2,
# moves them with move-digiphotos.sh and optionally deletes
# them from the camera's memory.
#
# This script was originally written and put into
# Public Domain by Jarno Elonen <elonen@iki.fi> in June 2003.
# Feel free to do whatever you like with it.

TMPDIR=/home/jarno/gfx/tmp

if [ ! -d "$TMPDIR" ]; then
  echo "*** Error: download directory '$TMPDIR' does not exist, aborting."
  exit 1
fi
pushd "$TMPDIR" &> /dev/null

gphoto2 -P
if [ $? != 0 ]; then
  echo "*** error executing gphoto2, aborting."
  popd &> /dev/null
  exit 1
fi

move-digiphotos

echo
echo -n "Delete pictures from camera? [y/N] "
read x
if [ $x == "y" ]; then
  gphoto2 -D
fi
if [ $? != 0 ]; then
  echo "Warning: error executing gphoto2."
  popd &> /dev/null
  exit 1
fi

echo "Done."
popd &> /dev/null
