#!/bin/sh

PKGNAME="Memopal"
PKGSTATUSFILE="/etc/zyxel/pkg_conf/status"
PKGINSTPATH=`grep "${PKGNAME}" ${PKGSTATUSFILE} | grep "Installed-Rule" | awk -F":" '{print $2}' | sed 's/\/$//g' | sed 's/ //g'`
CONFIG_FOLDER="${PKGINSTPATH}/config/${PKGNAME}"
CONFIG_FILE="${PKGINSTPATH}/config/${PKGNAME}/localConfig"
RESET_FLAG="/tmp/PKG_RESET"

killall -9 memopal

if [ -e ${CONFIG_FILE} ]; then
	sed -i '1c status: disable' ${CONFIG_FILE}
fi

#check need or not reset the configuration file
if [ -f "${RESET_FLAG}" ]; then
        isReset=`cat ${RESET_FLAG} | grep ${PKGNAME}`
fi

if [ "${isReset}" != "" ]; then
	#remove config file
	/bin/rm -rf ${CONFIG_FOLDER}
fi

rm -rf /i-data/.system/zy-pkgs/${PKGNAME}
rm -rf /i-data/.system/zy-pkgs/pkggui/${PKGNAME}

exit 0
