#!/bin/sh
#
# lpstat - fake System V lpstat(1) program for PLP installations.
#	   it'll convince most scripts, but don't think your users
#          will be fooled... ;)
#
#          most of these functions _rely_ on your lpq supporting
#          the -n option, new in PLP 3.3.0.
#
#	   -- Justin Mason <jmason@iona.ie> May '94.

PLP_DIR=/usr/local/bin

OPTSTR="drRsta:c:f:l:o:p:DlS:lu:v:"

accepting=n
default=n
sched=n
status=n

while getopts $OPTSTR opt ; do
case $opt in
  a ) accepting=y ;;
  d ) default=y ;;
  p ) status=y ;;
  r ) sched=y ;;
  s ) default=y; sched=y ;;
  t ) accepting=y; default=y; status=y; sched=y ;;

  u | v | S | R | D | c | f | l ) true ;;
esac; shift
done

date=`date`

if [ $sched = y ] ; then
  echo "scheduler is running"
fi
if [ $default = y ] ; then
  echo "system default destination: lp"
fi

if [ $accepting = y -o $status = y ] ; then
  allprinters=`$PLP_DIR/lpq -n`		# or invoke a script here
fi

if [ $accepting = y ] ; then
  for printer in $allprinters ; do
    echo "$printer accepting requests since $date"
  done
fi

if [ $status = y ] ; then
  for printer in $allprinters ; do
    echo "printer $printer online. enabled since $date. available."
    $PLP_DIR/lpq -P$printer | awk '(!/^Printer/) { print $0; }'
  done
fi
