#!/bin/sh
#*****************************************************************************

#            Copyright (C) 1989, 1990, Alias Research, Inc.                  *
#                                                                            *
#    These coded instructions,  statements and  computer programs contain    *
#    unpublished information proprietary to Alias Research, Inc.  and are    *
#    protected by the Canadian and US Federal copyright law. They may not    *
#    be disclosed to third parties  or copied  or duplicated, in whole or    *
#    in part,  without the prior written consent of Alias Research,  Inc.    *
#                                                                            *
# Unpublished-rights reserved under the Copyright Laws of the United States. *
#                                                                            *
#****************************************************************************/
#
#	$Source: /tmp_mnt/worf/root/v/alias5.1/src/Utility/etc/RCS/vy5000_face.sh_sgi,v $
#   $Revision: 5.0 $
#	$Author: software $
#   $Date: 94/03/23 02:30:33 $
#
#
#
# vy5000face - LP interface for Hitachi VY-5000 on SCSI bus
#
# Info for lptool:
#
# NAME=Hitachi VY-5000 on SCSI bus 0
#
# dev 2, OPTIONS=DEV=/dev/scsi/sc0d2l0, DEVICE=SCSI
# dev 3, OPTIONS=DEV=/dev/scsi/sc0d3l0, DEVICE=SCSI
# dev 4, OPTIONS=DEV=/dev/scsi/sc0d4l0, DEVICE=SCSI
# dev 5, OPTIONS=DEV=/dev/scsi/sc0d5l0, DEVICE=SCSI
# dev 6, OPTIONS=DEV=/dev/scsi/sc0d6l0, DEVICE=SCSI
# dev 7, OPTIONS=DEV=/dev/scsi/sc0d7l0, DEVICE=SCSI
#
# NAME=Hitachi VY-5000 on SCSI bus 1
#
# dev 1, OPTIONS=DEV=/dev/scsi/sc1d1l0, DEVICE=SCSI
# dev 2, OPTIONS=DEV=/dev/scsi/sc1d2l0, DEVICE=SCSI
# dev 3, OPTIONS=DEV=/dev/scsi/sc1d3l0, DEVICE=SCSI
# dev 4, OPTIONS=DEV=/dev/scsi/sc1d4l0, DEVICE=SCSI
# dev 5, OPTIONS=DEV=/dev/scsi/sc1d5l0, DEVICE=SCSI
# dev 6, OPTIONS=DEV=/dev/scsi/sc1d6l0, DEVICE=SCSI
# dev 7, OPTIONS=DEV=/dev/scsi/sc1d7l0, DEVICE=SCSI
#
# Optional Configuration:
#
# LOGFILE may be set to the name of log file for error and status
# messages.  The default value is /usr/spool/lp/log.
# 
# VERBOSE may be set to non-zero to enable logging in $LOGFILE.  The
# flag may be turned on for individual requests by using the -overbose
# option on the lp command line.
#
# PRINTLIB is the name of the directory containing the filter program.

# DEV will be filled in if the printer is added by lptool, if DEV
# remains null we will use the default device built into the driver
#
# DEV, PRINTLIB, FILTER and ALIAS_LOCATION are filled in by the ALIAS
# install_kodak script so if you change their names you will have to change
# the installation script as well
#
# TYPE is used by the lptool stuff, setting it to Color will result in a
# colorful printer icon
DEV=
NAME="Hitachi VY-5000 (SCSI)"
TYPE=Color

# Change VERBOSE flag to 1 for full logging in LOGFILE
# If VY5000LOG is non-empty, stuff is written to this file for every attempted
# print - good for seeing who is printing stuff to the kodak
VERBOSE=0
LOGFILE=log
VY5000LOG=vy5000_log
PRINTLIB=
FILTER=
TEMPFILE=/tmp/${FILTER}.$$
send=$PRINTLIB/$FILTER

trap '/bin/rm -f $TEMPFILE ; exit 0' 1 2 3 15

# have to set ALIAS_LOCATION so that security works properly
ALIAS_LOCATION=
export ALIAS_LOCATION

pr=`basename $0`

if [ ! -w "$LOGFILE" ] ; then
	disable -r"can't access log file $LOGFILE" $pr 1>/dev/console 2>&1
	exit 1
fi

if [ "$send" -a ! -x "$send" ]; then
	disable -r"can't access $send filter" $pr 1>/dev/console 2>&1
	exit 1
fi

# parse command line options
seqid=$1
name=$2
title="$3"
copies=$4
options=$5
shift; shift; shift; shift; shift
files="$*"
if [ -z "$title" ] ; then
	title=`basename $1`
fi

# check through some standard options
for j in $options
do
	case $j in
		verb*)	VERBOSE=1 ;;
		erase)	erase=$j ;;
		*)		# make sure hyphen is in front of all args
				if expr X$j : 'X-.*' > /dev/null 2>&1; then
					opts="$opts $j"
				else
					opts="$opts -$j"
				fi
	esac
done

# set up to send the job
if [ ! -x $send ] ; then
	disable -r"can't execute $send filter" $pr
	exit 1
fi

if [ $VERBOSE != 0 ]; then
	echo $pr: $seqid $name "$title" start - `date` >> $LOGFILE
fi

# now print the files
for f in $files; do
    if [ $VERBOSE != 0 ]; then
	    echo $pr: $seqid `basename $f` - `date` >> $LOGFILE
		echo $pr: $send $opts $f - `date` >> $LOGFILE
    fi

	if [ "$DEV" ]; then
		$send -D$DEV $opts $f 2> $TEMPFILE 
	else
		$send $opts $f 2> $TEMPFILE 
	fi

	status=$?
	if [ $status -ne 0 ]; then
		if [ "$VY5000LOG" ]; then
			echo $seqid print of $title by $name failed - `date` >> $VY5000LOG
			cat $TEMPFILE >> $VY5000LOG
		fi
		cat $TEMPFILE >> $LOGFILE
		#
		# only disable if it was really bad
		#
		if [ $status -eq 2 ]; then
			reason=`cat $TEMPFILE | sed -n 1p`
			disable -r"$reason" $pr
		fi
		break
	else
		if [ "$VY5000LOG" ]; then
			echo $seqid print of $title by $name succeeded - `date` >> $VY5000LOG
		fi
	fi
done

/bin/rm -f $TEMPFILE

if [ -n "$erase" ]; then
    rm -f $files
fi

if [ $VERBOSE != 0 ]; then
	echo $pr: $seqid end - `date` >> $LOGFILE
fi

exit $status
