#! /bin/bash # Last edited on 2003-07-20 20:42:20 by stolfi usage="${0##*/} [-rm] BATCHDIR DISKDIR [ RAWNAME NEWNAME DISP COMMENT ] ... eob" # Create symbolic links {DISP}/{BATCHDIR}/{NEWNAME}.jpg # to the raw Mavica CD-300 # images RAW/{DISKDIR}/{RAWNAME}.JPG. Also creates symlinks to # the small # ("{NEWNAME}-s.JPG"), enhanced ("{NEWNAME}-s.JPG"), and iconic # ("{NEWNAME}-i.JPG") versions of those images. # # If "-rm" is given, the links are removed instead. # # The directory {DISP}/{BATCHDIR} is created if necessary. # The {COMMENT} is a string and 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 # Ensuring a symlink from ${disp}/${bat} to RAW/${dsk}: if [ ! -r ${disp}/${bat}/${dsk} ]; then echo "${disp}/${bat}/${dsk} -> ../../../RAW/${dsk}" ( cd ${disp}/${bat} && ln -s ../../../RAW/${dsk} ) fi if [ ! -r ${disp}/${bat}/${dsk} ]; then echo "link ${disp}/${bat}/${dsk} seems broken"; exit 1 fi } function createlink () { # Usage: createlink 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 and necessary symlink exist: createbatchdir ${disp} # If the link 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 link: if [ ! -e ${fnew} ]; then echo "${fnew} -> ${dsk}/${lold}" ( cd ${disp}/${bat} && ln -s ${dsk}/${lold} ${lnew} ) elif [ -L ${disp}/${bat}/${lnew} ]; then echo "${fnew} already exists" else echo "${fnew} already exists and is not a link" fi if [ ! -r ${fnew} ]; then echo "link ${fnew} seems broken"; exit 1 fi } function removelink () { # Usage: removelink NEWNAME local lnew="$1"; local disp="xxx"; for disp in ${disps[@]}; do local fnew="${disp}/${bat}/${lnew}" if [ -L ${fnew} ]; then ( cd ${disp}/${bat} && rm -v ${lnew} ) elif [ -e ${fnew} ]; then echo "${fnew} is not a link" 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 removelink ${new} removelink ${newsm} removelink ${newic} removelink ${newen} else createlink ${old} ${new} ${dsp} createlink ${oldsm} ${newsm} ${dsp} createlink ${oldic} ${newic} ${dsp} createlink ${olden} ${newen} ${dsp} fi done if [ ! "$1" = "eob" ]; then echo "missing 'eob', found '$1'"; exit 1; fi