#!/bin/sh
# Copyright (c) 2000-2014 Synology Inc. All rights reserved.

if [ "$SYNOPKG_PKG_STATUS" ==  "UPGRADE" -o -f "/tmp/WordPress.upgrade" ]; then
	exit 0
fi

WPWEBDIR="/var/services/web/wordpress"

rm -rf /usr/syno/synoman/webman/3rdparty/WordPress
wpconfig=`find /var/services/web/ -name wp-config.php`
wp=`dirname $wpconfig`
rm -rf ${wp}
rm -rf ${WPWEBDIR}

# Get DSM Version
[ -f "/etc.defaults/VERSION" ] || exit 1
DSM_VERSION=`grep ^majorversion= /etc.defaults/VERSION | cut -d'"' -f2`
[ -z "$DSM_VERSION" ] && exit 1

# DSM 4 use different config
if [ $DSM_VERSION -le 4 ]; then
	SITES_ENABLED_USER_DIR="/usr/syno/etc/sites-enabled-user"
	ApacheUserScript="/usr/syno/etc/rc.d/S97apache-user.sh"

	if [ -d $SITES_ENABLED_USER_DIR ]; then
		rm $SITES_ENABLED_USER_DIR"/SYNO.SDS.WordPress.conf"
		$ApacheUserScript restart > /dev/null 2>&1
	fi
else
	PHP_CONF_DIR="/etc/php/conf.d"
	
	if [ -d $PHP_CONF_DIR ]; then
		rm $PHP_CONF_DIR"/SYNO.SDS.WordPress.ini"
		initctl restart php-fpm > /dev/null 2>&1
	fi
fi
exit 0
