#!/bin/sh

set -e
PATH="/sbin:/bin:/usr/sbin:/usr/bin"

if [ "$1" = "openoffice.org" -a "$2" = "upgrade" ]; then
	# we need this only if we upgrade from an older version to
	# 1.0.99+1.1rc
	if dpkg --compare-versions 1.0.3-2 lt $3; then
		# this should run before the actual package in unpackaged;
		# so the file doesn't exist. After unpacking the deb
		# the modifications are already done and the file is
		# there so skip if we find it
		if [ ! -e /usr/share/myspell/infos/ooo/openoffice.org ]; then
			echo "upgrading from <= 1.0.3-2; changing dictionary.lst"
			# remove old dictionary.lst entries shipped by former
			# OOo revisions
			TMP=`mktemp -q`
			cat /etc/openoffice/dictionary.lst | \
				sed -e s/"DICT en US en_US"// \
			  	-e s/"HYPH en US hyph_en"// \
			  	-e s/"THES en US th_en_US"// \
			  	-e s/"\# Additional writing aids"// \
			  	-e s/"HYPH de DE hyph_de"// \
			  	-e s/"HYPH da DK hyph_da"// \
			  	-e s/"HYPH ru RU hyph_ru"// > $TMP
			chmod 644 $TMP && mv $TMP /etc/openoffice/dictionary.lst
		fi
	fi
fi

if [ "$1" = "openoffice.org" -a "$2" = "remove" -a \
	! -e /usr/share/doc/openoffice-org/changelog.Debian.gz ]; then
	update-openoffice-dicts
fi

if [ "$1" = "openoffice.org" -a "$2" = "configure" ]; then
	update-openoffice-dicts
fi

if [ "$1" = "openoffice.org-thesaurus-en-us" -a "$2" = "configure" ]; then
	update-openoffice-dicts
fi
	
