Annotation of /mcore-src/trunk/mcore-tools/daemon/client/include/printing.client.class
Parent Directory | Revision Log
Revision 2011 -
(hide annotations)
(download)
Mon Aug 13 09:52:58 2012 UTC (11 years, 8 months ago) by niro
File size: 2957 byte(s)
Mon Aug 13 09:52:58 2012 UTC (11 years, 8 months ago) by niro
File size: 2957 byte(s)
-support $MROOT variable
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 | niro | 2011 | [[ ! -d ${MROOT}/etc/printcap.d ]] && install -d ${MROOT}/etc/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 | 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 | niro | 2011 | CONFIG="${MROOT}/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 | 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 | 2011 | if [[ -f ${MROOT}/etc/printcap.d/${name}.conf ]] |
61 | niro | 1248 | then |
62 | niro | 2011 | rm ${MROOT}/etc/printcap.d/${name}.conf |
63 | niro | 1248 | fi |
64 | |||
65 | niro | 2011 | if [[ -d ${MROOT}/var/spool/lpd/${name} ]] |
66 | niro | 1248 | then |
67 | niro | 2011 | rm -rf ${MROOT}/var/spool/lpd/${name} |
68 | niro | 1248 | fi |
69 | |||
70 | niro | 2011 | if [[ -d ${MROOT}/var/log/lprng/${name} ]] |
71 | niro | 1895 | then |
72 | niro | 2011 | rm -rf ${MROOT}/var/log/lprng/${name} |
73 | niro | 1895 | fi |
74 | |||
75 | niro | 1248 | # regenerate printcap |
76 | helper_generate_printcap | ||
77 | } | ||
78 | |||
79 | niro | 1261 | set_printing_printer() |
80 | niro | 1248 | { |
81 | niro | 1261 | local action="$1" |
82 | local name="$2" | ||
83 | local port="$3" | ||
84 | local ip="$4" | ||
85 | local share="$5" | ||
86 | |||
87 | case "${action}" in | ||
88 | add) helper_addprinter "${name}" "${port}" "${ip}" "${share}" ;; | ||
89 | del) helper_delprinter "${name}" ;; | ||
90 | *) help_printing_printer && return 1 ;; | ||
91 | esac | ||
92 | niro | 1248 | } |
93 | |||
94 | get_printing_printer() | ||
95 | { | ||
96 | local i | ||
97 | local printer | ||
98 | |||
99 | for i in $(find /etc/printcap.d -type f -name \*.conf) | ||
100 | do | ||
101 | printer="${printer} $(basename ${i} .conf)" | ||
102 | done | ||
103 | |||
104 | niro | 1647 | rvecho ${printer} |
105 | niro | 1248 | } |
106 | |||
107 | helper_generate_printcap() | ||
108 | { | ||
109 | local i | ||
110 | niro | 1895 | local prn |
111 | niro | 1248 | |
112 | niro | 2011 | CONFIG="${MROOT}/etc/printcap" |
113 | niro | 1248 | clearconfig |
114 | |||
115 | niro | 2011 | for i in $(find ${MROOT}/etc/printcap.d -type f -name \*.conf) |
116 | niro | 1248 | do |
117 | mecho "adding ${i}" | ||
118 | addconfig "#--- added by mcored ---" | ||
119 | cat ${i} >> ${CONFIG} | ||
120 | addconfig "#-----------------------" | ||
121 | addconfig | ||
122 | |||
123 | niro | 1895 | prn=$(basename ${i} .conf) |
124 | |||
125 | niro | 1248 | # install spooler directories |
126 | niro | 2011 | install -o lp -g lp -m0700 -d ${MROOT}/var/spool/lpd/${prn} |
127 | niro | 1895 | |
128 | # create empty log files | ||
129 | niro | 2011 | install -d ${MROOT}/var/log/lprng |
130 | touch ${MROOT}/var/log/lprng/${prn} | ||
131 | chown lp:lp ${MROOT}/var/log/lprng/${prn} | ||
132 | chmod 0600 ${MROOT}/var/log/lprng/${prn} | ||
133 | niro | 1248 | done |
134 | } |