#!/bin/sh

set -eu

command=$1
shift

symlink_targets='
  /usr/bin/cnijlgmon3
  /usr/bin/tocanonij
  /usr/bin/tocnpwg
  /usr/lib/bjlib2/cnnet.ini
  /usr/lib/cups/backend/cnijbe2
  /usr/lib/cups/filter/cmdtocanonij2
  /usr/lib/cups/filter/rastertocanonij
  /usr/lib/libcnbpcnclapicom2.so.5.0.0
  /usr/lib/libcnbpnet20.so.1.0.0
  /usr/lib/libcnbpnet30.so.1.0.0
  /usr/lib/libcnnet2.so.1.2.4
  /usr/share/cmdtocanonij2/autoalign.utl
  /usr/share/cmdtocanonij2/cleaning.utl
  /usr/share/cmdtocanonij2/nozzlecheck.utl
  /usr/share/cnijlgmon3/cnb_cnijlgmon2.res
  /usr/share/doc/cnijfilter2
  /usr/share/locale/de/LC_MESSAGES/cnijlgmon3.mo
  /usr/share/locale/fr/LC_MESSAGES/cnijlgmon3.mo
  /usr/share/locale/ja/LC_MESSAGES/cnijlgmon3.mo
  /usr/share/locale/zh/LC_MESSAGES/cnijlgmon3.mo
  /usr/share/ppd/canone460.ppd
  /usr/share/ppd/canone470.ppd
  /usr/share/ppd/canone480.ppd
  /usr/share/ppd/canong3000.ppd
  /usr/share/ppd/canong4000.ppd
  /usr/share/ppd/canonib4000.ppd
  /usr/share/ppd/canonib4100.ppd
  /usr/share/ppd/canonip110.ppd
  /usr/share/ppd/canonmb2000.ppd
  /usr/share/ppd/canonmb2100.ppd
  /usr/share/ppd/canonmb2300.ppd
  /usr/share/ppd/canonmb2700.ppd
  /usr/share/ppd/canonmb5000.ppd
  /usr/share/ppd/canonmb5100.ppd
  /usr/share/ppd/canonmb5300.ppd
  /usr/share/ppd/canonmb5400.ppd
  /usr/share/ppd/canonmg2900.ppd
  /usr/share/ppd/canonmg3000.ppd
  /usr/share/ppd/canonmg3600.ppd
  /usr/share/ppd/canonmg5600.ppd
  /usr/share/ppd/canonmg5700.ppd
  /usr/share/ppd/canonmg6600.ppd
  /usr/share/ppd/canonmg6800.ppd
  /usr/share/ppd/canonmg6900.ppd
  /usr/share/ppd/canonmg7500.ppd
  /usr/share/ppd/canonmg7700.ppd
  /usr/share/ppd/canonmx490.ppd
  /usr/share/ppd/canonts5000.ppd
  /usr/share/ppd/canonts6000.ppd
  /usr/share/ppd/canonts8000.ppd
  /usr/share/ppd/canonts9000.ppd
'

case "${command}" in
    configure)
	upstream_dir=$1

        for symlink_target in ${symlink_targets}; do
            mkdir -p $(dirname "${symlink_target}")
            ln -fns -T "${upstream_dir}${symlink_target}" "${symlink_target}"
        done
	;;
    unconfigure)
        for symlink_target in ${symlink_targets}; do
            rm -f "${symlink_target}"
        done
	;;
    unpack)
	upstream_pack=$1
	upstream_dir=$2

        debversion='5.40-1'
        debfile="cnijfilter2-${debversion}-deb/packages/cnijfilter2_${debversion}_amd64.deb"

        tar -O -zxf "$upstream_pack" "$debfile" \
          | dpkg-deb -x - "$upstream_dir"
	;;
    *)
	;;
esac
