#!/bin/sh
. /etc/PG.conf

#SYS ENV
RAMDISK=/usr/ramdisk/
WEBROOT=${RAMDISK}/admin
FLOWEYE=${RAMDISK}/bin/floweye

#APP ENV
APPNAME=topurl
APPROOT=${PGPATH}/app/${APPNAME}

HTMLDIR=${WEBROOT}/html/App/${APPNAME}
CGIDIR=${WEBROOT}/cgi-bin/App/${APPNAME}
TMPWEBDIR=${RAMDISK}/app/${APPNAME}/web/


app_status()
{
	errmsg=`${FLOWEYE} ntmhost stat`
	
	if [ $? -ne 0 ]; then
		echo "disable"
		return
	fi
	
	for val in ${errmsg}
	do
		eval ${val}
	done
	
	if [ "${enable}" = "1" ]; then
		echo "enable"
	else
		echo "disable"
	fi
}


app_start()
{
	mkdir -p ${CGIDIR}
	mkdir -p ${HTMLDIR}

	chmod +x ${APPROOT}/web/cgi/*

	cp -Rf ${APPROOT}/web/cgi/* ${CGIDIR}/
	cp -Rf ${APPROOT}/web/html/* ${HTMLDIR}/

	[ -d ${TMPWEBDIR} ] && rm -rf ${TMPWEBDIR}
}


app_enable()
{
	${FLOWEYE} ntmhost config enable=1
	${FLOWEYE} npmhost config enable=1
}


app_disable()
{
	${FLOWEYE} ntmhost config enable=0
	${FLOWEYE} npmhost config enable=0
}


case "$1" in 
	"start")
		app_start
		;;

	"stop")
		;;

	"enable")
		app_enable
		;;

	"disable")
		app_disable
		;;

	"status")
		app_status
		;;

	*)
		echo "unknown action!"
		;;
esac


