Annotation of /mcore-src/trunk/mcore-tools/src/modules/lprng/printing.client.class.in
Parent Directory | Revision Log
Revision 1647 -
(hide annotations)
(download)
Thu Mar 10 18:15:28 2011 UTC (13 years, 2 months ago) by niro
Original Path: mcore-src/trunk/mcore-tools/daemon/client/include/printing.client.class
File size: 2485 byte(s)
Thu Mar 10 18:15:28 2011 UTC (13 years, 2 months ago) by niro
Original Path: mcore-src/trunk/mcore-tools/daemon/client/include/printing.client.class
File size: 2485 byte(s)
-helper_addprinter(): added a missing clearconfig call -use rvecho() for function retvals
1 | niro | 1248 | # $Id$ |
2 | |||
3 | provide lprng | ||
4 | |||
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 | mecho " ip - ip of the remote printer - optional" | ||
19 | mecho " share - share/port name of the remote printer - optional" | ||
20 | } | ||
21 | |||
22 | niro | 1261 | helper_addprinter() |
23 | niro | 1248 | { |
24 | local name="$1" | ||
25 | local port="$2" | ||
26 | local ip="$3" | ||
27 | local share="$4" | ||
28 | |||
29 | niro | 1261 | [[ -z ${name} ]] && help_printing_printer && return 1 |
30 | [[ -z ${port} ]] && help_printing_printer && return 1 | ||
31 | niro | 1248 | |
32 | [[ ! -d /etc/printcap.d ]] && install -d /etc/printcap.d | ||
33 | |||
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 | usb[0-9]*) port="/dev/usb/lp$(( ${port/usb/}-1 ))" ;; | ||
38 | #lpd) port="lpd://${ip}/${share}" ;; | ||
39 | #socket) port="socket://${ip}:${share}" ;; | ||
40 | esac | ||
41 | |||
42 | CONFIG="/etc/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 | |||
48 | # regenerate printcap | ||
49 | helper_generate_printcap | ||
50 | } | ||
51 | |||
52 | niro | 1261 | helper_delprinter() |
53 | niro | 1248 | { |
54 | local name="$1" | ||
55 | |||
56 | niro | 1261 | [[ -z ${name} ]] && help_printing_printer && return 1 |
57 | niro | 1248 | |
58 | if [[ -f /etc/printcap.d/${name}.conf ]] | ||
59 | then | ||
60 | rm /etc/printcap.d/${name}.conf | ||
61 | fi | ||
62 | |||
63 | if [[ -d /var/spool/lpd/${name} ]] | ||
64 | then | ||
65 | rm -rf /var/spool/lpd/${name} | ||
66 | fi | ||
67 | |||
68 | # regenerate printcap | ||
69 | helper_generate_printcap | ||
70 | } | ||
71 | |||
72 | niro | 1261 | set_printing_printer() |
73 | niro | 1248 | { |
74 | niro | 1261 | local action="$1" |
75 | local name="$2" | ||
76 | local port="$3" | ||
77 | local ip="$4" | ||
78 | local share="$5" | ||
79 | |||
80 | case "${action}" in | ||
81 | add) helper_addprinter "${name}" "${port}" "${ip}" "${share}" ;; | ||
82 | del) helper_delprinter "${name}" ;; | ||
83 | *) help_printing_printer && return 1 ;; | ||
84 | esac | ||
85 | niro | 1248 | } |
86 | |||
87 | get_printing_printer() | ||
88 | { | ||
89 | local i | ||
90 | local printer | ||
91 | |||
92 | for i in $(find /etc/printcap.d -type f -name \*.conf) | ||
93 | do | ||
94 | printer="${printer} $(basename ${i} .conf)" | ||
95 | done | ||
96 | |||
97 | niro | 1647 | rvecho ${printer} |
98 | niro | 1248 | } |
99 | |||
100 | helper_generate_printcap() | ||
101 | { | ||
102 | local i | ||
103 | |||
104 | CONFIG="/etc/printcap" | ||
105 | clearconfig | ||
106 | |||
107 | for i in $(find /etc/printcap.d -type f -name \*.conf) | ||
108 | do | ||
109 | mecho "adding ${i}" | ||
110 | addconfig "#--- added by mcored ---" | ||
111 | cat ${i} >> ${CONFIG} | ||
112 | addconfig "#-----------------------" | ||
113 | addconfig | ||
114 | |||
115 | # install spooler directories | ||
116 | install -o lp -g lp -m0700 -d /var/spool/lpd/$(basename ${i} .conf) | ||
117 | done | ||
118 | } |