#!/bin/sh
# 2001.4.25 added ".png"
# 2001.10.6 added lock by lock
if [ "$1" ]
then
  pmondir=$1
else
  echo 'usage : make_pmon_index [img_dir] ([scale ...])'
  echo '               scale - 1,2,3 or 4.'
  exit
fi
if [ -f $pmondir/LOCK ]
then
  exit
fi
touch $pmondir/LOCK
tempfile=/tmp/make_pmon_index.$$
shift
while [ "$1" ]
do
  if [ $1 = 1 ]
  then
    scale=""
  else
    scale="$1".
  fi
  title=`cat $pmondir/TITLE`
# Header
  cat - << END > $tempfile
<html>
<head><title>Monitor Records</title></head>
<body>
<h3>$title (1/$1 scale)</h3>
<dl option=compact>
END
# Body
  day_prev=000000
  (cd $pmondir;ls -1|egrep '[0-9]*0'."$scale"gif'|''[0-9]*0'."$scale"png|tail -1008)|
  while read filename
  do
    day=`echo $filename|cut -c1-6`
    start_time=`echo $filename|cut -c8-11`
    if [ $day != $day_prev ]
    then
      echo \<dt\>\<b\>$day\</b\> >> $tempfile
      echo \<dd\> >> $tempfile
      day_prev=$day
    fi
    echo \<a href=\"$filename\"\>$start_time\</a\>  >> $tempfile
  done
# Trailer
  cat - << END >> $tempfile
</dl>
</body>
</html>
END
  cp $tempfile $pmondir/index."$scale"html
  shift
done
rm $tempfile
rm $pmondir/LOCK
