#!/bin/bash
if [ $1 = "start" -o $1 = "install" ]; then
	# fix location
	sed -i "s|${MY_HOSTROOTDIR}|${VHOST_ROOT}|g" /usr/bin/standalone_httpd /usr/bin/rt-crontool /usr/bin/webmux.pl /usr/lib/RT.pm
	sed -i "s|${MY_HOSTROOTDIR}|\/usr|" /usr/bin/mason_handler.scgi
	sed -i "s|${MY_HTDOCSDIR}|${MY_INSTALLDIR}|" /usr/lib/RT.pm /usr/bin/rt-mailgate

	# fix permissions
	chown -R  ${VHOST_SERVER_GID}:${VHOST_SERVER_UID} /var/rt

	# check for upgrades
	cd ${VHOST_ROOT}/rt-config/upgrade
	echo "You may need to update your database."
	echo "For each item in the output below"
	echo "whose name is greater than your previously installed RT version,"
	echo "rt-setup-database --action schema --datadir ${VHOST_ROOT}/rt-config/upgrade/<version>"
	echo "rt-setup-database --action acl --datadir ${VHOST_ROOT}/rt-config/upgrade/<version>"
	echo "rt-setup-database --action insert --datadir ${VHOST_ROOT}/rt-config/upgrade/<version>"
	echo "Don't forget to read the README for more details"
	ls

elif [ $1 = "clean" ]; then
	rm -f /usr/bin/standalone_httpd /usr/bin/rt-crontool /usr/bin/webmux.pl /usr/lib/RT.pm /usr/bin/mason_handler.scgi /usr/bin/rt-mailgate
	rm -rf /var/rt
fi