#!/bin/sh

SERVICETOOL="/usr/syno/bin/servicetool"
PACKAGE_DIR="/var/packages/VideoStation"

remove_port_setting()
{
        # remove port-forwarding config file
        ${SERVICETOOL} --remove-configure-file --package videostation_port
}

remove_synosdk_userhook_plugin()
{
	local destuserdeletefile="/usr/local/libexec/user_delete/synovideostation_user_del"

	rm -f ${destuserdeletefile}
}

remove_port_setting
remove_synosdk_userhook_plugin

case "$SYNOPKG_PKG_STATUS" in
	UNINSTALL)
	if [ "$pkgwizard_remove_db" = "true" ]; then
		/usr/syno/pgsql/bin/dropdb -U admin video_metadata
		rm -f ${PACKAGE_DIR}/etc/folder.conf
		rm -f ${PACKAGE_DIR}/etc/plugin.conf
		rm -f ${PACKAGE_DIR}/etc/channels.conf
		rm -f ${PACKAGE_DIR}/etc/dtv_schedule.json
		rm -f ${PACKAGE_DIR}/etc/dtvrecord.idx
		rm -f ${PACKAGE_DIR}/etc/scan.conf
		rm -f ${PACKAGE_DIR}/etc/stream.conf
		rm -f ${PACKAGE_DIR}/etc/record.conf
		rm -rf ${PACKAGE_DIR}/etc/EPG
	fi
	;;
	UPGRADE)
	;;
esac

exit 0
