#!/bin/sh

# This script is run after the package is removed from the system.

VIDEOSTATION_DIR=/var/packages/VideoStation
DEST_DIR=${VIDEOSTATION_DIR}/target/plugins/syno_allocine

case "$SYNOPKG_PKG_STATUS" in
	UNINSTALL)
		if [ ! -d ${VIDEOSTATION_DIR} ]
		then
			exit 1
		fi
		echo "$(date +%d.%m.%y_%H:%M:%S): <b>Desinstallation</b><br>">>${SYNOPKG_TEMP_LOGFILE}
		if [ -d ${DEST_DIR} ]; then
			echo "$(date +%d.%m.%y_%H:%M:%S): Suppression du pluggin.<br>">>${SYNOPKG_TEMP_LOGFILE}
			rm -rf ${DEST_DIR}
		fi

		echo "$(date +%d.%m.%y_%H:%M:%S): Restauration du fichier des plugin.<br>">>${SYNOPKG_TEMP_LOGFILE}
		if [ -f ${VIDEOSTATION_DIR}/target/etc/plugin.org ]
		then
			rm ${VIDEOSTATION_DIR}/target/etc/plugin.conf
			mv ${VIDEOSTATION_DIR}/target/etc/plugin.org  ${VIDEOSTATION_DIR}/target/etc/plugin.conf
		fi
		if [ -f ${VIDEOSTATION_DIR}/etc/plugin.org ]
		then
			rm ${VIDEOSTATION_DIR}/etc/plugin.conf
			mv ${VIDEOSTATION_DIR}/etc/plugin.org  ${VIDEOSTATION_DIR}/etc/plugin.conf
		fi
		if [ -d ${VIDEOSTATION_DIR}${VIDEOSTATION_DIR}/plugin_data/com.synology.allocine ]
		then
			rm -rf ${VIDEOSTATION_DIR}/plugin_data/com.synology.allocine
		fi
	;;
	UPGRADE)
	;;
esac

/var/packages/VideoStation/scripts/S86synovideoindexd.sh restart
/var/packages/VideoStation/scripts/S86synovideometadatad.sh restart

exit 0

