1 |
# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_printers.sh,v 1.7 2005-04-12 21:39:24 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 |
prn_ids=$(mysqldo "select id from cfg_printers where serial='${ALX_SERIAL}'") |
12 |
|
|
13 |
# 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 |
14 |
# please note that cups must be restarted or reloaded or stopped |
CONFIG="/etc/printcap" |
15 |
[ -n "$(pidof cupsd)" ] && /etc/init.d/cups stop &> /dev/null |
clearconfig |
|
:> /etc/cups/printers.conf |
|
16 |
|
|
17 |
# debug |
if [[ -d /var/spool/lpd ]] |
18 |
# echo "ALX_COUNT: ${ALX_COUNT}" |
then |
19 |
|
rm -rf /var/spool/lpd |
20 |
|
install -d /var/spool/lpd |
21 |
|
install -d /var/spool/lpd/lp |
22 |
|
chown lp:lp /var/spool/lpd/lp |
23 |
|
chmod 0700 /var/spool/lpd/lp |
24 |
|
fi |
25 |
|
|
26 |
for (( i=0; i < ALX_COUNT; i++ )) |
for i in ${prn_ids} |
27 |
do |
do |
28 |
|
evaluate_table cfg_printers "where serial='${ALX_SERIAL}' and id='${i}'" |
29 |
# get real port settings |
# get real port settings |
30 |
case ${ALX_PORT[${i}]} in |
case ${cfg_printers_port} in |
31 |
lpt1) |
lpt[0-9]*) port="/dev/lp$(( ${cfg_printers_port/lpt/}-1 ))" ;; |
32 |
port="parallel:/dev/lp0" |
com[0-9]*) port="/dev/ttyS$(( ${cfg_printers_port/com/}-1 ))" ;; |
33 |
;; |
usb[0-9]*) port="/dev/usb/lp$(( ${cfg_printers_port/usb/}-1 ))" ;; |
34 |
com1) |
#lpd) port="lpd://${ip}/${share}" ;; |
35 |
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}]}" |
|
|
;; |
|
36 |
esac |
esac |
37 |
|
|
38 |
# now add new printers (writing printers.conf) |
# now add new printers (writing printcap) |
39 |
#/usr/sbin/lpadmin -p ${ALX_PRINTER_NAME[${i}]} -E -v ${port} |
addconfig "#--- added by alxconfig ---" |
40 |
echo "<Printer ${ALX_PRINTER_NAME[${i}]}>" >> /etc/cups/printers.conf |
addconfig "${cfg_printers_name}|${cfg_printers_name}" |
41 |
echo "Info ${ALX_PRINTER_NAME[${i}]}" >> /etc/cups/printers.conf |
addconfig " :lp=${port}" |
42 |
echo "DeviceURI ${port}" >> /etc/cups/printers.conf |
addconfig " :sd=/var/spool/lpd/${cfg_printers_name}" |
43 |
echo "State Idle" >> /etc/cups/printers.conf |
addconfig "#-----------------------" |
44 |
echo "Accepting Yes" >> /etc/cups/printers.conf |
addconfig |
45 |
echo "JobSheets none none" >> /etc/cups/printers.conf |
|
46 |
echo "QuotaPeriod 0" >> /etc/cups/printers.conf |
# install spooler directories |
47 |
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 |
|
48 |
done |
done |
49 |
|
|
50 |
# start samba and cups if ALX_COUNT > 0 |
# start lprng |
51 |
if [[ ${ALX_COUNT} != 0 ]] |
if [[ -n ${prn_ids} ]] |
52 |
then |
then |
53 |
# echo "DEBUG: adding samba+cups" |
rc-config add lprng &> /dev/null |
|
rc-config add cups &> /dev/null |
|
|
rc-config add samba &> /dev/null |
|
54 |
else |
else |
55 |
# echo "DEBUG: deleting samba+cups" |
rc-config del lprng &> /dev/null |
|
rc-config del cups &> /dev/null |
|
|
rc-config del samba &> /dev/null |
|
56 |
fi |
fi |
57 |
} |
} |