#!/bin/sh

set -e

#INCLUDE_SHELL_LIB#

case "$1" in install|upgrade)
	# move a already-filled in javasettingsunopkginstall.xml to the new
 	# location on upgrades
	if [ ! -e `echo /@OODIR@ | sed -e s/usr/var/`/share/config/javasettingsunopkginstall.xml ]; then
		if [ ! -d `echo /@OODIR@ | sed -e s/usr/var/`/share/config ]; then
			mkdir -p `echo /@OODIR@ | sed -e s/usr/var/`/share/config
		fi
		if [ -e `echo /@OODIR@ | sed -e s/usr/var/ | sed -e s/libre/open/`/config/javasettingsunopkginstall.xml ]; then
			mv `echo /@OODIR@ | sed -e s/usr/var/ | sed -e s/libre/open/`/share/config/javasettingsunopkginstall.xml \
				 `echo /@OODIR@ | sed -e s/usr/var/`/share/config/javasettingsunopkginstall.xml
		fi
	fi

	dpkg-maintscript-helper rm_conffile "/etc/bash_completion.d/ooffice.sh" 1:3.3.0~rc4-2 libreoffice-common -- "$@"
        if [ -n "$2" ] && dpkg --compare-versions "$2" lt "1:3.3.0-3"; then
		if [ -d /share ]; then
			rm -f /share/config/javasettingsunopkginstall.xml
			rmdir /share/config 2> /dev/null && rmdir /share 2> /dev/null || true
		fi

		if [ -d /user ]; then
			for i in shared tmp; do
				rmdir /user/extensions/$i/extensions 2> /dev/null || true
				rm -f /user/extensions/$i/extensions.db
				rm -f /user/extensions/$i/lastsynchronized
				rm -f /user/extensions/$i/log.txt
				rmdir /user/extensions/$i/registry/com.sun.star.comp.deployment.bundle.PackageRegistryBackend 2> /dev/null || true
				rmdir /user/extensions/$i/registry/com.sun.star.comp.deployment.component.PackageRegistryBackend 2> /dev/null || true
				rm -f /user/extensions/$i/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/backenddb.xml || true
				rm -f /user/extensions/$i/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/registered_packages.db || true
				rmdir /user/extensions/$i/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend 2> /dev/null || true
				rmdir /user/extensions/$i/registry/com.sun.star.comp.deployment.executable.PackageRegistryBackend 2> /dev/null || true
				rm -f /user/extensions/$i/registry/com.sun.star.comp.deployment.help.PackageRegistryBackend/backenddb.xml || true
				rmdir /user/extensions/$i/registry/com.sun.star.comp.deployment.help.PackageRegistryBackend 2> /dev/null || true
				rmdir /user/extensions/$i/registry/com.sun.star.comp.deployment.script.PackageRegistryBackend 2> /dev/null || true
				rmdir /user/extensions/$i/registry/com.sun.star.comp.deployment.sfwk.PackageRegistryBackend 2> /dev/null || true
				rmdir /user/extensions/$i/registry 2> /dev/null && rmdir /user/extensions/$i 2> /dev/null || true
			done
			rmdir /user/extensions/ 2> /dev/null && rmdir /user 2> /dev/null || true

			rm -f /user/uno_packages/cache/log.txt
			rmdir /user/uno_packages/cache/registry/com.sun.star.comp.deployment.bundle.PackageRegistryBackend 2> /dev/null || true
			rmdir /user/uno_packages/cache/registry/com.sun.star.comp.deployment.component.PackageRegistryBackend 2> /dev/null || true
			rm -f /user/uno_packages/cache/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/backenddb.xml || true
			rm -f /user/uno_packages/cache/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend/registered_packages.db || true
			rmdir /user/uno_packages/cache/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend 2> /dev/null || true
			rmdir /user/uno_packages/cache/registry/com.sun.star.comp.deployment.configuration.PackageRegistryBackend 2> /dev/null || true
			rmdir /user/uno_packages/cache/registry/com.sun.star.comp.deployment.executable.PackageRegistryBackend 2> /dev/null || true
			rm -f /user/uno_packages/cache/registry/com.sun.star.comp.deployment.help.PackageRegistryBackend/backenddb.xml || true
			rmdir /user/uno_packages/cache/registry/com.sun.star.comp.deployment.help.PackageRegistryBackend 2> /dev/null || true
			rmdir /user/uno_packages/cache/registry/com.sun.star.comp.deployment.script.PackageRegistryBackend 2> /dev/null || true
			rmdir /user/uno_packages/cache/registry/com.sun.star.comp.deployment.sfwk.PackageRegistryBackend 2> /dev/null || true
			rmdir /user/uno_packages/cache/uno_packages 2> /dev/null || true
			rm -f /user/uno_packages/cache/uno_packages.db 2> /dev/null || true


			rmdir /user/uno_packages/cache/registry 2> /dev/null && rmdir /user/uno_packages/cache 2> /dev/null && rmdir /user/uno_packages 2> /dev/null || true

			rmdir /user 2> /dev/null || true
		fi
	fi

	dpkg-maintscript-helper mv_conffile \
		"/etc/openoffice/psprint.conf" "/etc/libreoffice/psprint.conf" "" libreoffice-common -- "$@"
	dpkg-maintscript-helper mv_conffile \
		"/etc/openoffice/sofficerc" "/etc/libreoffice/sofficerc" "" libreoffice-common -- "$@"
	dpkg-maintscript-helper mv_conffile \
		"/etc/openoffice/soffice.sh" "/etc/libreoffice/soffice.sh" "" libreoffice-common -- "$@"
	;;
esac

#DEBHELPER#

exit 0
