1#!/bin/sh 
2
3# This script is an input filter for printcap printing on a unix machine. It
4# uses the smbclient program to print the file to the specified smb-based 
5# server and service.
6# For example you could have a printcap entry like this
7#
8# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint
9#
10# which would create a unix printer called "smb" that will print via this 
11# script. You will need to create the spool directory /usr/spool/smb with
12# appropriate permissions and ownerships for your system.
13
14# Set these to the server and service you wish to print to 
15# In this example I have a WfWg PC called "lapland" that has a printer 
16# exported called "printer" with no password.
17
18#
19# Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton)
20# so that the server, service, and password can be read from 
21# a /usr/var/spool/lpd/PRINTNAME/.config file.
22#
23# Script further modified by Richard Sharpe to fix some things.
24# Get rid of the -x on the first line, and add parameters
25#
26#    -t  now causes translate to be used when sending files
27#
28# In order for this to work the /etc/printcap entry must include an 
29# accounting file (af=...):
30#
31#   cdcolour:\
32#	:cm=CD IBM Colorjet on 6th:\
33#	:sd=/var/spool/lpd/cdcolour:\
34#	:af=/var/spool/lpd/cdcolour/acct:\
35#	:if=/usr/local/etc/smbprint:\
36#	:mx=0:\
37#	:lp=/dev/null:
38#
39# The /usr/var/spool/lpd/PRINTNAME/.config file should contain:
40#   server=PC_SERVER
41#   service=PR_SHARENAME
42#   password="password"
43#
44# E.g.
45#   server=PAULS_PC
46#   service=CJET_371
47#   password=""
48
49#
50# Debugging log file, change to /dev/null if you like.
51#
52logfile=/tmp/smb-print.log
53# logfile=/dev/null
54
55
56#
57# The last parameter to the filter is the accounting file name.
58#   Extract the directory name from the file name.
59#   Concat this with /.config to get the config file.
60#
61TRANS=0
62eval acct_file=\${$#}
63spool_dir=`dirname $acct_file` 
64config_file=$spool_dir/.config
65
66# Should read the following variables set in the config file:
67#   server
68#   service
69#   password
70eval `cat $config_file`
71
72while getopts t c; do
73  case $c in
74    t)
75       TRANS=1
76       ;;
77
78    '?')  # Bad parameters, ignore it ...
79       ;;
80  esac
81done
82#
83# Some debugging help, change the >> to > if you want to same space.
84#
85echo "server $server, service $service" >> $logfile
86
87(
88# NOTE You may wish to add the line `echo translate' if you want automatic
89# CR/LF translation when printing.
90	if [ $TRANS -eq 1 ]; then
91          echo translate
92        fi
93	echo "print -"
94	cat
95) | /usr/local/samba/bin/smbclient "\\\\$server\\$service" $password -U $server -N -P >> $logfile
96