cvsdist bd5b9b5
#!/bin/sh
cvsdist bd5b9b5
# This script is an input filter for printcap printing on a unix machine. It
cvsdist bd5b9b5
# uses the smbclient program to print the file to the specified smb-based 
cvsdist bd5b9b5
# server and service.
cvsdist bd5b9b5
# For example you could have a printcap entry like this
cvsdist bd5b9b5
#
cvsdist bd5b9b5
# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint
cvsdist bd5b9b5
#
cvsdist bd5b9b5
# which would create a unix printer called "smb" that will print via this 
cvsdist bd5b9b5
# script. You will need to create the spool directory /usr/spool/smb with
cvsdist bd5b9b5
# appropriate permissions and ownerships for your system.
cvsdist bd5b9b5
cvsdist bd5b9b5
# Set these to the server and service you wish to print to 
cvsdist bd5b9b5
# In this example I have a WfWg PC called "lapland" that has a printer 
cvsdist bd5b9b5
# exported called "printer" with no password.
cvsdist bd5b9b5
cvsdist bd5b9b5
#
cvsdist bd5b9b5
# Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton)
cvsdist bd5b9b5
# so that the server, service, and password can be read from 
cvsdist bd5b9b5
# a /usr/var/spool/lpd/PRINTNAME/.config file.
cvsdist bd5b9b5
#
cvsdist bd5b9b5
# In order for this to work the /etc/printcap entry must include an 
cvsdist bd5b9b5
# accounting file (af=...):
cvsdist bd5b9b5
#
cvsdist bd5b9b5
#   cdcolour:\
cvsdist bd5b9b5
#	:cm=CD IBM Colorjet on 6th:\
cvsdist bd5b9b5
#	:sd=/var/spool/lpd/cdcolour:\
cvsdist bd5b9b5
#	:af=/var/spool/lpd/cdcolour/acct:\
cvsdist bd5b9b5
#	:if=/usr/local/etc/smbprint:\
cvsdist bd5b9b5
#	:mx=0:\
cvsdist bd5b9b5
#	:lp=/dev/null:
cvsdist bd5b9b5
#
cvsdist bd5b9b5
# The /usr/var/spool/lpd/PRINTNAME/.config file should contain:
cvsdist bd5b9b5
#   share=PC_SERVER
cvsdist bd5b9b5
#   user="user"
cvsdist bd5b9b5
#   password="password"
cvsdist bd5b9b5
#
cvsdist bd5b9b5
# Please, do not modify the order in the file.
cvsdist bd5b9b5
# Example:
cvsdist bd5b9b5
#   share=\\server\deskjet
cvsdist bd5b9b5
#   user="fred"
cvsdist bd5b9b5
#   password=""
cvsdist bd5b9b5
cvsdist bd5b9b5
#
cvsdist bd5b9b5
# The last parameter to the filter is the accounting file name.
cvsdist bd5b9b5
#   Extract the directory name from the file name.
cvsdist bd5b9b5
#   Concat this with /.config to get the config file.
cvsdist bd5b9b5
#
cvsdist e56dc1b
eval acct_file=\${$#}
cvsdist bd5b9b5
spool_dir=`dirname $acct_file` 
cvsdist bd5b9b5
config_file=$spool_dir/.config
cvsdist bd5b9b5
cvsdist bd5b9b5
# Should read the following variables set in the config file:
cvsdist bd5b9b5
#   share
cvsdist bd5b9b5
#   hostip
cvsdist bd5b9b5
#   user
cvsdist bd5b9b5
#   password
cvsdist bd5b9b5
cvsdist bd5b9b5
eval `cat $config_file`
cvsdist bd5b9b5
cvsdist bd5b9b5
share=`echo $share | sed "s/[\]/\//g"`
cvsdist bd5b9b5
cvsdist bd5b9b5
if [ "$user" != "" ]; then
cvsdist bd5b9b5
   usercmd="-U"
cvsdist bd5b9b5
else
cvsdist bd5b9b5
   usercmd=""
cvsdist bd5b9b5
fi
cvsdist bd5b9b5
cvsdist bd5b9b5
if [ "$workgroup" != "" ]; then
cvsdist bd5b9b5
   workgroupcmd="-W"
cvsdist bd5b9b5
else
cvsdist bd5b9b5
   workgroupcmd=""
cvsdist bd5b9b5
fi
cvsdist bd5b9b5
cvsdist bd5b9b5
if [ "$translate" = "yes" ]; then
cvsdist bd5b9b5
 command="translate ; print -"
cvsdist bd5b9b5
else
cvsdist bd5b9b5
 command="print -"
cvsdist bd5b9b5
fi
cvsdist bd5b9b5
#echo $share $password $translate $x_command > /tmp/smbprint.log
cvsdist bd5b9b5
cvsdist bd5b9b5
cat | /usr/bin/smbclient "$share" "$password" -E ${hostip:+-I} \
cvsdist bd5b9b5
     $hostip -N -P $usercmd "$user" $workgroupcmd "$workgroup" \
cvsdist bd5b9b5
     -c "$command" 2>/dev/null