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 $ |
# $Id$ |
2 |
# configures printing on the host via mysql db settings |
# configures printing on the host via mysql db settings |
3 |
|
|
4 |
get_printer_settings() |
get_printer_settings() |
6 |
local i all count prn_ids settings DB_PRINTER |
local i all count prn_ids settings DB_PRINTER |
7 |
|
|
8 |
# first get all printer names |
# first get all printer names |
9 |
prn_ids=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
prn_ids=$(mysqldo "select id from cfg_printers where serial='${ALX_SERIAL}'") |
|
"select id from cfg_printers where serial='${ALX_SERIAL}'") |
|
10 |
|
|
11 |
# set counter equal to numbers of printers |
# set counter equal to numbers of printers |
12 |
declare -i count=0 |
declare -i count=0 |
13 |
for i in ${prn_ids} |
for i in ${prn_ids} |
14 |
do |
do |
15 |
# now get the other settings und put them in arrays |
# now get the other settings und put them in arrays |
16 |
ALX_PRINTER_NAME[${count}]=$(mysql_command \ |
ALX_PRINTER_NAME[${count}]=$(mysqldo "select printer_name from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'") |
17 |
${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
ALX_PORT[${count}]=$(mysqldo "select port from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'") |
18 |
"select printer_name |
ALX_IP[${count}]=$(mysqldo "select ip from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'") |
19 |
from cfg_printers |
ALX_SHARE[${count}]=$(mysqldo "select share from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'") |
|
where serial='${ALX_SERIAL}' and id='${i}'") |
|
|
|
|
|
ALX_PORT[${count}]=$(mysql_command \ |
|
|
${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
|
|
"select port |
|
|
from cfg_printers |
|
|
where serial='${ALX_SERIAL}' and id='${i}'") |
|
|
|
|
|
ALX_IP[${count}]=$(mysql_command \ |
|
|
${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
|
|
"select ip |
|
|
from cfg_printers |
|
|
where serial='${ALX_SERIAL}' and id='${i}'") |
|
|
|
|
|
ALX_SHARE[${count}]=$(mysql_command \ |
|
|
${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
|
|
"select share |
|
|
from cfg_printers |
|
|
where serial='${ALX_SERIAL}' and id='${i}'") |
|
20 |
|
|
21 |
(( count++ )) |
(( count++ )) |
22 |
done |
done |
23 |
|
|
|
# DEBUG MSG |
|
|
# for (( i=0; i <= count; i++ )) |
|
|
# do |
|
|
# echo -n "${ALX_PRINTER_NAME[${i}]} " |
|
|
# echo -n "${ALX_PORT[${i}]} " |
|
|
# echo -n "${ALX_IP[${i}]} " |
|
|
# echo "${ALX_SHARE[${i}]}" |
|
|
# done |
|
|
|
|
24 |
# export all settings |
# export all settings |
25 |
export ALX_COUNT=${count} |
export ALX_COUNT=${count} |
26 |
export ALX_PRINTER_NAME |
export ALX_PRINTER_NAME |
29 |
export ALX_SHARE |
export ALX_SHARE |
30 |
} |
} |
31 |
|
|
|
config_printing_old() |
|
|
{ |
|
|
local port |
|
|
|
|
|
#first of all get the vars |
|
|
get_printer_settings |
|
|
|
|
|
# first of all delete all printers, by wiping /etc/cups/printers.conf |
|
|
# please note that cups must be restarted or reloaded or stopped |
|
|
[ -n "$(pidof cupsd)" ] && /etc/init.d/cups stop &> /dev/null |
|
|
:> /etc/cups/printers.conf |
|
|
|
|
|
# now start cups |
|
|
/etc/init.d/cups start &> /dev/null |
|
|
|
|
|
# debug |
|
|
# echo "ALX_COUNT: ${ALX_COUNT}" |
|
|
|
|
|
for (( i=0; i < ALX_COUNT; i++ )) |
|
|
do |
|
|
# get real port settings |
|
|
case ${ALX_PORT[${i}]} in |
|
|
lpt1) |
|
|
port="parallel:/dev/lp0" |
|
|
;; |
|
|
com1) |
|
|
port="serial:/dev/ttyS0?baud=9600+bits=8+parity=none+flow=none" |
|
|
;; |
|
|
com2) |
|
|
port="serial:/dev/ttyS1?baud=9600+bits=8+parity=none+flow=none" |
|
|
;; |
|
|
lpd) |
|
|
port="lpd://${ALX_IP[${i}]}/${ALX_SHARE[${i}]}" |
|
|
;; |
|
|
socket) |
|
|
port="socket://${ALX_IP[${i}]}:${ALX_SHARE[${i}]}" |
|
|
;; |
|
|
esac |
|
|
|
|
|
# now add new printers |
|
|
/usr/sbin/lpadmin -p ${ALX_PRINTER_NAME[${i}]} -E -v ${port} |
|
|
done |
|
|
} |
|
|
|
|
32 |
config_printing() |
config_printing() |
33 |
{ |
{ |
34 |
local port |
local port |
35 |
|
|
36 |
#first of all get the vars |
# first of all get the vars |
37 |
get_printer_settings |
get_printer_settings |
38 |
|
|
39 |
# first of all delete all printers, by wiping /etc/cups/printers.conf |
# first of all delete all printers, by wiping /etc/printcap and all spooler directories |
40 |
# please note that cups must be restarted or reloaded or stopped |
:> /etc/printcap |
41 |
[ -n "$(pidof cupsd)" ] && /etc/init.d/cups stop &> /dev/null |
if [[ -d /var/spool/lpd ]] |
42 |
:> /etc/cups/printers.conf |
then |
43 |
|
rm -rf /var/spool/lpd |
44 |
# debug |
install -d /var/spool/lpd |
45 |
# echo "ALX_COUNT: ${ALX_COUNT}" |
install -d /var/spool/lpd/lp |
46 |
|
chown lp:lp /var/spool/lpd/lp |
47 |
|
chmod 0700 /var/spool/lpd/lp |
48 |
|
fi |
49 |
|
|
50 |
for (( i=0; i < ALX_COUNT; i++ )) |
for (( i=0; i < ALX_COUNT; i++ )) |
51 |
do |
do |
52 |
# get real port settings |
# get real port settings |
53 |
case ${ALX_PORT[${i}]} in |
case ${ALX_PORT[${i}]} in |
54 |
lpt1) |
lpt[0-9]*) port="/dev/lp$(( ${port/lpt/}-1 ))" ;; |
55 |
port="parallel:/dev/lp0" |
com[0-9]*) port="/dev/ttyS$(( ${port/com/}-1 ))" ;; |
56 |
;; |
usb[0-9]*) port="/dev/usb/lp$(( ${port/usb/}-1 ))" ;; |
57 |
com1) |
#lpd) port="lpd://${ip}/${share}" ;; |
58 |
port="serial:/dev/ttyS0?baud=9600+bits=8+parity=none+flow=none" |
#socket) port="socket://${ip}:${share}" ;; |
|
;; |
|
|
com2) |
|
|
port="serial:/dev/ttyS1?baud=9600+bits=8+parity=none+flow=none" |
|
|
;; |
|
|
lpd) |
|
|
port="lpd://${ALX_IP[${i}]}/${ALX_SHARE[${i}]}" |
|
|
;; |
|
|
socket) |
|
|
port="socket://${ALX_IP[${i}]}:${ALX_SHARE[${i}]}" |
|
|
;; |
|
59 |
esac |
esac |
60 |
|
|
61 |
# now add new printers (writing printers.conf) |
# now add new printers (writing printcap) |
62 |
#/usr/sbin/lpadmin -p ${ALX_PRINTER_NAME[${i}]} -E -v ${port} |
echo "#--- added by alxconfig ---" >> /etc/printcap |
63 |
echo "<Printer ${ALX_PRINTER_NAME[${i}]}>" >> /etc/cups/printers.conf |
echo "${ALX_PRINTER_NAME[${i}]}|${ALX_PRINTER_NAME[${i}]}" >> /etc/printcap |
64 |
echo "Info ${ALX_PRINTER_NAME[${i}]}" >> /etc/cups/printers.conf |
echo " :lp=${port}" >> /etc/printcap |
65 |
echo "DeviceURI ${port}" >> /etc/cups/printers.conf |
echo " :sd=/var/spool/lpd/${ALX_PRINTER_NAME[${i}]}" >> /etc/printcap |
66 |
echo "State Idle" >> /etc/cups/printers.conf |
echo "#-----------------------" |
67 |
echo "Accepting Yes" >> /etc/cups/printers.conf |
echo >> /etc/printcap |
68 |
echo "JobSheets none none" >> /etc/cups/printers.conf |
|
69 |
echo "QuotaPeriod 0" >> /etc/cups/printers.conf |
# install spooler directories |
70 |
echo "PageLimit 0" >> /etc/cups/printers.conf |
install -o lp -g lp -m0700 -d /var/spool/lpd/${ALX_PRINTER_NAME[${i}]} |
|
echo "KLimit 0" >> /etc/cups/printers.conf |
|
|
echo "</Printer>" >> /etc/cups/printers.conf |
|
71 |
done |
done |
72 |
|
|
73 |
|
# start lprng if ALX_COUNT > 0 |
74 |
|
if [[ ${ALX_COUNT} != 0 ]] |
75 |
|
then |
76 |
|
rc-config add lprng &> /dev/null |
77 |
|
else |
78 |
|
rc-config del lprng &> /dev/null |
79 |
|
fi |
80 |
} |
} |