#!/bin/sh -e
# 
# postrm maintainer script for the Debian tex-common package.
#
# Copyright (C) 2004 by Frank Küster <frank@kuesterei.ch>. 
# Copyright (C) 2012 by Norbert Preining <preining@debian.org>.
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to: The Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
#
# On Debian GNU/Linux System you can find a copy of the GNU General Public
# License in "/usr/share/common-licenses/GPL".

# give commandline args a name
action=$1 # remove, purge, upgrade, failed-upgrade, abort-install, abort-upgrade, disappear

## do the things we have to do always
case $action in
  abort-install|abort-upgrade)
    syml=/usr/share/texmf/doc
    if [ -n "$2" ] && dpkg --compare-versions "$2" lt "4" ; then
      if [ -L $syml.dpkg-remove ] && [ ! -e $syml ] ; then
        echo "Reinstatiating $syml"
        mv $syml.dpkg-remove $syml
      fi
    fi
  ;;
  remove)
    # remove TEXMFSYSVARDIR: All files and dirs are created either by
    # us, or by packages depending on us.
    rm -rf /var/lib/texmf
    # same with obsolete /var/cache/fonts
    rm -rf /var/cache/fonts
    ;;
  purge)
    if [ -L /usr/share/texmf/doc.dpkg-remove ] ; then
      rm -f /usr/share/texmf/doc.dpkg-remove
    fi

    # TODO purge ucf files

    # remove texmf.cnf
    if [ -d /etc/texmf/web2c ] ; then
      rm -rf /etc/texmf/web2c/texmf.cnf
      rmdir --ignore-fail-on-non-empty /etc/texmf/web2c
    fi

    # try to remove /usr/local/share/texmf if it is empty
    # people should normally not have TEXMFLOCAL ls-R files
    # unless they called mktexlsr manually, in which case this is fine
    # maintainer scripts should call mktexlsr with a list of trees so
    # no /u/l/s/texmf/ls-R is created
    #rm -f /usr/local/share/texmf/ls-R 2>/dev/null || true
    rmdir --ignore-fail-on-non-empty /usr/local/share/texmf/ 2>/dev/null || true
    ;;
  *)
    ;;
esac

#DEBHELPER#

