1 |
# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_printers.sh,v 1.8 2005-04-20 11:46:41 niro Exp $ |
# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_printers.sh,v 1.9 2005-10-09 21:29:41 niro Exp $ |
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/cups/printers.conf |
41 |
[ -n "$(pidof cupsd)" ] && /etc/init.d/cups stop &> /dev/null |
[ -n "$(pidof cupsd)" ] && /etc/init.d/cups stop &> /dev/null |
42 |
:> /etc/cups/printers.conf |
:> /etc/cups/printers.conf |
43 |
|
|
|
# debug |
|
|
# echo "ALX_COUNT: ${ALX_COUNT}" |
|
|
|
|
44 |
for (( i=0; i < ALX_COUNT; i++ )) |
for (( i=0; i < ALX_COUNT; i++ )) |
45 |
do |
do |
46 |
# get real port settings |
# get real port settings |
50 |
;; |
;; |
51 |
com1) |
com1) |
52 |
port="serial:/dev/ttyS0?baud=9600+bits=8+parity=none+flow=none" |
port="serial:/dev/ttyS0?baud=9600+bits=8+parity=none+flow=none" |
53 |
;; |
;;# echo "DEBUG: deleting samba+cups+inetd" |
54 |
com2) |
com2) |
55 |
port="serial:/dev/ttyS1?baud=9600+bits=8+parity=none+flow=none" |
port="serial:/dev/ttyS1?baud=9600+bits=8+parity=none+flow=none" |
56 |
;; |
;; |
63 |
esac |
esac |
64 |
|
|
65 |
# now add new printers (writing printers.conf) |
# now add new printers (writing printers.conf) |
|
#/usr/sbin/lpadmin -p ${ALX_PRINTER_NAME[${i}]} -E -v ${port} |
|
66 |
echo "<Printer ${ALX_PRINTER_NAME[${i}]}>" >> /etc/cups/printers.conf |
echo "<Printer ${ALX_PRINTER_NAME[${i}]}>" >> /etc/cups/printers.conf |
67 |
echo "Info ${ALX_PRINTER_NAME[${i}]}" >> /etc/cups/printers.conf |
echo "Info ${ALX_PRINTER_NAME[${i}]}" >> /etc/cups/printers.conf |
68 |
echo "DeviceURI ${port}" >> /etc/cups/printers.conf |
echo "DeviceURI ${port}" >> /etc/cups/printers.conf |
81 |
# start samba and cups if ALX_COUNT > 0 |
# start samba and cups if ALX_COUNT > 0 |
82 |
if [[ ${ALX_COUNT} != 0 ]] |
if [[ ${ALX_COUNT} != 0 ]] |
83 |
then |
then |
|
# echo "DEBUG: adding samba+cups+inetd" |
|
84 |
rc-config add inetd &> /dev/null |
rc-config add inetd &> /dev/null |
85 |
rc-config add cups &> /dev/null |
rc-config add cups &> /dev/null |
86 |
rc-config add samba &> /dev/null |
rc-config add samba &> /dev/null |
87 |
else |
else |
|
# echo "DEBUG: deleting samba+cups+inetd" |
|
88 |
rc-config del inetd &> /dev/null |
rc-config del inetd &> /dev/null |
89 |
rc-config del cups &> /dev/null |
rc-config del cups &> /dev/null |
90 |
rc-config del samba &> /dev/null |
rc-config del samba &> /dev/null |