#!/bin/sh -e
# /usr/lib/emacsen-common/packages/remove/emacspeak

FLAVOR=$1
PACKAGE=emacspeak

if test -x /usr/sbin/install-info-altdir; then
    echo remove/${PACKAGE}: removing Info links for ${FLAVOR}
    install-info-altdir --quiet --remove --dirname=${FLAVOR} /usr/info/emacspeak.info.gz
fi

ENAME=`echo $FLAVOR | perl -pe 's/emacs.*/emacs/'`
update-alternatives --remove ${ENAME}peak /usr/bin/${ENAME}peak.${FLAVOR}
rm -f /usr/bin/${ENAME}peak.${FLAVOR}

echo remove/${PACKAGE}: purging byte-compiled files for ${FLAVOR}
if [ ${FLAVOR} = emacs ]; then
    FILES="$(find /usr/share/${FLAVOR}/site-lisp/${PACKAGE} -name \*.elc)"
    if [ -n "$FILES" ] ; then
        rm $FILES
    fi
    rm -f /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/README
    rm -f /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/debian_compiled_version
    rm -f /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/install.log.gz
    rm -f /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/etc/emacspeak.sh
    rm -f /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/lisp/emacspeak-cus-load.el
    rm -f /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/lisp/emacspeak-cus-load.el~
    rm -f /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/lisp/emacspeak-loaddefs.el
    rm -f /usr/share/${FLAVOR}/site-lisp/${PACKAGE}/lisp/emacspeak-loaddefs.el~
else
    rm -rf /usr/share/${FLAVOR}/site-lisp/${PACKAGE}
fi
