#! /bin/bash # Last edited on 2003-07-20 20:42:50 by stolfi usage="${0##*/} [-rm] BATCHDIR DISKDIR [ RAWNAME NEWNAME DISP COMMENT ] ... eob" # Creates actual copies of the raw Mavica CD-300 images # RAW/{DISKDIR}/{RAWNAME}.JPG and places them # {DISP}/{BATCHDIR}/{NEWNAME}.jpg. Also copies the small # ("{NEWNAME}-s.JPG"), enhanced ("{NEWNAME}-s.JPG"), and iconic # ("{NEWNAME}-i.JPG") versions of those images. # # 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 3 ]; then echo "usage: ${usage}"; exit 1; fi bat="$1"; shift; dsk="$1"; shift; disps=( ETC PRE TEC PUB ) pwd echo "copying RAW/${dsk} -> {${disps[@]}}/${bat}" # Ensure that directories exist: if [ ! -d RAW/${dsk} ]; then echo "directory RAW/${dsk} does not exist"; exit 1 fi function createbatchdir () { # Usage: createbatchdir DISP local disp="$1"; if [ ! -d ${disp}/${bat} ]; then echo "creating directory ${disp}/${bat}" mkdir -p ${disp}/${bat} fi } function createcopy () { # Usage: createcopy RAWNAME NEWNAME DISP local lold="$1"; local lnew="$2"; local disp="$3"; local fold="RAW/${dsk}/${lold}" local fnew="${disp}/${bat}/${lnew}" # Ensure that batch directory exists: createbatchdir ${disp} # If the copy is in the wrong PUB/ETC/TEC dir, # move it to the correct one: for alt in ${disps[@]}; do if [ "${disp}" != "${alt}" ]; then if [ -r ${alt}/${bat}/${lnew} ]; then mv -v ${alt}/${bat}/${lnew} ${fnew} fi fi done # Create 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 removecopy () { # Usage: removecopy NEWNAME local lnew="$1"; local disp="xxx"; for disp in ${disps[@]}; do local fnew="${disp}/${bat}/${lnew}" if [ -e ${fnew} ]; then rm -v ${fnew} else echo "${fnew} doesnt exist" fi done } # Loop on arguments: 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##*.}" olden="${old%.*}-e.${old##*.}" newen="${new%.*}-e.${new##*.}" if (( ${remove} )); then removecopy ${new} removecopy ${newsm} removecopy ${newic} removecopy ${newen} else createcopy ${old} ${new} ${dsp} createcopy ${oldsm} ${newsm} ${dsp} createcopy ${oldic} ${newic} ${dsp} createcopy ${olden} ${newen} ${dsp} fi done if [ ! "$1" = "eob" ]; then echo "missing 'eob', found '$1'"; exit 1; fi