Magellan Linux

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

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

alx-src/trunk/alxconfig-ng/functions/config_printers.sh revision 270 by niro, Wed Apr 20 11:46:41 2005 UTC alx-src/branches/alxconf-060/functions/config_printers.sh revision 2610 by niro, Wed Jul 6 21:33:33 2011 UTC
# Line 1  Line 1 
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 $  # $Id$
2  # configures printing on the host via mysql db settings  # configures printing on the host via mysql db settings
3    
4  get_printer_settings()  config_printing()
 {  
  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()  
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}'")
   
  # 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  
12    
13   # now start cups   # first of all delete all printers, by wiping /etc/printcap and all spooler directories
14   /etc/init.d/cups start &> /dev/null   CONFIG="/etc/printcap"
15     clearconfig
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   # get real port settings   evaluate_table cfg_printers "where serial='${ALX_SERIAL}' and id='${i}'"
  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  
 }  
   
 config_printing()  
 {  
  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  
29    
30   # debug   # do not add any printers if the name is empty - warn the user
31  # echo "ALX_COUNT: ${ALX_COUNT}"   if [[ -z ${cfg_printers_printer_name} ]]
32     then
33     echo -e "${COLRED}No printer_name given in config of printer '${i}' with port '${cfg_printers_port}'. Not added!${COLDEFAULT}"
34     continue
35     fi
36    
  for (( i=0; i < ALX_COUNT; i++ ))  
  do  
37   # get real port settings   # get real port settings
38   case ${ALX_PORT[${i}]} in   case ${cfg_printers_port} in
39   lpt1)   lpt[0-9]*) port="/dev/lp$(( ${cfg_printers_port/lpt/}-1 ))" ;;
40   port="parallel:/dev/lp0"   com[0-9]*) port="/dev/ttyS$(( ${cfg_printers_port/com/}-1 ))" ;;
41   ;;   usb[0-9]*) port="/dev/usb/lp$(( ${cfg_printers_port/usb/}-1 ))" ;;
42   com1)   #lpd) port="lpd://${ip}/${share}" ;;
43   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}]}"  
  ;;  
44   esac   esac
45    
46   # now add new printers (writing printers.conf)   # now add new printers (writing printcap)
47   #/usr/sbin/lpadmin -p ${ALX_PRINTER_NAME[${i}]} -E -v ${port}   addconfig "#--- added by alxconfig ---"
48   echo "<Printer ${ALX_PRINTER_NAME[${i}]}>" >> /etc/cups/printers.conf   addconfig "${cfg_printers_printer_name}|${cfg_printers_printer_name}"
49   echo "Info ${ALX_PRINTER_NAME[${i}]}" >> /etc/cups/printers.conf   addconfig " :lp=${port}"
50   echo "DeviceURI ${port}" >> /etc/cups/printers.conf   addconfig " :sd=/var/spool/lpd/${cfg_printers_printer_name}"
51   echo "State Idle" >> /etc/cups/printers.conf   addconfig "#-----------------------"
52   echo "Accepting Yes" >> /etc/cups/printers.conf   addconfig
  echo "JobSheets none none" >> /etc/cups/printers.conf  
  echo "QuotaPeriod 0" >> /etc/cups/printers.conf  
  echo "PageLimit 0" >> /etc/cups/printers.conf  
  echo "KLimit 0" >> /etc/cups/printers.conf  
  echo "</Printer>" >> /etc/cups/printers.conf  
  done  
53    
54   # setup lpd print-services   # install spooler directories
55   echo "printer stream tcp nowait lp /usr/lib/cups/daemon/cups-lpd cups-lpd" > /etc/inetd.conf   install -o lp -g lp -m0700 -d /var/spool/lpd/${cfg_printers_printer_name}
56     done
57    
58   # start samba and cups if ALX_COUNT > 0   # start lprng
59   if [[ ${ALX_COUNT} != 0 ]]   if [[ -n ${prn_ids} ]]
60   then   then
61  # echo "DEBUG: adding samba+cups+inetd"   rc-config add lprng &> /dev/null
  rc-config add inetd &> /dev/null  
  rc-config add cups &> /dev/null  
  rc-config add samba &> /dev/null  
62   else   else
63  # echo "DEBUG: deleting samba+cups+inetd"   rc-config del lprng &> /dev/null
  rc-config del inetd &> /dev/null  
  rc-config del cups &> /dev/null  
  rc-config del samba &> /dev/null  
64   fi   fi
65  }  }

Legend:
Removed from v.270  
changed lines
  Added in v.2610