You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
5.3 KiB

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