#! /bin/bash # Last edited on 2003-02-05 02:57:07 by stolfi usage="${0##*/} [-rm] ROOTDIR BATCHDIR RAWDIR [ RAWNAME NEWNAME DISP COMMENT ] ... eob" # Copies the raw Mavica CD-300 images from # {ROOTDIR}/RAW/{DISKDIR}/{RAWNAME}.JPG to # {ROOTDIR}/{DISP}/{BATCHDIR}/{NEWNAME}.jpg. # # If "-rm" is given, the copies are removed instead. # # The directory {DISP}/{BATCHDIR} is created if necessary. # # The COMMENT argument is a string and it is ignored for now. remove=0; while ( [ $# -gt 0 ] && [ "/${1:0:1}" == "/-" ] ); do if [ "$1" == "-rm" ]; then remove=1; shift; else echo "usage: ${usage}"; exit 1; fi done if [ $# -lt 2 ]; then echo "usage: ${usage}"; exit 1; fi rut="$1"; shift; bat="$1"; shift; dsk="$1"; shift; groups=( ETC PRE TEC PUB ) echo "copying RAW/${dsk} -> {${groups[@]}}/${bat}" if [ ! -d ${rut} ]; then echo "${rut} not found"; exit 1; fi cd ${rut} # Ensure that directories exist: if [ ! -d RAW/${dsk} ]; then echo "directory RAW/${dsk} does not exist"; exit 1 fi for disp in ${groups[@]}; do if [ ! -d ${disp}/${bat} ]; then echo "creating directory ${disp}/${bat}" mkdir -p ${disp}/${bat} else echo "directory ${disp}/${bat} already exists" fi done function createcopy () { # Usage: createcopy RAWNAME NEWNAME DISP local lold="$1"; local lnew="$2"; local disp="$3"; # echo "createcopy ${lold} ${lnew} ${disp}" local fold="RAW/${dsk}/${lold}" local fnew="${disp}/${bat}/${lnew}" # If the image is in the wrong PUB/ETC/TEC dir, # copy it to the correct one: for alt in ${groups[@]}; do if [ "${disp}" != "${alt}" ]; then if [ -r ${alt}/${bat}/${lnew} ]; then mv -v ${alt}/${bat}/${lnew} ${fnew} fi fi done # Make the copy if [ ! -e ${fnew} ]; then cp -av ${fold} ${fnew} elif [ -f ${fnew} ]; then echo "${fnew} already exists" else echo "${fnew} already exists and is not a link" fi if [ ! -r ${fnew} ]; then echo "${fnew} seems broken"; exit 1 fi } function refilecopy () { # Usage: refilecopy NEWNAME DISP local lnew="$1"; local disp="$2"; # echo "refilecopy ${lnew} ${disp}" local fnew="${disp}/${bat}/${lnew}" # If the image is in the wrong PUB/ETC/TEC dir, # copy it to the correct one: for alt in ${groups[@]}; do if [ "${disp}" != "${alt}" ]; then if [ -r ${alt}/${bat}/${lnew} ]; then mv -v ${alt}/${bat}/${lnew} ${fnew} fi fi done if [ ! -r ${fnew} ]; then echo "${fnew} broken or missing"; exit 1 fi } function removecopy () { local lnew="$1"; # echo "removecopy ${lnew}" local disp="xxx"; for disp in ${groups[@]}; do local fnew="${disp}/${bat}/${lnew}" if [ -e ${fnew} ]; then rm -v ${fnew} else echo "${fnew} doesnt exist" fi done } while [ $# -gt 1 ]; do if [ $# -lt 4 ]; then echo "usage: ${usage}"; exit 1; fi old="$1"; shift; new="$1"; shift; dsp="$1"; shift; cmt="$1"; shift; oldsm="${old%.*}-s.${old##*.}" newsm="${new%.*}-s.${new##*.}" oldic="${old%.*}-i.${old##*.}" newic="${new%.*}-i.${new##*.}" newno="${new%.*}-n.${new##*.}" if (( ${remove} )); then removecopy ${new} removecopy ${newsm} removecopy ${newic} else createcopy ${old} ${new} ${dsp} createcopy ${oldsm} ${newsm} ${dsp} createcopy ${oldic} ${newic} ${dsp} ( refilecopy ${newno} ${dsp} ; echo ' ' ) fi done if [ ! "$1" = "eob" ]; then echo "missing 'eob', found '$1'"; exit 1; fi