#!/bin/bash # N50CH folder curation steps # by Marc, November 2017 BASEDIR=/var/naapo/scans BINDIR=$BASEDIR/bin CORES=4 cd $BASEDIR if [ $? -ne 0 ]; then exit 3 fi if [[ -z $1 ]]; then echo Kindly specify folder number. >&2 exit 3 fi case $2 in help) # help echo "options: help failsafe lower jpeg proof purge refile seq sha1" ;; failsafe) # make extra hard links to images in case I clobber them mkdir -p $BASEDIR/failsafe/folder.$1 cp -l $BASEDIR/cr2/folder.$1/* $BASEDIR/failsafe/folder.$1 echo if good, $0 $1 lower ;; lower) # change .CR2 to .cr2 rename 's/CR2/cr2/' $BASEDIR/cr2/folder.$1/*.CR2 echo if good, $0 $1 jpeg ;; jpeg) # make JPEGs using $CORES cores rm -rf $BASEDIR/jpg/folder.$1 mkdir $BASEDIR/jpg/folder.$1 cd $BASEDIR/cr2/folder.$1 ls *.cr2 | xargs -n 1 -P $CORES $BINDIR/folder_jpeg $1 cd .. echo if good, $0 $1 proof ;; pngjpeg) # make JPEGs for the old PNG scans using $CORES cores rm -rf $BASEDIR/jpg/folder.$1 mkdir $BASEDIR/jpg/folder.$1 cd $BASEDIR/png/folder.$1 ls *.png | xargs -n 1 -P $CORES $BINDIR/folder_png_jpeg $1 cd $BASEDIR/jpg/folder.$1 sha1sum *.jpg >SHA1SUM cd .. echo if good, great ;; proof) # launch eog for proofreading rm ~/.local/share/recently-used.xbel # perf killer cd $BASEDIR/jpg/folder.$1 tar c $(ls | head -n 600) | cat >/dev/null & # cache files ps aux | grep tar cd ../.. eog $BASEDIR/jpg/folder.$1 echo when good, $0 $1 purge ;; purge) # kill any .cr2 that doesn't still have a .jpg cd $BASEDIR/cr2/folder.$1 for im in *.cr2 do if [[ ! -f $BASEDIR/jpg/folder.$1/${im/.cr2/.jpg} ]]; then rm $im && echo removed $im fi done cd .. echo if good, $0 $1 refile new_folder start_at echo -- or -- $0 $1 seq ;; refile) # move all starting at a given name to another folder if [[ -z $3 ]]; then echo Kindly specify destination folder number. >&2 exit 3 fi if [[ -z $4 ]]; then echo Kindly specify first image to move. >&2 exit 3 fi mkdir -p $BASEDIR/{cr2,jpg}/folder.$3 for kind in cr2 jpg do cd $kind/folder.$1 for im in *.$kind do if [[ ! $im < $4 ]]; then mv $im $BASEDIR/$kind/folder.$3/ fi done cd $BASEDIR done echo if good, $0 $1 seq ;; seq) # renumber starting at ###-001 where ### is the folder number for kind in cr2 jpg do cd $kind/folder.$1 rename 's/^/z/' *.$kind next=1001 for im in *.$kind do mv $im $1--$((next++)).$kind done rename 's/--1/-/' *.$kind cd $BASEDIR done echo if good, $0 $1 sha1 ;; sha1) # calculate file digests for kind in cr2 jpg do cd $kind/folder.$1 sha1sum *.$kind >SHA1SUM cd $BASEDIR done echo if good, $0 $1 digs ;; digs) # collect SHA1SUM filenames into DIGESTS find . -name SHA1SUM | LC_ALL=C sort >DIGESTS echo if good, these can be archived ;; *) # unrecognized command echo Try $0 $1 help >&2 exit 3 ;; esac exit 0