#! /bin/bash -e
#
# <% elisp %> Emacs remove script for auctex
#
# Copyright (C) 1997, 98, 99, 2000, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10
# by Davide G. M. Salvetti.
#
# This program 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 3 of the License, or (at your
# option) any later version.
#
# This program 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, see <http://www.gnu.org/licenses/>.
#
# On Debian GNU/Linux System you can find a copy of the GNU General Public
# License in "/usr/share/common-licenses/GPL".

set -o posix

FLAVOR=${1}

undo_install () {
    echo >&2 -n "remove/auctex: Removing for ${FLAVOR}... "
    rm -f /usr/share/${FLAVOR}/site-lisp/auctex//../{auctex,tex-site}.el
    rm -f /usr/share/${FLAVOR}/site-lisp/auctex//../preview-latex.el
    rm -f /usr/share/${FLAVOR}/site-lisp/auctex//CompilationLog{,.gz}
    rm -f /usr/share/${FLAVOR}/site-lisp/auctex//images
    rm -f /usr/share/${FLAVOR}/site-lisp/auctex//*.el
    rm -f /usr/share/${FLAVOR}/site-lisp/auctex//*.elc
    rm -f /usr/share/${FLAVOR}/site-lisp/auctex//.nosearch
    rm -f /usr/share/${FLAVOR}/site-lisp/auctex//style//*.elc
    rm -f /usr/share/${FLAVOR}/site-lisp/auctex//style//.nosearch
    test -d /usr/share/${FLAVOR}/site-lisp/auctex//style/ && \
	rmdir --ignore-fail-on-non-empty \
	/usr/share/${FLAVOR}/site-lisp/auctex//style/
    test -d /usr/share/${FLAVOR}/site-lisp/auctex/ && \
	rmdir --ignore-fail-on-non-empty \
	/usr/share/${FLAVOR}/site-lisp/auctex/
    echo >&2 "done."
    return 0
}

undo_auto () {
    rm -rf /var/lib/auctex//${FLAVOR}/

        rm -f /var/log/auctex.log

    LOGFILE=/var/log/auctex-${FLAVOR}.log
    rm -f ${LOGFILE}
    return 0
}

case "${FLAVOR}" in
    emacs) :;;
    emacs2[123]|emacs-snapshot)
		undo_auto
	undo_install;;
    *) echo >&2 "remove/auctex:" \
	"Ignoring emacsen flavor: \"${FLAVOR}\"."
esac

exit 0
