#!/bin/sh

###################################################
# Script to process commands generated by the webapp
# It listens on stdin for single-line commands of the form:
# <action> <module>
# Eg 'refresh xml-site', 'publish xml-forrest'
###################################################

. `dirname $0`/local-vars

function lookup_script()
{
	echo $1-cvs.xml
}

function refresh()
{
	echo "Refreshing $module"
	$BASE/refresh `lookup_script $module` >> $REFRESH_LOG 2>&1
}

function publish()
{
	echo "Upload $module"
	$BASE/publish_livesite $module >> $REFRESH_LOG 2>&1
}

while true; do
read action module
case $action in
refresh)
	refresh $module
	;;
publish)
	publish $module
	;;
quit) exit
	;;
'')
  # When stdin closes we get a continuous stream of EOFs.  Sleep through these.
  sleep 2
;;
*)
	echo "Unknown command '$action'"
	echo "Available commands are 'refresh', 'publish'."
	;;
esac
done


