#!/bin/sh
#
# This file is released under the terms of the Artistic License.
# Please see the file LICENSE, included in this package, for details.
#
# Copyright (C) 2015      Mark Wong
# Copyright (C) 2015      2ndQuadrant, Ltd.
#

if [ $# -ne 2 ]; then
	echo "usage: `basename $0` <title> <csv dir>"
	exit 1
fi

TITLE=$1
PNGDIR=$2

HTMLFILE="$PNGDIR/db.html"

cat << __EOF__ > $HTMLFILE
<html>
<head>
<title>$TITLE Database Charts</title>
</head>
<body>
<h1>$TITLE Database Charts</h1>
__EOF__

	FILES=`ls -v $PNGDIR/*.png 2> /dev/null`
	if [ -n "$FILES" ]; then
		for chart in $FILES; do
			chart="$URL`basename $chart`"
			cat << __EOF__ >> $HTMLFILE
<p>
$chart<br/>
<a href="$chart"><img src="$chart" width="100%" /></a>
</p>
__EOF__
		done
	fi

	cat << __EOF__ >> $HTMLFILE
</body>
</html>
__EOF__
