Annotation of /mcore-src/trunk/mcore-tools/src/modules/lprng/printing.client.class.in
Parent Directory | Revision Log
Revision 2646 -
(hide annotations)
(download)
Mon Nov 9 14:52:40 2015 UTC (8 years, 6 months ago) by niro
File size: 3216 byte(s)
Mon Nov 9 14:52:40 2015 UTC (8 years, 6 months ago) by niro
File size: 3216 byte(s)
-fixed lprng config loop
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 " :lf=/var/log/lprng/${name}" |
48 | niro | 1248 | |
49 | # regenerate printcap | ||
50 | helper_generate_printcap | ||
51 | } | ||
52 | |||
53 | niro | 1261 | helper_delprinter() |
54 | niro | 1248 | { |
55 | local name="$1" | ||
56 | |||
57 | niro | 1261 | [[ -z ${name} ]] && help_printing_printer && return 1 |
58 | niro | 1248 | |
59 | niro | 2176 | if [[ -f ${MROOT}@@SYSCONFDIR@@/printcap.d/${name}.conf ]] |
60 | niro | 1248 | then |
61 | niro | 2176 | rm ${MROOT}@@SYSCONFDIR@@/printcap.d/${name}.conf |
62 | niro | 1248 | fi |
63 | |||
64 | niro | 2176 | if [[ -d ${MROOT}@@LOCALSTATEDIR@@/spool/lpd/${name} ]] |
65 | niro | 1248 | then |
66 | niro | 2176 | rm -rf ${MROOT}@@LOCALSTATEDIR@@/spool/lpd/${name} |
67 | niro | 1248 | fi |
68 | |||
69 | niro | 2176 | if [[ -d ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${name} ]] |
70 | niro | 1895 | then |
71 | niro | 2176 | rm -rf ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${name} |
72 | niro | 1895 | fi |
73 | niro | 2175 | |
74 | niro | 1248 | # regenerate printcap |
75 | helper_generate_printcap | ||
76 | } | ||
77 | |||
78 | niro | 1261 | set_printing_printer() |
79 | niro | 1248 | { |
80 | niro | 2269 | local action="${CLASS_ARGV[0]}" |
81 | local name="${CLASS_ARGV[1]}" | ||
82 | local port="${CLASS_ARGV[2]}" | ||
83 | niro | 2584 | # local ip="${CLASS_ARGV[3]}" |
84 | # local share="${CLASS_ARGV[4]}" | ||
85 | niro | 1261 | |
86 | case "${action}" in | ||
87 | niro | 2584 | # add) helper_addprinter "${name}" "${port}" "${ip}" "${share}" ;; |
88 | add) helper_addprinter "${name}" "${port}";; | ||
89 | niro | 1261 | del) helper_delprinter "${name}" ;; |
90 | *) help_printing_printer && return 1 ;; | ||
91 | esac | ||
92 | niro | 1248 | } |
93 | |||
94 | get_printing_printer() | ||
95 | { | ||
96 | niro | 2176 | list_files_in_directory ${MROOT}@@SYSCONFDIR@@/printcap.d |
97 | niro | 1248 | } |
98 | |||
99 | helper_generate_printcap() | ||
100 | { | ||
101 | local i | ||
102 | niro | 1895 | local prn |
103 | niro | 1248 | |
104 | niro | 2176 | CONFIG="${MROOT}@@SYSCONFDIR@@/printcap" |
105 | niro | 1248 | clearconfig |
106 | |||
107 | niro | 2176 | for i in $(find ${MROOT}@@SYSCONFDIR@@/printcap.d -type f -name \*.conf) |
108 | niro | 1248 | do |
109 | mecho "adding ${i}" | ||
110 | addconfig "#--- added by mcored ---" | ||
111 | cat ${i} >> ${CONFIG} | ||
112 | addconfig "#-----------------------" | ||
113 | addconfig | ||
114 | |||
115 | niro | 1895 | prn=$(basename ${i} .conf) |
116 | |||
117 | niro | 1248 | # install spooler directories |
118 | niro | 2586 | install -o @@LPRNG_SPOOLER_USER@@ -g @@LPRNG_SPOOLER_USER@@ -m0700 -d ${MROOT}@@LOCALSTATEDIR@@/spool/lpd/${prn} |
119 | niro | 1895 | |
120 | # create empty log files | ||
121 | niro | 2176 | install -d ${MROOT}@@LOCALSTATEDIR@@/log/lprng |
122 | touch ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn} | ||
123 | niro | 2586 | chown @@LPRNG_SPOOLER_USER@@:@@LPRNG_SPOOLER_USER@@ ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn} |
124 | niro | 2176 | chmod 0600 ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn} |
125 | niro | 1248 | done |
126 | } |