#! /bin/sh

. $TS_GLOBAL

case "$1" in  
init)
    if ! pkg_initialized $PACKAGE; then

	touch /var/log/spooler.log

	let x=0
	PRINTER_X_NAME=$PRINTER_0_NAME

	while [ -n "$PRINTER_X_NAME" ] ; do
	  PRINTER_X_DEVICE=`eval echo '$PRINTER_'$x'_DEVICE'`
	  PRINTER_X_TYPE=`eval echo '$PRINTER_'$x'_TYPE'`
	  PRINTER_X_OPTIONS=`eval echo '$PRINTER_'$x'_OPTIONS'`
	  PRINTER_X_NAME=`eval echo '$PRINTER_'$x'_NAME'`
	  PRINTER_X_DRIVER=`eval echo '$PRINTER_'$x'_DRIVER'`
	  
    	  if [ "$PRINTER_X_TYPE" = "P" ] ; then
	    modprobe parport_pc
	    modprobe lp
	  fi

          if [ "$PRINTER_X_TYPE" = "U" ] ; then
	    modprobe usblp
	  fi

	  if [ "`make_caps "$ICA_PRINTER"`" = "ON" ] ; then
	     PRINTER_X_DRIVER="$PRINTER_X_NAME"
	     if [ -n "$PRINTER_X_NAME" ] ; then
		if [ $x -eq 0 ] ; then
			PRINTER_X_NAME="lp"
		else
			PRINTER_X_NAME="lp$x"
		fi
	     fi
	  fi

	  echo "$PRINTER_X_NAME:lp=$PRINTER_X_DEVICE:wd=$PRINTER_X_DRIVER:br=$PRINTER_X_OPTIONS:lf=/var/log/spooler.log:sh:sf" >> /etc/printcap

	  let x=x+1
	  PRINTER_X_NAME=`eval echo '\$PRINTER_'$x'_NAME'`
	done	

	checkpc -f -V
	lpd
	sleep 1

	chmod 666 /dev/printer

	pkg_set_init_flag $PACKAGE
    fi
    ;;
help)
    echo "Usage: $0 init"
    ;;
  *)
    exit 1
    ;;
esac

exit 0
