#!/bin/sh
set -i

. /usr/share/debconf/confmodule
db_version 2.0
db_get proofgeneral/autoload || true; autoload=${RET}

if [ "$1" = "configure" ]; then 
    # register info pages
    install-info --quiet --section Emacs Emacs /usr/share/info/proofgeneral.info
    install-info --quiet --section Emacs Emacs /usr/share/info/proofgeneral-adapting.info

    # remove old scripts
    if [ -f /etc/emacs21/site-start.d/50proofgeneral.el ]; then
        echo "Removing old proofgeneral startup file for Emacs21"
        rm -f /etc/emacs21/site-start.d/50proofgeneral.el
    fi
    if [ -L /etc/xemacs21/site-start.d/50proofgeneral.el ]; then
        echo "Removing old proofgeneral startup file for XEmacs21"
        rm -f /etc/xemacs21/site-start.d/50proofgeneral.el
    fi

    # remove startup script if autoload is disabled
    if [ ${autoload} = "true" ] ; then
	echo "Installing proofgeneral startup files for Emacs"
	cat <<EOF > /etc/emacs/site-start.d/50proofgeneral.el
;; -*-emacs-lisp-*-
;;
;; Emacs startup file for the Debian GNU/Linux proofgeneral package
;;
;; This file is automatically generated by the proofgeneral postinst
;; script. It will automatically be removed or changed on remove or 
;; upgrade. If you want to change this file anyway use 
;; "dpkg-reconfigure proofgeneral" to disable the autoload behaviour
;;  and install your own version of this file.
;;
(defun proofgeneral ()
  (interactive)
  "Load the ProofGeneral and bind several proof script file extensions to 
   the respective ProofGeneral major mode."
  (load "/usr/share/emacs/site-lisp/proofgeneral/generic/proof-site.el"))
EOF
    else
	echo "Removing proofgeneral startup files for Emacs"
        rm -f /etc/emacs/site-start.d/50proofgeneral.el
    fi
fi

#DEBHELPER#

exit 0
