| 1 |
#!/bin/sh |
| 2 |
# This script is an input filter for printcap printing on a unix machine. It |
| 3 |
# uses the smbclient program to print the file to the specified smb-based |
| 4 |
# server and service. |
| 5 |
# For example you could have a printcap entry like this |
| 6 |
# |
| 7 |
# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint |
| 8 |
# |
| 9 |
# which would create a unix printer called "smb" that will print via this |
| 10 |
# script. You will need to create the spool directory /usr/spool/smb with |
| 11 |
# appropriate permissions and ownerships for your system. |
| 12 |
|
| 13 |
# Set these to the server and service you wish to print to |
| 14 |
# In this example I have a WfWg PC called "lapland" that has a printer |
| 15 |
# exported called "printer" with no password. |
| 16 |
|
| 17 |
# |
| 18 |
# Script further altered by [email protected] (Michael Hamilton) |
| 19 |
# so that the server, service, and password can be read from |
| 20 |
# a /usr/var/spool/lpd/PRINTNAME/.config file. |
| 21 |
# |
| 22 |
# In order for this to work the /etc/printcap entry must include an |
| 23 |
# accounting file (af=...): |
| 24 |
# |
| 25 |
# cdcolour:\ |
| 26 |
# :cm=CD IBM Colorjet on 6th:\ |
| 27 |
# :sd=/var/spool/lpd/cdcolour:\ |
| 28 |
# :af=/var/spool/lpd/cdcolour/acct:\ |
| 29 |
# :if=/usr/local/etc/smbprint:\ |
| 30 |
# :mx=0:\ |
| 31 |
# :lp=/dev/null: |
| 32 |
# |
| 33 |
# The /usr/var/spool/lpd/PRINTNAME/.config file should contain: |
| 34 |
# share=PC_SERVER |
| 35 |
# user="user" |
| 36 |
# password="password" |
| 37 |
# |
| 38 |
# Please, do not modify the order in the file. |
| 39 |
# Example: |
| 40 |
# share=\\server\deskjet |
| 41 |
# user="fred" |
| 42 |
# password="" |
| 43 |
|
| 44 |
# |
| 45 |
# The last parameter to the filter is the accounting file name. |
| 46 |
# Extract the directory name from the file name. |
| 47 |
# Concat this with /.config to get the config file. |
| 48 |
# |
| 49 |
eval acct_file="\${$#}" |
| 50 |
spool_dir=$(dirname $acct_file) |
| 51 |
config_file=$spool_dir/.config |
| 52 |
|
| 53 |
# Should read the following variables set in the config file: |
| 54 |
# share |
| 55 |
# hostip |
| 56 |
# user |
| 57 |
# password |
| 58 |
|
| 59 |
eval $(cat $config_file) |
| 60 |
|
| 61 |
share=$(echo $share | sed "s/[\]/\//g") |
| 62 |
|
| 63 |
if [ "$user" != "" ]; then |
| 64 |
usercmd="-U" |
| 65 |
else |
| 66 |
usercmd="" |
| 67 |
fi |
| 68 |
|
| 69 |
if [ "$workgroup" != "" ]; then |
| 70 |
workgroupcmd="-W" |
| 71 |
else |
| 72 |
workgroupcmd="" |
| 73 |
fi |
| 74 |
|
| 75 |
if [ "$translate" = "yes" ]; then |
| 76 |
command="translate ; print -" |
| 77 |
else |
| 78 |
command="print -" |
| 79 |
fi |
| 80 |
#echo $share $password $translate $x_command > /tmp/smbprint.log |
| 81 |
|
| 82 |
cat | /usr/bin/smbclient "$share" "$password" -E ${hostip:+-I} \ |
| 83 |
$hostip -N -P $usercmd "$user" $workgroupcmd "$workgroup" \ |
| 84 |
-c "$command" 2>/dev/null |