brother_lpdwrapper_HL1210W2 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #! /bin/sh
  2. #
  3. # CUPS filter for HL1210W
  4. # Copyright Brother Industries,Ltd 2006-2014
  5. #
  6. # Ver1.05
  7. # This program is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU General Public License as published by the Free
  9. # Software Foundation; either version 2 of the License, or (at your option)
  10. # any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful, but WITHOUT
  13. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. # more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along with
  18. # this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  19. # Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. LOGFILE="/dev/null"
  22. LOGCLEVEL="7"
  23. DEBUG=0
  24. LOG_LATESTONLY=1
  25. PRINTER=HL1210W
  26. BASEDIR=/opt/brother/Printers/$PRINTER/
  27. LATESTINFO=/tmp/HL1210W_latest_print_info
  28. rm -f $LATESTINFO
  29. touch $LATESTINFO
  30. options="$5"
  31. if [ "$(echo $options | grep 'force-debug=1')" != '' ];then
  32. DEBUG=1
  33. elif [ "$(echo $options | grep 'force-debug=2')" != '' ];then
  34. DEBUG=2
  35. elif [ "$(echo $options | grep 'force-debug=3')" != '' ];then
  36. DEBUG=3
  37. elif [ "$(echo $options | grep 'force-debug=4')" != '' ];then
  38. DEBUG=4
  39. fi
  40. errorcode=0
  41. set +o noclobber
  42. if [ $DEBUG != 0 ]; then
  43. LOGFILE=/tmp/br_cupsfilter_debug_log
  44. fi
  45. if [ "$PPD" = "" ]; then
  46. PPD="/usr/share/cups/model/$PRINTER.ppd"
  47. fi
  48. if [ $LOGFILE != "/dev/null" ]; then
  49. if [ $LOG_LATESTONLY = "1" ]; then
  50. rm -f $LOGFILE
  51. date >$LOGFILE
  52. else
  53. if [ -e $LOGFILE ]; then
  54. date >>$LOGFILE
  55. else
  56. date >$LOGFILE
  57. fi
  58. fi
  59. echo "arg0 = $0" >>$LOGFILE
  60. echo "arg1 = $1" >>$LOGFILE
  61. echo "arg2 = $2" >>$LOGFILE
  62. echo "arg3 = $3" >>$LOGFILE
  63. echo "arg4 = $4" >>$LOGFILE
  64. echo "arg5 = $5" >>$LOGFILE
  65. echo "arg6 = $6" >>$LOGFILE
  66. echo "PPD = $PPD" >>$LOGFILE
  67. fi
  68. TMP_RC=/tmp/brHL1210Wrc_$$
  69. cp /opt/brother/Printers/$PRINTER//inf/brHL1210Wrc $TMP_RC
  70. export BRPRINTERRCFILE=$TMP_RC
  71. if [ $DEBUG != 0 ]; then
  72. echo BRPRINTERRCFILE=$BRPRINTERRCFILE >>$LOGFILE
  73. fi
  74. if [ -e "/$BASEDIR/lpd/filter_"${PRINTER}"" ]; then
  75. :
  76. else
  77. echo "ERROR: /$BASEDIR/lpd/filter_"$PRINTER" does not exist" >>$LOGFILE
  78. echo "ERROR: /$BASEDIR/lpd/filter_"$PRINTER" does not exist" >> $LATESTINFO
  79. errorcode=2
  80. rm $TMP_RC
  81. exit
  82. fi
  83. if [ -e "/opt/brother/Printers/$PRINTER//cupswrapper/brcupsconfig4" ]; then
  84. if [ $DEBUG = 0 ]; then
  85. /opt/brother/Printers/$PRINTER//cupswrapper/brcupsconfig4 $PRINTER $PPD 0 "$options" >> /dev/null
  86. else
  87. /opt/brother/Printers/$PRINTER//cupswrapper/brcupsconfig4 $PRINTER $PPD $LOGCLEVEL "$options" >>$LOGFILE
  88. fi
  89. fi
  90. if [ $DEBUG = 0 ]; then
  91. if [ $# -ge 7 ]; then
  92. cat $6 | /$BASEDIR/lpd/filter_"$PRINTER"
  93. else
  94. cat | /$BASEDIR/lpd/filter_"$PRINTER"
  95. fi
  96. echo brHL1210Wrc_$$ >> $LATESTINFO
  97. cat $TMP_RC >> $LATESTINFO
  98. rm $TMP_RC
  99. exit $errorcode
  100. else
  101. ## ---------------- for debug
  102. echo --------------------------- >>$LOGFILE
  103. cat $BRPRINTERRCFILE >>$LOGFILE
  104. echo --------------------------- >>$LOGFILE
  105. INPUT_TEMP_PS=`mktemp /tmp/br_input_ps.XXXXXX`
  106. if [ $# -ge 7 ]; then
  107. cat $6 > $INPUT_TEMP_PS
  108. else
  109. cat > $INPUT_TEMP_PS
  110. fi
  111. case $DEBUG in
  112. 1)
  113. export LPD_DEBUG=1
  114. cat $INPUT_TEMP_PS | /$BASEDIR/lpd/filter_"$PRINTER"
  115. ;;
  116. 2)
  117. export LPD_DEBUG=2
  118. echo "" >>$LOGFILE
  119. echo " ------PostScript Data-------" >>$LOGFILE
  120. cat $INPUT_TEMP_PS >>$LOGFILE
  121. cat $INPUT_TEMP_PS | /$BASEDIR/lpd/filter_"$PRINTER"
  122. ;;
  123. 3)
  124. export LPD_DEBUG=3
  125. echo "" >>$LOGFILE
  126. echo " ------PostScript Data-------" >>$LOGFILE
  127. cat $INPUT_TEMP_PS >>$LOGFILE
  128. ;;
  129. 4)
  130. export LPD_DEBUG=4
  131. echo "" >>$LOGFILE
  132. echo " ------PostScript Data-------" >>$LOGFILE
  133. cat $INPUT_TEMP_PS >>$LOGFILE
  134. echo " ------Print Data-------" >>$LOGFILE
  135. cat $INPUT_TEMP_PS | /$BASEDIR/lpd/filter_"$PRINTER" | hexdump -C >>$LOGFILE
  136. ;;
  137. esac
  138. rm
  139. echo brHL1210Wrc_$$ >> $LATESTINFO
  140. cat $TMP_RC >> $LATESTINFO
  141. rm $TMP_RC
  142. fi
  143. exit