#! /bin/sh
# postrm script for jadetex
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postrm> `remove'
#        * <postrm> `purge'
#        * <old-postrm> `upgrade' <new-version>
#        * <new-postrm> `failed-upgrade' <old-version>
#        * <new-postrm> `abort-install'
#        * <new-postrm> `abort-install' <old-version>
#        * <new-postrm> `abort-upgrade' <old-version>
#        * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PACKAGE=jadatex
ETC_CONFIG=/etc/texmf/jadetex
FMTDIR=/etc/texmf/fmt.d

remove_conffile_rollback () {
  # syntax: remove_conffile_rollback filename
  #
  # Roll back the removal of a conffile "filename".
  #
  # Call this function from a postrm script in the event $1 is "abort-upgrade"
  # or "abort-install" is  after having used remove_conffile_prepare() in the
  # preinst.

  # validate arguments
  if [ $# -ne 1 ]; then
    echo "remove_conffile_rollback() called with wrong number of" \
                "arguments; expected 1, got $#"
    exit 2
  fi

  conffile="$1"

  # if the temporary file created by remove_conffile_prepare() exists, move it
  # back
  if [ -e "$conffile.${PACKAGE}-tmp" ]; then
    echo "rolling back removal of obsolete conffile $conffile"
    mv "$conffile.${PACKAGE}-tmp" "$conffile"
  fi
}

case "$1" in
    purge)
	rm -rf $ETC_CONFIG || true
	rm -f ${FMTDIR}/*jadetex.cnf*
	rm -f /etc/texmf/texmf.d/*JadeTeX*
	if [ -x "`which update-texmf 2>/dev/null`" ]; then
	  update-texmf
	fi

	;;

    abort-install|abort-upgrade)
	remove_conffile_rollback /etc/texmf/fmt.d/40jadetex.cnf
	;;

    remove|upgrade|failed-upgrade|disappear)

        ;;

    *)
        echo "postrm called with unknown argument \`$1'" >&2
        exit 1

esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
