#!/bin/bash PARENT='/photo/pictures/' cd $PARENT extra=$1 start=20000 mount=/dev/sdd1 sudo mount $mount /mnt/camera if [ $? -ne 0 ]; then echo "no camera to mount?" exit 1 fi ls -l /mnt/camera for n in "101ncd70" "102ncd70" "103ncd70" "101nd300" "102nd300" "103nd300" do if [ -d /mnt/camera/dcim/${n}/ ]; then echo "******************************************************"; echo "you have images in ${n}! fsck!" echo "******************************************************"; # umount /mnt/camera # exit; fi done for n in "100ncd70" "101ncd70" "100nikon" "102ncd70" "103ncd70" "100nd300" "101nd300" "102nd300" "103nd300" do echo "trying /mnt/camera/dcim/${n}/"; if [ -d /mnt/camera/dcim/${n}/ ]; then d300=`echo ${n} | grep nd`; echo "rsync -rtuv /mnt/camera/dcim/${n}/ $PARENT" rsync -rtuv /mnt/camera/dcim/${n}/ $PARENT fi done sudo umount $mount if [[ $d300 ]]; then start=0; fi export START=$start echo "start is :$start:" # normalize, just in case for i in _DSC* _01C* do if [[ -e $i ]]; then new=`echo $i | tr A-Z a-z` echo "mv $i $new" mv $i $new fi done for i in *.jpg *.nef *.tif do # avoid trying to process the literal "*.jpg" if [ ! -e $i ]; then echo "*** no files to process?" continue fi # normalize the filename new=`echo $i | sed -e 's/_//'` new=`echo $new | perl -pne 's/(dscn?|01c)(\d+)(\.\w+)/$1 . sprintf("%.5d", $2) . $3/e; chomp'` #big=`echo $new | grep -v dscn | perl -pne 'm/(dscn?)(\d+)(\.\w+)/; $a = ($2 < 9996 ? "1" . sprintf("%.4d", $2) : $2); $_ = "$1$a$3"'` big=`echo $new | grep -v dscn | perl -pne 'm/(dscn?|01c)(\d+)(\.\w+)/; $a = ($ENV{START} + $2); $_ = sprintf("%s%.5d%s", $1, $a, $3)'` if [[ $big ]]; then final=$big else final=$new fi new=$final echo "moving $i to $new"; mv -f $i $new # protect chmod 0444 $new # timestamp the file with the exif date time=`exiftool -d '%c' -DateTimeOriginal $new | sed 's/.* ://'` touch -d "$time" $new # make /pictures/YYYY-MM and /pictures/raw/YYYY-MM dir=`date -d "$time" +"%Y-%m"` if [ ! -z $extra ]; then dir="$extra/$dir" #echo "using dir pattern '$extra' to generate $dir" fi if [ ! -d $dir ]; then mkdir -p $dir fi if [ ! -d raw/$dir ]; then mkdir -p raw/$dir fi jpg=`echo $new | sed -e s/nef/jpg/` if [ $new == $jpg ]; then # jpg processing if [ -e $dir/$new ]; then echo "removing $new - $dir/$new exists?" rm -f $new else # rotate #exifautotran $new # retouch, since exifautotran nuked the time touch -d "$time" $new mv -f $new $dir chmod 0444 "$dir/$new" fi else # nef processing if [ -e raw/$dir/$new ]; then echo "removing $new - raw/$dir/$new exists?" rm -f $new else if [ -e ${PARENT}${dir}/$jpg ]; then echo "$jpg exists, skipping raw conversion..." else # batch process ufraw --batch --wb=camera \ --curve=camera \ --out-type=jpeg \ --compression=95 \ --saturation=1.5 \ --out-path=${PARENT}${dir} $new neftags2jpg $new ${PARENT}${dir}/$jpg # protect chmod 0444 ${PARENT}${dir}/$jpg # stamp touch -d "$time" ${PARENT}${dir}/$jpg fi # move the nef file mv -f $new raw/$dir fi fi done cd -