#!/bin/sh
# preinst script for fonts-mathematica
#
# see: dh_installdeb(1)

set -e

rm_conffile() {
  PKGNAME="$1"
  CONFFILE="$2"
  if [ -e "$CONFFILE" ]; then
   md5sum="`md5sum \"$CONFFILE\" | sed -e \"s/ .*//\"`"
   old_md5sum="`dpkg-query -W -f='${Conffiles}' $PKGNAME | sed -n -e \"\\\\' $CONFFILE'{s/ obsolete$//;s/.* //p}\"`"
   if [ "$md5sum" != "$old_md5sum" ]; then
     echo "Obsolete conffile $CONFFILE has been modified by you."
     echo "Saving as $CONFFILE.dpkg-bak ..."
     mv -f "$CONFFILE" "$CONFFILE".dpkg-bak
   else
     echo "Removing obsolete conffile $CONFFILE ..."
     rm -f "$CONFFILE"
   fi
 fi
}

if [ $1 = install -o $1 = upgrade ]; then

. /usr/share/debconf/confmodule
db_version 2.0
#db_capb backup

db_get mathematica-fonts/accept_license
if [ "$RET" = "true" ]; then
    echo "The license has already been accepted." >&2
    exit 0
fi

#db_fset mathematica-fonts/license seen false
#db_fset mathematica-fonts/accept_license seen false

# confirm if user really refuses to accept
db_input critical mathematica-fonts/license || true
db_input critical mathematica-fonts/accept_license || true
db_go || true

db_get mathematica-fonts/accept_license
if [ "$RET" != "true" ]; then
    # user refused to accept
    echo "License declined, aborting." >&2
    exit 2
fi

fi

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

#DEBHELPER#

exit 0

