Annotation of /mcore-src/trunk/mcore-tools/src/modules/lprng/printing.client.class.in
Parent Directory | Revision Log
Revision 2584 -
(hide annotations)
(download)
Thu Sep 17 14:34:57 2015 UTC (8 years, 8 months ago) by niro
File size: 3177 byte(s)
Thu Sep 17 14:34:57 2015 UTC (8 years, 8 months ago) by niro
File size: 3177 byte(s)
-disable all lpd/socket traces
1 | niro | 1248 | # $Id$ |
2 | |||
3 | niro | 2582 | provide printing lprng |
4 | niro | 1248 | |
5 | niro | 1261 | help_printing_printer() |
6 | niro | 1248 | { |
7 | niro | 1261 | mecho "get printing.printer" |
8 | mecho " Shows all configured printers." | ||
9 | mecho | ||
10 | mecho "set printing.addprinter [action] [name] [port] [ip] [share]" | ||
11 | mecho " Adds or deletes a printer." | ||
12 | mecho " Actions:" | ||
13 | mecho " add - adds given printer" | ||
14 | mecho " del - deletes given printer" | ||
15 | mecho | ||
16 | niro | 1248 | mecho " name - name of the printer" |
17 | mecho " port - printing port (lpt1, usb1, com1 ... lptN, usbN, comN" | ||
18 | niro | 2583 | # mecho " ip - ip of the remote printer - optional" |
19 | niro | 2584 | # mecho " share - share/port name of the remote printer - optional" |
20 | niro | 1248 | } |
21 | |||
22 | niro | 1261 | helper_addprinter() |
23 | niro | 1248 | { |
24 | local name="$1" | ||
25 | local port="$2" | ||
26 | niro | 2584 | # local ip="$3" |
27 | # local share="$4" | ||
28 | niro | 1248 | |
29 | niro | 1261 | [[ -z ${name} ]] && help_printing_printer && return 1 |
30 | [[ -z ${port} ]] && help_printing_printer && return 1 | ||
31 | niro | 1248 | |
32 | niro | 2176 | [[ ! -d ${MROOT}@@SYSCONFDIR@@/printcap.d ]] && install -d ${MROOT}@@SYSCONFDIR@@/printcap.d |
33 | niro | 1248 | |
34 | case ${port} in | ||
35 | lpt[0-9]*) port="/dev/lp$(( ${port/lpt/}-1 ))" ;; | ||
36 | com[0-9]*) port="/dev/ttyS$(( ${port/com/}-1 ))" ;; | ||
37 | niro | 2177 | usb[0-9]*) port="/dev/usb/lp$(( ${port/usb/}-1 ))" ;; |
38 | niro | 1248 | #lpd) port="lpd://${ip}/${share}" ;; |
39 | #socket) port="socket://${ip}:${share}" ;; | ||
40 | esac | ||
41 | |||
42 | niro | 2176 | CONFIG="${MROOT}@@SYSCONFDIR@@/printcap.d/${name}.conf" |
43 | niro | 1647 | clearconfig |
44 | niro | 1248 | addconfig "${name}|${name}" |
45 | addconfig " :lp=${port}" | ||
46 | addconfig " :sd=/var/spool/lpd/${name}" | ||
47 | niro | 1895 | addconfig " :sd=/var/spool/lpd/${name}" |
48 | addconfig " :lf=/var/log/lprng/${name}" | ||
49 | niro | 1248 | |
50 | # regenerate printcap | ||
51 | helper_generate_printcap | ||
52 | } | ||
53 | |||
54 | niro | 1261 | helper_delprinter() |
55 | niro | 1248 | { |
56 | local name="$1" | ||
57 | |||
58 | niro | 1261 | [[ -z ${name} ]] && help_printing_printer && return 1 |
59 | niro | 1248 | |
60 | niro | 2176 | if [[ -f ${MROOT}@@SYSCONFDIR@@/printcap.d/${name}.conf ]] |
61 | niro | 1248 | then |
62 | niro | 2176 | rm ${MROOT}@@SYSCONFDIR@@/printcap.d/${name}.conf |
63 | niro | 1248 | fi |
64 | |||
65 | niro | 2176 | if [[ -d ${MROOT}@@LOCALSTATEDIR@@/spool/lpd/${name} ]] |
66 | niro | 1248 | then |
67 | niro | 2176 | rm -rf ${MROOT}@@LOCALSTATEDIR@@/spool/lpd/${name} |
68 | niro | 1248 | fi |
69 | |||
70 | niro | 2176 | if [[ -d ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${name} ]] |
71 | niro | 1895 | then |
72 | niro | 2176 | rm -rf ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${name} |
73 | niro | 1895 | fi |
74 | niro | 2175 | |
75 | niro | 1248 | # regenerate printcap |
76 | helper_generate_printcap | ||
77 | } | ||
78 | |||
79 | niro | 1261 | set_printing_printer() |
80 | niro | 1248 | { |
81 | niro | 2269 | local action="${CLASS_ARGV[0]}" |
82 | local name="${CLASS_ARGV[1]}" | ||
83 | local port="${CLASS_ARGV[2]}" | ||
84 | niro | 2584 | # local ip="${CLASS_ARGV[3]}" |
85 | # local share="${CLASS_ARGV[4]}" | ||
86 | niro | 1261 | |
87 | case "${action}" in | ||
88 | niro | 2584 | # add) helper_addprinter "${name}" "${port}" "${ip}" "${share}" ;; |
89 | add) helper_addprinter "${name}" "${port}";; | ||
90 | niro | 1261 | del) helper_delprinter "${name}" ;; |
91 | *) help_printing_printer && return 1 ;; | ||
92 | esac | ||
93 | niro | 1248 | } |
94 | |||
95 | get_printing_printer() | ||
96 | { | ||
97 | niro | 2176 | list_files_in_directory ${MROOT}@@SYSCONFDIR@@/printcap.d |
98 | niro | 1248 | } |
99 | |||
100 | helper_generate_printcap() | ||
101 | { | ||
102 | local i | ||
103 | niro | 1895 | local prn |
104 | niro | 1248 | |
105 | niro | 2176 | CONFIG="${MROOT}@@SYSCONFDIR@@/printcap" |
106 | niro | 1248 | clearconfig |
107 | |||
108 | niro | 2176 | for i in $(find ${MROOT}@@SYSCONFDIR@@/printcap.d -type f -name \*.conf) |
109 | niro | 1248 | do |
110 | mecho "adding ${i}" | ||
111 | addconfig "#--- added by mcored ---" | ||
112 | cat ${i} >> ${CONFIG} | ||
113 | addconfig "#-----------------------" | ||
114 | addconfig | ||
115 | |||
116 | niro | 1895 | prn=$(basename ${i} .conf) |
117 | |||
118 | niro | 1248 | # install spooler directories |
119 | niro | 2176 | install -o lp -g lp -m0700 -d ${MROOT}@@LOCALSTATEDIR@@/spool/lpd/${prn} |
120 | niro | 1895 | |
121 | # create empty log files | ||
122 | niro | 2176 | install -d ${MROOT}@@LOCALSTATEDIR@@/log/lprng |
123 | touch ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn} | ||
124 | chown lp:lp ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn} | ||
125 | chmod 0600 ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn} | ||
126 | niro | 1248 | done |
127 | } |