Magellan Linux

Annotation of /alx-src/branches/alxconf-060/functions/config_printers.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2126 - (hide annotations) (download) (as text)
Mon May 16 12:23:08 2011 UTC (13 years ago) by niro
File MIME type: application/x-sh
File size: 2328 byte(s)
-fixed ports
1 niro 1972 # $Id$
2 niro 218 # 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 niro 341 prn_ids=$(mysqldo "select id from cfg_printers where serial='${ALX_SERIAL}'")
10 niro 218
11     # set counter equal to numbers of printers
12     declare -i count=0
13     for i in ${prn_ids}
14     do
15     # now get the other settings und put them in arrays
16 niro 341 ALX_PRINTER_NAME[${count}]=$(mysqldo "select printer_name from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'")
17     ALX_PORT[${count}]=$(mysqldo "select port from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'")
18     ALX_IP[${count}]=$(mysqldo "select ip from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'")
19     ALX_SHARE[${count}]=$(mysqldo "select share from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'")
20 niro 218
21     (( count++ ))
22     done
23    
24     # export all settings
25     export ALX_COUNT=${count}
26     export ALX_PRINTER_NAME
27     export ALX_PORT
28     export ALX_IP
29     export ALX_SHARE
30     }
31    
32 niro 232 config_printing()
33 niro 218 {
34     local port
35 niro 2034 local CONFIG
36 niro 218
37 niro 341 # first of all get the vars
38 niro 218 get_printer_settings
39    
40 niro 1972 # first of all delete all printers, by wiping /etc/printcap and all spooler directories
41 niro 2034 CONFIG=/etc/printcap
42     clearconfig
43    
44 niro 1972 if [[ -d /var/spool/lpd ]]
45     then
46     rm -rf /var/spool/lpd
47     install -d /var/spool/lpd
48     install -d /var/spool/lpd/lp
49     chown lp:lp /var/spool/lpd/lp
50     chmod 0700 /var/spool/lpd/lp
51     fi
52 niro 218
53     for (( i=0; i < ALX_COUNT; i++ ))
54     do
55     # get real port settings
56     case ${ALX_PORT[${i}]} in
57 niro 2126 lpt[0-9]*) port="/dev/lp$(( ${ALX_PORT[${i}]/lpt/}-1 ))" ;;
58     com[0-9]*) port="/dev/ttyS$(( ${ALX_PORT[${i}]/com/}-1 ))" ;;
59     usb[0-9]*) port="/dev/usb/lp$(( ${ALX_PORT[${i}]/usb/}-1 ))" ;;
60 niro 1972 #lpd) port="lpd://${ip}/${share}" ;;
61     #socket) port="socket://${ip}:${share}" ;;
62 niro 218 esac
63    
64 niro 1972 # now add new printers (writing printcap)
65 niro 2034 addconfig "#--- added by alxconfig ---"
66     addconfig "${ALX_PRINTER_NAME[${i}]}|${ALX_PRINTER_NAME[${i}]}"
67     addconfig " :lp=${port}"
68     addconfig " :sd=/var/spool/lpd/${ALX_PRINTER_NAME[${i}]}"
69     addconfig "#-----------------------"
70     addconfig
71 niro 1972
72     # install spooler directories
73     install -o lp -g lp -m0700 -d /var/spool/lpd/${ALX_PRINTER_NAME[${i}]}
74 niro 218 done
75 niro 244
76 niro 1972 # start lprng if ALX_COUNT > 0
77 niro 244 if [[ ${ALX_COUNT} != 0 ]]
78     then
79 niro 1972 rc-config add lprng &> /dev/null
80 niro 244 else
81 niro 1972 rc-config del lprng &> /dev/null
82 niro 244 fi
83 niro 218 }