#!/bin/sh
set -e
c=0
find . -mindepth 1 -maxdepth 1 -type f \
    | grep '....-..-.._' \
    | cut -b 1-19 \
    | sort -u \
    | while read line
do
    things="$(findimagedupes -t 95% -- $line*)"
    [ -z "$things" ] && continue
    c=$(( c + 1 ))
    ls -1l $things \
        | awk '{ print $5" "$9  }' \
        | sort -nr \
        | cut -d" " -f2- \
        | while read thing
        do
            mkdir -p set-$c
            if [ -z "$PICK" ]
            then
                PICK=$thing
                echo pick set-$c/1-$(basename $PICK)
                mv $PICK set-$c/1-$(basename $PICK)
            else
                echo discard set-$c/2-$(basename $thing)
                mv $thing set-$c/2-$(basename $thing)
            fi
        done
        PICK=
done
