#!/bin/sh

PKGPATH="/usr/local/zy-pkgs"
STATUS_FILE=/usr/local/zy-pkgs/share/myZyXELcloud-Agent_pkg_status
export CLOUDAGENT_INSTALL_DIR=$PKGPATH

if [ "$1" == "startup" ]; then
	cp $PKGPATH/share/zyxel_cloud_agent_configure.conf -a /tmp
	$PKGPATH/bin/start_cloudagent.sh &
	monitor_process=$(ps | grep [x]mpp_client_monitor)
	if [ -z "$monitor_process" ];then
		$PKGPATH/bin/xmpp_client_monitor.sh &
	fi
elif [ "$1" == "shutdown" ]; then
	killall -9 xmpp_client_monitor.sh
	killall -9 start_cloudagent.sh
	killall -9 set_upnp_to_router.sh
	killall -9 get_xmpp_info.sh
	killall -9 zyxel_device_register	
        killall -9 zyxel_xmpp_client
elif [ "$1" == "getlink" ]; then
        echo "https://mycloud.zyxel.com"
elif [ "$1" == "status" ]; then
	if [ -f $STATUS_FILE ]; then
		echo `cat $STATUS_FILE`
	else
		echo "Enabled"
	fi	
elif [ "$1" == "enable" ]; then
	echo "Enabled" > $STATUS_FILE
elif [ "$1" == "disable" ]; then
	echo "Disabled" > $STATUS_FILE
fi

exit 0
