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

PKG_DIR="Joomla_2.5.6"
tmp_path=/$(readlink /var/services/web|cut -d/ -f 2)/@tmp
if [ ! -d ${tmp_path}/joomla ]; then
	mkdir -p ${tmp_path}/joomla
fi

rm -rf ${tmp_path}/joomla/$PKG_DIR
/bin/cp -rf /var/services/web/joomla ${tmp_path}/joomla/$PKG_DIR

while read joomlafile
do
	# Package center uses preupgarde in new package but joomla_file.all is
	# from old package, thus remove Joomla_X.X.X in $joomlafile first
	joomlafile=${joomlafile#*\/}
	if [ -f "${tmp_path}/joomla/$PKG_DIR/$joomlafile" ]; then
		rm "${tmp_path}/joomla/$PKG_DIR/$joomlafile"
	fi
	# FIXME How about file not removed happens to be newly-added file in new
	# package? The file in new package will be overwritten when postupgrade
done < /var/services/web/joomla/etc/joomla_file.all

exit 0
