#!/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_synosdk_sharehook_plugin()
{
	local destsharedeletefile="/usr/local/libexec/share_delete/VideoindexShareDelete.sh"
	local destsharesetfile="/usr/local/libexec/share_set/VideoindexShareSet.sh"
	
	rm -f ${destsharedeletefile} 
	rm -f ${destsharesetfile}
}

remove_syslog_file()
{
	local LOG_ROTATE_CONF="/usr/local/etc/logrotate.d/videostation"
	local SYSLOGNG_CONF="/usr/local/etc/syslog-ng/patterndb.d/videostation.conf"

	rm -f ${LOG_ROTATE_CONF}
	rm -f ${SYSLOGNG_CONF}

	synoservicectl --reload syslog-ng
}

remove_synosdk_userhook_plugin
remove_synosdk_sharehook_plugin
remove_syslog_file

case "$SYNOPKG_PKG_STATUS" in
	UNINSTALL)
		remove_port_setting
		if [ "$pkgwizard_remove_db" = "true" ]; then
			/usr/bin/dropdb -U postgres video_metadata
			rm -rf ${PACKAGE_DIR}/etc/*
		fi
	;;
	UPGRADE)
	;;
esac

exit 0
