#!/bin/sh
# This maintainer script was originally written by Harri Pitkänen, Teemu Likonen
# and Timo Jyrinki and was adoptet from the openoffice.org-voikko package. It
# was modified by Sebastian Humenda to fit for the accessodf package.

PATH=/bin:/usr/bin:/usr/lib/libreoffice/program
set -e

flush_unopkg_cache() {
	INSTDIR=`mktemp -d`
        HOME=$INSTDIR unopkg list --shared "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1" > /dev/null 2>&1
}

remove_extension() {
  INSTDIR=`mktemp -d`
  if HOME=$INSTDIR unopkg list --shared $1 >/dev/null; then
    echo -n "Removing extension $1..."
    HOME=$INSTDIR unopkg remove --shared $1 \
      "-env:UserInstallation=file://$INSTDIR" \
      '-env:UNO_JAVA_JFW_INSTALL_DATA=$ORIGIN/../share/config/javasettingsunopkginstall.xml' \
      "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1"
    if [ -n $INSTDIR ]; then rm -rf $INSTDIR; fi
    echo " done."
    flush_unopkg_cache
  fi
}

case "$1" in
    upgrade|install)
	INSTDIR=`mktemp -d`
        echo Removing old accessodf extensions.
        id=" "
        while [ "$id" != ""  ]; do
            id=`HOME=$INSTDIR unopkg list --shared | egrep '^(Name|Identifier):.*accessodf' | cut -d":" -f2 | head -n 1`
            if [ "$id" != "" ]; then remove_extension $id; fi
        done
    ;;
esac


#DEBHELPER#
