#!/bin/bash -e ## @id $Id$ ## 1 2 3 4 5 6 7 8 ## 45678901234567890123456789012345678901234567890123456789012345678901234567890 # configuration ########################################################## prefix="@prefix@" test -e "@sysconfdir@/mvfotos.conf" && . "@sysconfdir@/mvfotos.conf" test -e ~/.mvfotos && . ~/.mvfotos # end of configuration ################################################### if test -z "${target}" -o ! -d "${target}"; then echo "Please configure $1 in " 1>&2 echo "@sysconfdir@/mvfotos.conf or in ~/.mvfotos" 1>&2 exit -1 fi cmd="mv -n" test=no globalprefix= globaltype= while [ $# -gt 0 ]; do if [ "$1" == "-c" ]; then cmd="cp -n" elif [ "$1" == "--test" ]; then test=yes elif [ "$1" == "-t" ]; then globaltype="$2" shift elif [ "$1" == "-p" ]; then globalprefix="$2" shift elif [ "$1" == "-h" ]; then echo "$0 [-p prefix] [-c] file [...]]" echo echo "OPTIONS" echo " -p prefix specify name prefix" echo " -c copy instead ov move" echo " -t type overwrite file name extension" echo " --test test only" exit 0 else postfix=$(basename "$1" | tr '[:upper:]' '[:lower:]' | sed 's/[ ]/_/g') type=${globaltype:-${postfix##*.}} date= if [ "${exif//${type}/}" != "$exif" ]; then date=$(exif -t 0x132 "$1" | sed -n 's/.*Value: \([0-9]*\):\([0-9]*\):\([0-9]*\) \([0-9]*\):\([0-9]*\):\([0-9]*\)/\1\2\3-\4\5\6/p' | uniq) if [ -z "$date" ]; then date=$(exif -t 0x9003 "$1" | sed -n 's/.*Value: \([0-9]*\):\([0-9]*\):\([0-9]*\) \([0-9]*\):\([0-9]*\):\([0-9]*\)/\1\2\3-\4\5\6/p' | uniq) fi if [ -z "$date" ]; then date=$(exiftool -FileModifyDate "$1" | sed -n 's/.*File Modification Date\/Time.*: \([0-9]*\):\([0-9]*\):\([0-9]*\) \([0-9]*\):\([0-9]*\):\([0-9]*\)[^0-9]*.*/\1\2\3-\4\5\6/p' | uniq) fi fi if [ -z "$date" ]; then date=$(stat -c%y "$1" | sed 's/\(....\)-\(..\)-\(..\) \(..\):\(..\):\(..\).*/\1\2\3-\4\5\6/') fi if [ -z "$date" ]; then echo "**** $0: CANNOT EVALUATE: $1" 1>&2 shift break fi year=$(echo "$date" | sed 's/\(....\)....-.*/\1/') month=$(echo "$date" | sed 's/....\(..\)..-.*/\1/') day=$(echo "$date" | sed 's/......\(..\)-.*/\1/') if [ "$month" -lt 3 -o "$month" -eq 3 -a "$day" -lt 21 ]; then season=winter elif [ "$month" -lt 6 -o "$month" -eq 6 -a "$day" -lt 21 ]; then season=fruehling elif [ "$month" -lt 9 -o "$month" -eq 9 -a "$day" -lt 21 ]; then season=sommer elif [ "$month" -lt 12 -o "$month" -eq 12 -a "$day" -lt 21 ]; then season=herbst else season=jahresende fi found=no for ((i=1; i<=$num; ++i)); do if [ "${ext[$i]//$type/}" != "${ext[$i]}" ]; then found=yes break fi done if [ $found = "no" ]; then echo "**** $0: UNKNOWN FYLE TYPE ($type): $1" 1>&2 shift break fi path="${target}/${path[$i]}/${year}/${year}_${season}" if test -z "$globalprefix"; then prefix=${prefix[$i]} else prefix=${globalprefix} fi test -d "path" || mkdir -p "$path" echo "$cmd $1 ${path}/${date}-${prefix}-${postfix}" if test -e "${path}/${date}-${prefix}-${postfix}"; then echo "WARNING: target already exists, ignored" else if test "$test" != "yes"; then $cmd "$1" "${path}/${date}-${prefix}-${postfix}" if which exiftran > /dev/null; then if [ "${exif//${type}/}" != "$exif" ]; then echo "exiftran -aip ${path}/${date}-${prefix}-${postfix}" exiftran -aip "${path}/${date}-${prefix}-${postfix}" fi fi fi fi clipinf="${1/STREAM/CLIPINF}" clipinf="${clipinf%.*}.CPI" if test -f "$clipinf"; then path="${target}/${path[$cpi]}/${year}/${year}_${season}" echo "$cmd $clipinf ${path}/${date}-${prefix}-${postfix%.*}.cpi" if test -e "${path}/${date}-${prefix}-${postfix%.*}.cpi"; then echo "WARNING: target already exists, ignored" else if test "$test" != "yes"; then test -d "path" || mkdir -p "$path" $cmd "$clipinf" "${path}/${date}-${prefix}-${postfix%.*}".cpi fi fi fi fi shift done