Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1972 by niro, Sat May 7 11:02:15 2011 UTC revision 2718 by niro, Mon Aug 8 08:43:51 2011 UTC
# Line 1  Line 1 
1  # $Id$  # $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=$(mysqldo "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}]=$(mysqldo "select printer_name from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'")  
  ALX_PORT[${count}]=$(mysqldo "select port from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'")  
  ALX_IP[${count}]=$(mysqldo "select ip from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'")  
  ALX_SHARE[${count}]=$(mysqldo "select share from cfg_printers where serial='${ALX_SERIAL}' and id='${i}'")  
   
  (( count++ ))  
  done  
   
  # export all settings  
  export ALX_COUNT=${count}  
  export ALX_PRINTER_NAME  
  export ALX_PORT  
  export ALX_IP  
  export ALX_SHARE  
 }  
   
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/printcap and all spooler directories   # first of all delete all printers, by wiping /etc/printcap and all spooler directories
14   :> /etc/printcap   CONFIG="/etc/printcap"
15   if [[ -d /var/spool/lpd ]]   clearconfig
  then  
  rm -rf /var/spool/lpd  
  install -d /var/spool/lpd  
  install -d /var/spool/lpd/lp  
  chown lp:lp /var/spool/lpd/lp  
  chmod 0700 /var/spool/lpd/lp  
  fi  
16    
17   for (( i=0; i < ALX_COUNT; i++ ))   # cleanup spooler directories
18     [[ -d /var/spool/lpd ]] && rm -r /var/spool/lpd
19     install -d /var/spool/lpd
20     install -d /var/spool/lpd/lp
21     chown lp:lp /var/spool/lpd/lp
22     chmod 0700 /var/spool/lpd/lp
23    
24     # cleanup log directories
25     [[ -d /var/log/lprng ]] && rm -r /var/log/lprng
26     install -d /var/log/lprng
27    
28     for i in ${prn_ids}
29   do   do
30     evaluate_table cfg_printers "where serial='${ALX_SERIAL}' and id='${i}'"
31    
32     # do not add any printers if the name is empty - warn the user
33     if [[ -z ${cfg_printers_printer_name} ]]
34     then
35     echo -e "${COLRED}No printer_name given in config of printer '${i}' with port '${cfg_printers_port}'. Not added!${COLDEFAULT}"
36     continue
37     fi
38    
39   # get real port settings   # get real port settings
40   case ${ALX_PORT[${i}]} in   case ${cfg_printers_port} in
41   lpt[0-9]*) port="/dev/lp$(( ${port/lpt/}-1 ))" ;;   lpt[0-9]*) port="/dev/lp$(( ${cfg_printers_port/lpt/}-1 ))" ;;
42   com[0-9]*) port="/dev/ttyS$(( ${port/com/}-1 ))" ;;   com[0-9]*) port="/dev/ttyS$(( ${cfg_printers_port/com/}-1 ))" ;;
43   usb[0-9]*) port="/dev/usb/lp$(( ${port/usb/}-1 ))" ;;   usb[0-9]*) port="/dev/usb/lp$(( ${cfg_printers_port/usb/}-1 ))" ;;
44   #lpd) port="lpd://${ip}/${share}" ;;   #lpd) port="lpd://${ip}/${share}" ;;
45   #socket) port="socket://${ip}:${share}" ;;   #socket) port="socket://${ip}:${share}" ;;
46   esac   esac
47    
48   # now add new printers (writing printcap)   # now add new printers (writing printcap)
49   echo "#--- added by alxconfig ---" >> /etc/printcap   addconfig "#--- added by alxconfig ---"
50   echo "${ALX_PRINTER_NAME[${i}]}|${ALX_PRINTER_NAME[${i}]}" >> /etc/printcap   addconfig "${cfg_printers_printer_name}|${cfg_printers_printer_name}"
51   echo " :lp=${port}" >> /etc/printcap   addconfig " :lp=${port}"
52   echo " :sd=/var/spool/lpd/${ALX_PRINTER_NAME[${i}]}" >> /etc/printcap   addconfig " :sd=/var/spool/lpd/${cfg_printers_printer_name}"
53   echo "#-----------------------"   addconfig " :lf=/var/log/lprng/${cfg_printers_printer_name}"
54   echo >> /etc/printcap   addconfig "#-----------------------"
55     addconfig
56    
57   # install spooler directories   # install spooler directories
58   install -o lp -g lp -m0700 -d /var/spool/lpd/${ALX_PRINTER_NAME[${i}]}   install -o lp -g lp -m0700 -d /var/spool/lpd/${cfg_printers_printer_name}
59   done   done
60    
61   # start lprng if ALX_COUNT > 0   # start lprng
62   if [[ ${ALX_COUNT} != 0 ]]   if [[ -n ${prn_ids} ]]
63   then   then
64   rc-config add lprng &> /dev/null   rc-config add lprng &> /dev/null
65   else   else

Legend:
Removed from v.1972  
changed lines
  Added in v.2718