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 |
|
|
|
get_printer_settings() |
|
|
{ |
|
|
local i all count prn_ids settings DB_PRINTER |
|
|
|
|
|
# first get all printer names |
|
|
prn_ids=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
|
|
"select id from cfg_printers where serial='${ALX_SERIAL}'") |
|
|
|
|
|
# set counter equal to numbers of printers |
|
|
declare -i count=0 |
|
|
for i in ${prn_ids} |
|
|
do |
|
|
# now get the other settings und put them in arrays |
|
|
ALX_PRINTER_NAME[${count}]=$(mysql_command \ |
|
|
${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ |
|
|
"select printer_name |
|
|
from cfg_printers |
|
|
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}'") |
|
|
|
|
|
(( count++ )) |
|
|
done |
|
|
|
|
|
# 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 |
|
|
|
|
|
# export all settings |
|
|
export ALX_COUNT=${count} |
|
|
export ALX_PRINTER_NAME |
|
|
export ALX_PORT |
|
|
export ALX_IP |
|
|
export ALX_SHARE |
|
|
} |
|
|
|
|
|
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 |
|
|
} |
|
|
|
|
4 |
config_printing() |
config_printing() |
5 |
{ |
{ |
6 |
local port |
local port |
7 |
|
local CONFIG |
8 |
|
local prn_ids |
9 |
|
|
10 |
#first of all get the vars |
# first of all get the vars |
11 |
get_printer_settings |
get_printer_settings |
12 |
|
prn_ids=$(mysqldo "select id from cfg_printers where serial='${ALX_SERIAL}'") |
13 |
|
|
14 |
# 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 |
15 |
# please note that cups must be restarted or reloaded or stopped |
CONFIG=/etc/printcap |
16 |
[ -n "$(pidof cupsd)" ] && /etc/init.d/cups stop &> /dev/null |
clearconfig |
17 |
:> /etc/cups/printers.conf |
|
18 |
|
if [[ -d /var/spool/lpd ]] |
19 |
# debug |
then |
20 |
# echo "ALX_COUNT: ${ALX_COUNT}" |
rm -rf /var/spool/lpd |
21 |
|
install -d /var/spool/lpd |
22 |
|
install -d /var/spool/lpd/lp |
23 |
|
chown lp:lp /var/spool/lpd/lp |
24 |
|
chmod 0700 /var/spool/lpd/lp |
25 |
|
fi |
26 |
|
|
27 |
for (( i=0; i < ALX_COUNT; i++ )) |
for i in ${prn_ids} |
28 |
do |
do |
29 |
|
evaluate_table cfg_printers "where serial='${ALX_SERIAL}' and id='${i}'" |
30 |
# get real port settings |
# get real port settings |
31 |
case ${ALX_PORT[${i}]} in |
case ${cfg_printers_port} in |
32 |
lpt1) |
lpt[0-9]*) port="/dev/lp$(( ${cfg_printers_port/lpt/}-1 ))" ;; |
33 |
port="parallel:/dev/lp0" |
com[0-9]*) port="/dev/ttyS$(( ${cfg_printers_port/com/}-1 ))" ;; |
34 |
;; |
usb[0-9]*) port="/dev/usb/lp$(( $cfg_printers_port/usb/}-1 ))" ;; |
35 |
com1) |
#lpd) port="lpd://${ip}/${share}" ;; |
36 |
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}]}" |
|
|
;; |
|
37 |
esac |
esac |
38 |
|
|
39 |
# now add new printers (writing printers.conf) |
# now add new printers (writing printcap) |
40 |
#/usr/sbin/lpadmin -p ${ALX_PRINTER_NAME[${i}]} -E -v ${port} |
addconfig "#--- added by alxconfig ---" |
41 |
echo "<Printer ${ALX_PRINTER_NAME[${i}]}>" >> /etc/cups/printers.conf |
addconfig "${cfg_printers_name}|${cfg_printers_name}" |
42 |
echo "Info ${ALX_PRINTER_NAME[${i}]}" >> /etc/cups/printers.conf |
addconfig " :lp=${port}" |
43 |
echo "DeviceURI ${port}" >> /etc/cups/printers.conf |
addconfig " :sd=/var/spool/lpd/${cfg_printers_name}" |
44 |
echo "State Idle" >> /etc/cups/printers.conf |
addconfig "#-----------------------" |
45 |
echo "Accepting Yes" >> /etc/cups/printers.conf |
addconfig |
46 |
echo "JobSheets none none" >> /etc/cups/printers.conf |
|
47 |
echo "QuotaPeriod 0" >> /etc/cups/printers.conf |
# install spooler directories |
48 |
echo "PageLimit 0" >> /etc/cups/printers.conf |
install -o lp -g lp -m0700 -d /var/spool/lpd/${cfg_printers_name} |
|
echo "KLimit 0" >> /etc/cups/printers.conf |
|
|
echo "</Printer>" >> /etc/cups/printers.conf |
|
49 |
done |
done |
50 |
|
|
51 |
|
# start lprng |
52 |
|
if [[ -n ${prn_ids} ]] |
53 |
|
then |
54 |
|
rc-config add lprng &> /dev/null |
55 |
|
else |
56 |
|
rc-config del lprng &> /dev/null |
57 |
|
fi |
58 |
} |
} |