#!/bin/sh

RAMDISK=/usr/ramdisk
FLOWEYE=/usr/ramdisk/bin/floweye
. /etc/PG.conf

ixcache_enable()
{
	local errmsg

	errmsg=`${FLOWEYE} ixcache config enable=1`
}

ixcache_disable()
{
	local errmsg

	errmsg=`${FLOWEYE} ixcache config enable=0`
}

ixcache_status()
{
	local errmsg

	errmsg=`${FLOWEYE} ixcache stat | grep "^enable" | cut -d'=' -f2`
	if [ "${errmsg}" = "1" ]; then
		echo "enable"
	else
		echo "disable"
	fi
}
	
ixcache_start()
{
	if [ ! -d ${RAMDISK}/admin/cgi-bin/App/ixcache ]; then
		mkdir -p ${RAMDISK}/admin/cgi-bin/App/ixcache
	fi

	cp -rf ${RAMDISK}/app/ixcache/web/* ${RAMDISK}/admin/cgi-bin/App/ixcache/
}

ixcache_verify()
{
	local errmsg

	errmsg=`${FLOWEYE} module list | grep ixcache`
	if [ "${errmsg}" = "" ]; then
		echo "no"
		return 0
	fi

	echo "yes"
	return 1
}

ixcache_unload()
{
	ixcache_disable
}

case "$1" in 
"start")
	ixcache_start
	;;
"stop")
	;;

"enable")
	ixcache_enable
	;;

"disable")
	ixcache_disable
	;;

"status")
	ixcache_status
	;;

"verify")
	ixcache_verify
	;;

"unload")
	ixcache_unload
	;;

*)
	echo "unknown action!"
	;;
esac

