Took care of some repetitive tasks via functions.
Code Select
#!/bin/bash
echo "Unload_camera version 3.1: This script will remove images and videos from your camera."
echo "Basic script by GrouchyGaijin. Heavy lifting by schragge. Additional modifications by cortman, steeldriver, and ofnuts"
echo "Run this script from the camera"
now=$(date +"%d-%b-%Y-%T")
mkdir /path/to/where/you want/the/pictures/put/$now
echo "Making directory to hold the photos."
dir="/path/to/clips/directory"
read -p "Press Enter to check if the clips directory is empty"
if [ "$(ls -A $dir)" ]; then
echo "Clips is not empty. Did you forget to empty it last time?"
fi
echo "If files were found type yes to empty the directory"
read x
if [ "$x" = "yes" ]
then
rm -f "$dir"/*
else
echo "OK, Leaving the directory as is."
fi
pics_dir="/path/to/$now"
clips_dir="/path/to/clips"
process_image() {
echo Resizing "$1"
gm mogrify -resize 720x720 "$1"
echo Moving "$1" to $pics_dir
mv "$1" "$pics_dir"
}
process_video() {
echo Moving "$1" to $clips_dir
mv "$1" "$clips_dir"
}
process_thumbnail() {
echo Removing "$1" from the camera
rm "$1"
}
unload() {
case $1 in
image) pattern='*.jpg *.JPG *.png *.PNG *.GIF *.gif';;
video) pattern='*.MOV *.mov *.mpg *.MPG *.mpeg *.mp4';;
thumbnail) pattern='*.THM';;
*) echo Unknown file type, aborting...; exit 1;;
esac
echo Press Enter to search for $1 files; read start
unset found
for i in $pattern; do
if [[ -f $i ]]; then
[[ -v found ]] || echo ${1^}s found.
: ${found:-set}
process_$1 "$i"
else
echo Skipping $i: not a regular file
fi
done
[[ -v found ]] || echo No or no additional ${1}s found.
}
shopt -s nullglob
unload image
unload video
unload thumbnail