#!/bin/bash
#
# compressor.sh - shell script to watch a data directory for tiff files
#             and create compressed jpeg images out of them, saving them
#             in the same directory as the tiff files.
#

destination_dir=/home/www/docs/halld/diamonds/chess-11-2012/data/latest

if [ $# != 0 ]; then
  echo "Usage: compressor.sh"
  exit 1
fi

while true; do
  for tif in `ls $destination_dir/*.tiff`; do
    jpg=`echo $tif | sed 's/tiff$/jpg/'`
    if [ ! -r $jpg ]; then
      convert $tif -resize 20% -normalize $jpg
    fi
  done
  echo sleeping...
  sleep 10;
done
