Contents of /alx-src/tags/alxconf-0_6_0-rc8/functions/config_printers.sh
Parent Directory | Revision Log
Revision 241 -
(show annotations)
(download)
(as text)
Tue Apr 12 20:54:19 2005 UTC (19 years, 5 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/functions/config_printers.sh
File MIME type: application/x-sh
File size: 4097 byte(s)
Tue Apr 12 20:54:19 2005 UTC (19 years, 5 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/functions/config_printers.sh
File MIME type: application/x-sh
File size: 4097 byte(s)
removed debug messages (commented them out)
1 | # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_printers.sh,v 1.6 2005-04-12 20:54:13 niro Exp $ |
2 | # configures printing on the host via mysql db settings |
3 | |
4 | get_printer_settings() |
5 | { |
6 | local i all count prn_ids settings DB_PRINTER |
7 | |
8 | # first get all printer names |
9 | prn_ids=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
10 | "select id from cfg_printers where serial='${ALX_SERIAL}'") |
11 | |
12 | # set counter equal to numbers of printers |
13 | declare -i count=0 |
14 | for i in ${prn_ids} |
15 | do |
16 | # now get the other settings und put them in arrays |
17 | ALX_PRINTER_NAME[${count}]=$(mysql_command \ |
18 | ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
19 | "select printer_name |
20 | from cfg_printers |
21 | where serial='${ALX_SERIAL}' and id='${i}'") |
22 | |
23 | ALX_PORT[${count}]=$(mysql_command \ |
24 | ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
25 | "select port |
26 | from cfg_printers |
27 | where serial='${ALX_SERIAL}' and id='${i}'") |
28 | |
29 | ALX_IP[${count}]=$(mysql_command \ |
30 | ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
31 | "select ip |
32 | from cfg_printers |
33 | where serial='${ALX_SERIAL}' and id='${i}'") |
34 | |
35 | ALX_SHARE[${count}]=$(mysql_command \ |
36 | ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
37 | "select share |
38 | from cfg_printers |
39 | where serial='${ALX_SERIAL}' and id='${i}'") |
40 | |
41 | (( count++ )) |
42 | done |
43 | |
44 | # DEBUG MSG |
45 | # for (( i=0; i <= count; i++ )) |
46 | # do |
47 | # echo -n "${ALX_PRINTER_NAME[${i}]} " |
48 | # echo -n "${ALX_PORT[${i}]} " |
49 | # echo -n "${ALX_IP[${i}]} " |
50 | # echo "${ALX_SHARE[${i}]}" |
51 | # done |
52 | |
53 | # export all settings |
54 | export ALX_COUNT=${count} |
55 | export ALX_PRINTER_NAME |
56 | export ALX_PORT |
57 | export ALX_IP |
58 | export ALX_SHARE |
59 | } |
60 | |
61 | config_printing_old() |
62 | { |
63 | local port |
64 | |
65 | #first of all get the vars |
66 | get_printer_settings |
67 | |
68 | # first of all delete all printers, by wiping /etc/cups/printers.conf |
69 | # please note that cups must be restarted or reloaded or stopped |
70 | [ -n "$(pidof cupsd)" ] && /etc/init.d/cups stop &> /dev/null |
71 | :> /etc/cups/printers.conf |
72 | |
73 | # now start cups |
74 | /etc/init.d/cups start &> /dev/null |
75 | |
76 | # debug |
77 | # echo "ALX_COUNT: ${ALX_COUNT}" |
78 | |
79 | for (( i=0; i < ALX_COUNT; i++ )) |
80 | do |
81 | # get real port settings |
82 | case ${ALX_PORT[${i}]} in |
83 | lpt1) |
84 | port="parallel:/dev/lp0" |
85 | ;; |
86 | com1) |
87 | port="serial:/dev/ttyS0?baud=9600+bits=8+parity=none+flow=none" |
88 | ;; |
89 | com2) |
90 | port="serial:/dev/ttyS1?baud=9600+bits=8+parity=none+flow=none" |
91 | ;; |
92 | lpd) |
93 | port="lpd://${ALX_IP[${i}]}/${ALX_SHARE[${i}]}" |
94 | ;; |
95 | socket) |
96 | port="socket://${ALX_IP[${i}]}:${ALX_SHARE[${i}]}" |
97 | ;; |
98 | esac |
99 | |
100 | # now add new printers |
101 | /usr/sbin/lpadmin -p ${ALX_PRINTER_NAME[${i}]} -E -v ${port} |
102 | done |
103 | } |
104 | |
105 | config_printing() |
106 | { |
107 | local port |
108 | |
109 | #first of all get the vars |
110 | get_printer_settings |
111 | |
112 | # first of all delete all printers, by wiping /etc/cups/printers.conf |
113 | # please note that cups must be restarted or reloaded or stopped |
114 | [ -n "$(pidof cupsd)" ] && /etc/init.d/cups stop &> /dev/null |
115 | :> /etc/cups/printers.conf |
116 | |
117 | # debug |
118 | # echo "ALX_COUNT: ${ALX_COUNT}" |
119 | |
120 | for (( i=0; i < ALX_COUNT; i++ )) |
121 | do |
122 | # get real port settings |
123 | case ${ALX_PORT[${i}]} in |
124 | lpt1) |
125 | port="parallel:/dev/lp0" |
126 | ;; |
127 | com1) |
128 | port="serial:/dev/ttyS0?baud=9600+bits=8+parity=none+flow=none" |
129 | ;; |
130 | com2) |
131 | port="serial:/dev/ttyS1?baud=9600+bits=8+parity=none+flow=none" |
132 | ;; |
133 | lpd) |
134 | port="lpd://${ALX_IP[${i}]}/${ALX_SHARE[${i}]}" |
135 | ;; |
136 | socket) |
137 | port="socket://${ALX_IP[${i}]}:${ALX_SHARE[${i}]}" |
138 | ;; |
139 | esac |
140 | |
141 | # now add new printers (writing printers.conf) |
142 | #/usr/sbin/lpadmin -p ${ALX_PRINTER_NAME[${i}]} -E -v ${port} |
143 | echo "<Printer ${ALX_PRINTER_NAME[${i}]}>" >> /etc/cups/printers.conf |
144 | echo "Info ${ALX_PRINTER_NAME[${i}]}" >> /etc/cups/printers.conf |
145 | echo "DeviceURI ${port}" >> /etc/cups/printers.conf |
146 | echo "State Idle" >> /etc/cups/printers.conf |
147 | echo "Accepting Yes" >> /etc/cups/printers.conf |
148 | echo "JobSheets none none" >> /etc/cups/printers.conf |
149 | echo "QuotaPeriod 0" >> /etc/cups/printers.conf |
150 | echo "PageLimit 0" >> /etc/cups/printers.conf |
151 | echo "KLimit 0" >> /etc/cups/printers.conf |
152 | echo "</Printer>" >> /etc/cups/printers.conf |
153 | done |
154 | } |