File: mtink-cups

package info (click to toggle)
mtink 1.0.16-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,480 kB
  • ctags: 1,349
  • sloc: ansic: 19,263; sh: 1,008; python: 626; xml: 444; makefile: 75
file content (137 lines) | stat: -rwxr-xr-x 4,718 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash

### MTINK CUPS backend
### Derived from "ptal" backend from Mark J. Horn <mark at hornclan dot com>
###
### This program is free software; you can redistribute it and/or
### modify it under the terms of the GNU General Public License
### as published by the Free Software Foundation; either version 2
### of the License, or (at your option) any later version.
### 
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
### 
### You should have received a copy of the GNU General Public License
### along with this program; if not, write to the Free Software
### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
###
### A copy of the GNU General Public License is available at: 
### http://www.gnu.org/licenses/gpl.txt

### INSTALLATION
### ------------
### To use this script, copy it into your CUPS backend directory, which
### might be in /usr/lib/cups/backend or /usr/local/lib/cups/backend.
### Name it "mtink". Make sure that the script is executable by whatever
### user ID cupsd runs with, and then restart CUPS.  To make the script
### executable, run "chmod a+rx mtink" (assuming that you named the script
### "mtink").
###
### In order for CUPS to detect your MTINK-connected printer at boot time
### it will have to be started *AFTER* mtink.  If it isn't, then 
### CUPS will not detect your printer, and you will not be able to 
### configure, nor print to your printer.
###
### You should then be able to configure printers in CUPS with the
### devices you've configured.
###
### This single script can be used to support multiple devices.  Each 
### supported device needs to be announced by the script when called 
### without arguments.  CUPS determines what printers are available
### when cupsd starts.  Thus any additional devices that you add 
### will require a restart of cupsd.
###
### DEPENDENCIES
### ------------
### This script is dependent upon built-in commands in bash.  It has not
### been tested against other non-bash shells.  I don't expect that
### it will work with them.  You are invited to test other shells.
### Please let me know if you have any success.
### 
### This script depends on the correctly installed mtink drivers
### available at: http://xwtools.automatix.de/
###
### This script depends on the following programs being in the PATH
### basename, cat
### If these commands are not in /usr/bin, /bin, /usr/bin,
### or /usr/local/bin on your computer, set PATH below to include
### where they are located.

PATH=$PATH:/usr/bin:/bin:/usr/bin:/usr/local/bin

### Uncomment for crude debugging output
# DEBUG=true
### Where we log debug stuff to:
DEBUG_PRINTARGS=/tmp/printargs
DEBUG_PRINTOUT=/tmp/printout

if [ -n "$DEBUG" ]; then
	echo "Args: $0 $*" > $DEBUG_PRINTARGS
	echo "Arg1: $1" >> $DEBUG_PRINTARGS
	echo "Arg2: $2" >> $DEBUG_PRINTARGS
	echo "Arg3: $3" >> $DEBUG_PRINTARGS
	echo "Arg4: $4" >> $DEBUG_PRINTARGS
	echo "Arg5: $5" >> $DEBUG_PRINTARGS
	echo "Arg6: $6" >> $DEBUG_PRINTARGS
	echo "Arg7: $7" >> $DEBUG_PRINTARGS
	command -V basename >> $DEBUG_PRINTARGS 2>&1
	command -V cat >> $DEBUG_PRINTARGS 2>&1
	declare >> $DEBUG_PRINTARGS
fi

ME=`basename $0`

if [ -z "$*" ]; then
	for DEV in `ls -1 /var/mtink 2>/dev/null` ; do
		DESC=`basename $DEV`
		if [ $? -eq 0 ]; then 
			echo direct $ME:/$DESC \"Epson Stylus $DESC\" \"MTINK $DESC\"
		fi
	done
	exit 0
fi

### For raw printing, $6 is the file to print.  For driver processed
### printing, $6 is empty and the data to print is in stdin.
FILE=$6

### When advertising multiple printers, the script has to be able
### determine where it should send real print jobs.  This is done
### through the environment variable $DEVICE_URI
SENDTO=${DEVICE_URI#${ME}:/}

if [ -n "$DEBUG" ]; then
	echo "SENDTO: $SENDTO" >> $DEBUG_PRINTARGS
	cat $FILE > $DEBUG_PRINTOUT
	FILE=$DEBUG_PRINTOUT
fi

### We need a lock in order to avoid that more as one process
### write to the pipe. The server will work as root, so we have
### to do this externally, locking the pipe or setting the right
### to read only do not work.

while [ -f /var/lock/subsys/mtink.$SENDTO ]
do
   echo mtink:$SENDTO busy; will retry in 30 seconds... 1>&2
   sleep 30
done

### cleanup at exit
trap "rm /var/lock/mtink.$SENDTO" 1 2 3 23 13 15
### create the lock file
touch /var/lock/mtink.$SENDTO 

### process the input stream
cat $FILE > /var/mtink/$SENDTO
STAT=$?

### wait a little bit so the last data are proccessed
### by the server
sleep 5

### remove the lock file
rm /var/lock/mtink.$SENDTO 
exit $STAT