Annotation of /mcore-src/trunk/mcore-tools/src/modules/lprng/printing.client.class.in
Parent Directory | Revision Log
Revision 2655 -
(hide annotations)
(download)
Tue Nov 10 15:13:53 2015 UTC (8 years, 6 months ago) by niro
File size: 3405 byte(s)
Tue Nov 10 15:13:53 2015 UTC (8 years, 6 months ago) by niro
File size: 3405 byte(s)
-install missing kernel modules as well
1 | niro | 1248 | # $Id$ |
2 | |||
3 | niro | 2582 | provide printing lprng |
4 | niro | 2655 | require basic-kernel |
5 | niro | 1248 | |
6 | niro | 1261 | help_printing_printer() |
7 | niro | 1248 | { |
8 | niro | 1261 | mecho "get printing.printer" |
9 | mecho " Shows all configured printers." | ||
10 | mecho | ||
11 | mecho "set printing.addprinter [action] [name] [port] [ip] [share]" | ||
12 | mecho " Adds or deletes a printer." | ||
13 | mecho " Actions:" | ||
14 | mecho " add - adds given printer" | ||
15 | mecho " del - deletes given printer" | ||
16 | mecho | ||
17 | niro | 1248 | mecho " name - name of the printer" |
18 | mecho " port - printing port (lpt1, usb1, com1 ... lptN, usbN, comN" | ||
19 | niro | 2583 | # mecho " ip - ip of the remote printer - optional" |
20 | niro | 2584 | # mecho " share - share/port name of the remote printer - optional" |
21 | niro | 1248 | } |
22 | |||
23 | niro | 1261 | helper_addprinter() |
24 | niro | 1248 | { |
25 | local name="$1" | ||
26 | local port="$2" | ||
27 | niro | 2584 | # local ip="$3" |
28 | # local share="$4" | ||
29 | niro | 1248 | |
30 | niro | 1261 | [[ -z ${name} ]] && help_printing_printer && return 1 |
31 | [[ -z ${port} ]] && help_printing_printer && return 1 | ||
32 | niro | 1248 | |
33 | niro | 2176 | [[ ! -d ${MROOT}@@SYSCONFDIR@@/printcap.d ]] && install -d ${MROOT}@@SYSCONFDIR@@/printcap.d |
34 | niro | 1248 | |
35 | case ${port} in | ||
36 | lpt[0-9]*) port="/dev/lp$(( ${port/lpt/}-1 ))" ;; | ||
37 | com[0-9]*) port="/dev/ttyS$(( ${port/com/}-1 ))" ;; | ||
38 | niro | 2177 | usb[0-9]*) port="/dev/usb/lp$(( ${port/usb/}-1 ))" ;; |
39 | niro | 1248 | #lpd) port="lpd://${ip}/${share}" ;; |
40 | #socket) port="socket://${ip}:${share}" ;; | ||
41 | esac | ||
42 | |||
43 | niro | 2176 | CONFIG="${MROOT}@@SYSCONFDIR@@/printcap.d/${name}.conf" |
44 | niro | 1647 | clearconfig |
45 | niro | 1248 | addconfig "${name}|${name}" |
46 | addconfig " :lp=${port}" | ||
47 | addconfig " :sd=/var/spool/lpd/${name}" | ||
48 | niro | 1895 | 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 | 2655 | # install required kernel modules as well |
106 | if is_provided basic-kernel | ||
107 | then | ||
108 | mcore-kernel-modules --add --module lp | ||
109 | mcore-kernel-modules --add --module usblp | ||
110 | fi | ||
111 | |||
112 | niro | 2176 | CONFIG="${MROOT}@@SYSCONFDIR@@/printcap" |
113 | niro | 1248 | clearconfig |
114 | |||
115 | niro | 2176 | for i in $(find ${MROOT}@@SYSCONFDIR@@/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 | 2586 | install -o @@LPRNG_SPOOLER_USER@@ -g @@LPRNG_SPOOLER_USER@@ -m0700 -d ${MROOT}@@LOCALSTATEDIR@@/spool/lpd/${prn} |
127 | niro | 1895 | |
128 | # create empty log files | ||
129 | niro | 2176 | install -d ${MROOT}@@LOCALSTATEDIR@@/log/lprng |
130 | touch ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn} | ||
131 | niro | 2586 | chown @@LPRNG_SPOOLER_USER@@:@@LPRNG_SPOOLER_USER@@ ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn} |
132 | niro | 2176 | chmod 0600 ${MROOT}@@LOCALSTATEDIR@@/log/lprng/${prn} |
133 | niro | 1248 | done |
134 | } |