#! /bin/bash
# Last edited on 2010-07-08 18:36:00 by stolfilocal

usage="$0 RA..."

# Re-generates the images for static labwork hand-ins.
# Arguments are RA numbers of students to process.
# For each student, expects to find the files
#   ${ra}/main.pov - the student's main POV-ray file,possibly edied by the teacher.
#   ${ra}/Makefile - homework-specific "rebuild" Makefile (us. link).
# (Re)generates the files
#   ${ra}/main.png - hand-in image (rebuilt to standard size)

export PATH=".:tools:../tools:../../tools:../../../tools:../../../../tools:${PATH}"

if [[ $#argv < 1 ]]; then
  echo "usage: ${usage}" 1>&2; exit 1
fi

ras=( "$@" )

imgfile="main.png"
povfile="main.pov"

for ra in ${ras[@]} ; do
  # Ckeck if the POV-ray source exists.
  # If so, re-build the image 
  if [[ -s ${ra}/${povfile} ]]; then
    echo "=== (re)building ${imgfile} in ${ra} ====================" 1>&2
    ( cd ${ra} && make image ; echo " " )
    echo "=== done rebuilding ${ra} ==============================" 1>&2
  else
    echo "${ra}/main.pov unreadable or empty" 1>&2
  fi
done