#!/usr/bin/env zsh
set -x
set -e
set -o nullglob

YYYYMMDD="$(date "+%Y-%m-%d")"

function downloadPhotos() {
    SRC=(/Volumes/*/DCIM)
    if [[ ! -d "$SRC" ]]; then
        echo "no photos" > /dev/stderr
        return
    fi
    DST="$HOME/Pictures/_ORIG"
    du -sh "$SRC"
    rsync -ah --no-inc-recursive --info=progress2 --remove-source-files "$SRC"/ $DST/$YYYYMMDD/
    cd "$DST/$YYYYMMDD"
    mv */* .
    f2 -r '../{{mtime.YYYY}}/{{mtime.YYYY}}-{{mtime.MM}}/{{mtime.YYYY}}-{{mtime.MM}}-{{mtime.DD}}/{{mtime.YYYY}}-{{mtime.MM}}-{{mtime.DD}}.{{x.model}}.{{f}}.{{hash.sha256}}{{ext}}' -x --verbose
}

function main() {
    # FIXME this doesn't work if there are no photos on the card but the
    # DCIM dir exists
    downloadPhotos
}

main
