#! /bin/sh
# postinst script for magicolor5440dl
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#

case "$1" in
    configure)
       PPD_DIR="/etc/cups/ppd/"
       FILETYPE=".ppd"
       LPADMIN="/usr/sbin/lpadmin"
       KM_PPD_DIR="/usr/share/cups/model/KONICA_MINOLTA"
       if [ -x $LPADMIN ] && [ -d $PPD_DIR ] && [ -n "`ls -1A ${PPD_DIR}`" ]; then
          KMPPDS=(`grep -l "magicolor 5440 DL" ${PPD_DIR}*`)
          for kmppd in ${KMPPDS[@]}; do
             ppdFile=${kmppd#${PPD_DIR}}
             Printer=${ppdFile%${FILETYPE}}
             ppdFileNew=`find "${KM_PPD_DIR}" -name "km5440dl.ppd.gz" -print`
             $LPADMIN -p $Printer -P $ppdFileNew
             if [ $? -eq 0 ]; then
                echo Succeed to update $Printer
             else
                echo Fail to update $Printer
             fi
          done
       fi

       [ -x /etc/init.d/cupsys ] && invoke-rc.d cupsys force-reload || true
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

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

#DEBHELPER#

exit 0


