xref: /plan9/sys/src/cmd/gs/lib/lprsetup.sh (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1#!/bin/sh
2# $Id: lprsetup.sh,v 1.3 2002/02/21 21:49:28 giles Exp $
3#
4# BSD PRINT FILTER SETUP utility for Ghostscript - used and tested on
5# SunOS 4.1.3, but I hope it will be useful on other BSD systems
6# See documentation for usage
7#
8
9DEVICES="bjt600.32 bjc600.32 bjc600.24 bjc600.24.3 bjc600.16 bjc600.8 bjc600.8.1 bjc600.1 bjc600.dq"
10#FILTERS="if nf tf gf vf df cf rf"
11FILTERS="if"
12
13# The port your printer is on
14PRINTERDEV=/dev/lp1
15# The kind of printer (accepted values: 'parallel' and 'serial')
16PRINTERTYPE=parallel
17
18GSDIR=/usr/local/lib/ghostscript
19GSFILTERDIR=$GSDIR/filt
20SPOOLDIR=/var/spool
21GSIF=unix-lpr.sh
22PCAP=printcap.insert
23
24PATH=/bin:/usr/bin:/usr/ucb
25export PATH
26
27if [ ! -w $GSDIR ]; then
28  echo "$GSDIR must be writable to create filter directory"
29  exit 1
30fi
31
32echo "
33Making links in the filter directory $GSFILTERDIR ...
34"
35
36#
37# Make the directory for holding the filter and links
38#
39if [ -d $GSFILTERDIR ]; then
40  echo "$GSFILTERDIR already exists - not created"
41else
42  mkdir $GSFILTERDIR
43fi
44rm -f $GSFILTERDIR/direct
45ln -s . $GSFILTERDIR/direct
46rm -f $GSFILTERDIR/indirect
47ln -s . $GSFILTERDIR/indirect
48
49#
50# Create a link from each filtertype to the real filter script
51#
52for filter in $FILTERS
53do
54  rm -f $GSFILTERDIR/gs$filter
55  ln -s  ../$GSIF $GSFILTERDIR/gs$filter
56done
57
58#
59# Create a link from each device to the filter directory
60#
61for device in $DEVICES
62do
63  dualqueue=
64  case "$device" in
65    *.dq) device=`basename $device .dq` ; dualqueue=t ;;
66  esac
67  rm -f $GSFILTERDIR/$device
68  if [ $dualqueue ]; then
69    rm -f $GSFILTERDIR/indirect/$device
70    ln -s . $GSFILTERDIR/indirect/$device
71  else
72    rm -f $GSFILTERDIR/direct/$device
73    ln -s . $GSFILTERDIR/direct/$device
74  fi
75done
76
77#
78# Create a basic printcap insert - this is made in the CURRENT directory
79#
80rm -f $PCAP
81cat > $PCAP << EOF
82# This is an example printcap insert for Ghostscript printers
83# You will probably want either to change the names for each printer
84# below (first line for each device) to something more sensible, or
85# to add additional name entries (eg cdjcolor for cdj500.24)
86# The example is shown set up for $PRINTERTYPE printers - you will need
87# to alter the entries for different or networked remote printer,
88# eg. a remote network printer would have a line something like:
89#    :lp=:rm=artemis:rp=LPT1:
90# for a PC called artemis, replacing the serial port settings
91#
92# NB/ This is only an example - it is unlikely to be complete or exactly
93# correct for your system, but is designed to illustrate filter names 
94# corresponding to the accompanying bsd-if print filter
95#
96EOF
97
98(
99previous=undefined
100for device in $DEVICES
101do
102  dualqueue=
103  case "$device" in
104    *.dq) device=`basename $device .dq` ; dualqueue=t ;;
105  esac
106  base="`echo $device | sed 's/\.[0-9][0-9]*$//'`"
107  base="`echo $base | sed 's/\.[0-9][0-9]*$//'`"
108#
109# If device listed with '.dq' suffix, we set up a separate output queue
110#
111  if [ $dualqueue ]; then
112    if [ $base != $previous ]; then
113      previous=$base
114      echo "\
115# Entry for raw device $base.raw
116$base.raw|Raw output device $base:\\
117    :lp=$PRINTERDEV:\\"
118    if test "$PRINTERTYPE" = serial
119    then
120	echo "br#19200:xc#0177777:\\"
121        echo ":ms=-parity,ixon,-opost:\\"
122    fi
123    echo ":sd=$SPOOLDIR/$base/raw:\\
124    :mx#0:sf:sh:rs:"
125    fi
126    echo "\
127# Entry for device $device (output to $base.raw)
128$device|Ghostscript device $device:\\
129    :lp=/dev/null:\\"
130  else
131    echo "\
132# Entry for device $device
133$device|Ghostscript device $device:\\
134    :lp=$PRINTERDEV:\\"
135    if test "$PRINTERTYPE" = serial
136    then
137	echo "br#19200:xc#0177777:\\"
138        echo ":ms=-parity,ixon,-opost:\\"
139    fi
140  fi
141  echo "\
142    :sd=$SPOOLDIR/$base:\\
143    :lf=$SPOOLDIR/$base/logfile:\\
144    :af=$SPOOLDIR/$base/acct:\\"
145  for filter in $FILTERS
146  do
147    if [ $dualqueue ]; then
148      echo "\
149    :$filter=$GSFILTERDIR/indirect/$device/gs$filter:\\"
150    else
151      echo "\
152    :$filter=$GSFILTERDIR/direct/$device/gs$filter:\\"
153    fi
154  done
155  echo "\
156    :mx#0:sf:sh:rs:"
157done
158) >> $PCAP
159
160echo "
161Example printcap insert file \"$PCAP\" now created"
162
163#
164# Remind the user what's still to do
165#
166
167echo "
168NB/ You will need to create the following directories, with
169appropriate permissions, and do 'touch logfile' and 'touch acct'
170in the top level directories (ie. not the 'raw' ones):
171"
172(
173for device in $DEVICES
174do
175  dualqueue=
176  case "$device" in
177    *.dq) device=`basename $device .dq` ; dualqueue=t ;;
178  esac
179  base="`echo $device | sed 's/\.[0-9][0-9]*$//'`"
180  base="`echo $base | sed 's/\.[0-9][0-9]*$//'`"
181  echo "  $SPOOLDIR/$base"
182  if [ $dualqueue ]; then
183    echo "  $SPOOLDIR/$base/raw"
184  fi
185done
186) | sort -u
187
188echo "
189        + + + "
190