#!/bin/bash
# Steps through raw cam snapshot folders and renames all .jpgs to creation time + random digits
# Only looks back at the last 490 minutes from the moment the command is run. Crontab kicks
# this off at 5am. Snapshots start at 9pm. That is 8 hours or 480 minutes worth of snapshots
# Add another 10 minutes to make it 490 minutes for good measure
# Front cam folder
find /mnt/rawsnaps/yourcamserialnumber/ -depth -mmin -490 -name "*.jpg" -exec sh -c 'mv -f "$1" "$(dirname "$1")/$(date -r "$1" +%Y-%m-%d_%H-%M-%S-%N).jpg"' _ {} \;
# Rear cam folder
find /mnt/rawsnaps/yourcameraserialnumber/ -depth -mmin -490 -name "*.jpg" -exec sh -c 'mv -f "$1" "$(dirname "$1")/$(date -r "$1" +%Y-%m-%d_%H-%M-%S-%N).jpg"' _ {} \;
# Now we need to copy all the renamed snapshots we did in the first step to the samba share.
# Bit of a hack, but we step back though directory structure limited to 490 minutes again.
# All of those files are copied to the Samba share. Would be better to simply copy the files in the
# above step to a new location after renaming to begin with instead of another dedicated step
# but what the hell...
# Front cam folder
find /mnt/rawsnaps/yourcamserialnumber/ -depth -mmin -490 -name \*.jpg | rsync -av --files-from - --no-relative / /mnt/camsnaps/$(date -d '-1 day' '+%Y-%m-%d')
# Rear cam folder
find /mnt/rawsnaps/yourcamserialnumber/ -depth -mmin -490 -name \*.jpg | rsync -av --files-from - --no-relative / /mnt/camsnaps/$(date -d '-1 day' '+%Y-%m-%d')