#!/bin/bash #Device settings PRINTERLP="/dev/lp0" PRINTERUSB="/dev/usb/lp0" #default gs GS="gs -q -dBATCH -dSAFER -dNOPAUSE -dPDFFitPage -sOutputFile=- -sPaperSize=a4 " #driver for PCL-5 printers DRIVERPCL5="-sDEVICE=ijs -sIjsServer=/usr/bin/ijsgimpprint -sDeviceManufacturer=HEWLETT-PACKARD -sDeviceModel=pcl-5 -sProcessColorModel=DeviceGray -dIjsUseOutputFD -" #driver for hp PSC 1200 all in one DRIVERPSC1200="-sDEVICE=ijs -sIjsServer=hpijs -sDeviceManufacturer=HEWLETT-PACKARD -sDeviceModel='psc 1200' -sIjsParams=Quality:Quality=0,Quality:MediaType=0 -dIjsUseOutputFD -" #default is now DRIVER=$DRIVERPCL5 PRINTER=$PRINTERLP #Only text mode : To switch 1 a4 on one paper use -B or 2 a4 on one paper (landscape) use -2rB NENMODE="-2rB" #make log file echo -e "aantal parameters = $# " >> /tmp/lpm.log for i in $* do echo -e "parameter = $i " >> /tmp/lpm.log done #-- select printer -- #test parameters if [ $# -ge 1 -a -n "`echo -e $1 | grep "\-P"`" ] ; then if [ $1 = "-Php" ]; then echo "hp printer" shift 1 DRIVER=$DRIVERPCL5 PRINTER=$PRINTERLP echo -e "$DRIVER\n> $PRINTER" > /usr/bin/lpmsetup elif [ $1 = "-Phpcolor" ] ; then echo "colorprinter" shift 1 DRIVER=$DRIVERPSC1200 PRINTER=$PRINTERUSB echo -e "$DRIVER\n> $PRINTER" > /usr/bin/lpmsetup elif [ $1 = "-Psmbhp" ] ; then echo "Samba hp" shift 1 WHICHPRINTER="//BUREAU-SERVER/hp" DRIVER=$DRIVERPCL5 PRINTER="smbclient -N $WHICHPRINTER -c \"print -\"" echo -e "$DRIVER\n| $PRINTER" > /usr/bin/lpmsetup else echo "printer $1 unknown" echo "printer $1 unknown" >> /tmp/lpm.log exit 1 fi fi # test input file if [ $# -eq 1 ]; then INPUTFILE="$1" else #test is there a pipe ? #hum tyd kan niet kleiner dan 1 read -e -t1 var if [ -n "$var" ] ; then #test if /tmp/lpm.data is there , means somebody use it . while [ -e /tmp/lpm.data ] ; do sleep 10 done echo -e "$var" > /tmp/lpm.data cat <&0 >> /tmp/lpm.data echo "Read pipe to /tmp/lpm.data" >> /tmp/lpm.log INPUTFILE="/tmp/lpm.data" else #help howto rm -f /tmp/lpm.data echo -e "Useage lpm [-Php | -Phpcolor] file\nIt prints .txt .pdf .doc .rtf .ps" echo "Useage lpm [-Php | -Phpcolor] file" >> /tmp/lpm.log exit 1 fi fi #check inputfile exsist if [ ! -s $INPUTFILE ] ; then echo "file $INPUTFILE not found !" echo "file $INPUTFILE not found !" >> /tmp/lpm.log exit 1 fi #-- Text transformation -- #Find file type type="file -b $INPUTFILE" if [ -n "`$type | grep -i "PCL"`" ] ; then if [ -n "`echo -e $DRIVER | grep -i "PCL-"`" ];then INPUT="cat $INPUTFILE" GS="" DRIVER="" echo -e "Raw data for PCL printer" >> /tmp/lpm.log else echo -e "Wrong printer for PCL data" >> /tmp/lpm.log exit 1 fi elif [ -n "`$type | grep -i "data"`" ] ; then if [ -n "`echo -e $DRIVER | grep -i "PSC"`" ];then INPUT="cat $INPUTFILE" GS="" DRIVER="" echo -e "Raw data for PSC printer" >> /tmp/lpm.log else echo -e "Wrong printer for PSC data" >> /tmp/lpm.log exit 1 fi elif [ -n "`$type | grep -i "Microsoft Office Document"`" ] ; then if [ -n "`basename $INPUTFILE | grep -i ".doc"`" -o \ -n "`basename $INPUTFILE | grep -i ".rtf"`" ] ; then #test if /tmp/lpm.data is there , means somebody use it . while [ -e /tmp/lpm.data ] ; do sleep 10 done echo "Converd MS office thru abiword" > /tmp/lpm.log #cann't pipe the print output in abiword --print=- doesn't work ! INPUT="abiword --print=/tmp/lpm.data $INPUTFILE ; cat /tmp/lpm.data |" fi elif test -n "`$type | grep -i "PDF"`";then # do PDF echo PDF bestand >> /tmp/lpm.log INPUT="cat $INPUTFILE |" elif test -n "`$type | grep -i "PostScript"`";then # do Postscript echo PostScript bestand >> /tmp/lpm.log INPUT="cat $INPUTFILE |" elif test -n "`$type | grep -i "text"`";then # do nenscript echo textfile >> /tmp/lpm.log INPUT="nenscript $NENMODE -p- $INPUTFILE |" else # Unknown echo unknown file type ! >> /tmp/lpm.log exit 1 fi #get printer if no printer is given it takes the previus one DRIVER="`cat /usr/bin/lpmsetup | head -n 1`" PRINTER="`cat /usr/bin/lpmsetup | tail -n 1`" #-- execute -- #make a print script echo -e "#!/bin/sh \n$INPUT $GS $DRIVER $PRINTER" > /tmp/exepr chmod 755 /tmp/exepr #check or printer is inuse (a kind of semaphore) . cat $PRINTER 2>/tmp/printlp0 PRINTERSTATUS="cat /tmp/printlp0" while [ -n "`$PRINTERSTATUS | grep -i "busy"`" ] do sleep 60 #wait for 60 sec and try again cat /dev/lp0 2>/tmp/printlp0 PRINTERSTATUS="cat /tmp/printlp0" done #start printing /tmp/exepr #clear temp files rm -f /tmp/exepr #samba also writes in tmp , they can be very large so remove thim . #but samba seems to start lpm in /tmp so I donn't get the full path name in INPUTFILE . if [ -n "`echo -e $INPUTFILE | grep -i ^"/tmp/"`" -o -n "`echo -e $INPUTFILE | grep -i ^"smbprn"`" ] ; then echo -e `date` "remove file " $INPUTFILE >> /tmp/lpm.log rm -f $INPUTFILE fi #-- end script --