#!/bin/sh

if [ -d /usr/local/openfire ]; then

	# stop openfire
	/bin/launchctl unload /Library/LaunchDaemons/org.jivesoftware.openfire.plist

	# remove existing tmp storage
	/bin/rm -rf /tmp/openfireInstallBackup

	# create tmp storage location and assorted pieces
	/bin/mkdir -p /tmp/openfireInstallBackup

	# preserve these files, they should never be upgraded
	if [ -f /usr/local/openfire/conf/openfire.xml ]; then
		/bin/cp /usr/local/openfire/conf/openfire.xml /tmp/openfireInstallBackup/openfire.xml
	fi
	if [ -f /usr/local/openfire/conf/security.xml ]; then
		/bin/cp /usr/local/openfire/conf/security.xml /tmp/openfireInstallBackup/security.xml
	fi
	if [ -f /usr/local/openfire/resources/security/keystore ]; then
		/bin/cp /usr/local/openfire/resources/security/keystore /tmp/openfireInstallBackup/keystore
	fi
	if [ -f /usr/local/openfire/resources/security/truststore ]; then
		/bin/cp /usr/local/openfire/resources/security/truststore /tmp/openfireInstallBackup/truststore
	fi
	if [ -f /usr/local/openfire/resources/security/client.truststore ]; then
		/bin/cp /usr/local/openfire/resources/security/client.truststore /tmp/openfireInstallBackup/client.truststore
	fi
	if [ -f /usr/local/openfire/lib/log4j.xml ]; then
		/bin/cp /usr/local/openfire/lib/log4j.xml /tmp/openfireInstallBackup/log4j.xml
	fi

fi
