# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_printers.sh,v 1.4 2005-03-09 00:28:29 niro Exp $ # configures printing on the host via mysql db settings 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 } 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 # 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 (writing printers.conf) #/usr/sbin/lpadmin -p ${ALX_PRINTER_NAME[${i}]} -E -v ${port} echo "" >> /etc/cups/printers.conf echo "Info ${ALX_PRINTER_NAME[${i}]}" >> /etc/cups/printers.conf echo "DeviceURI ${port}" >> /etc/cups/printers.conf echo "State Idle" >> /etc/cups/printers.conf echo "Accepting Yes" >> /etc/cups/printers.conf 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 "" >> /etc/cups/printers.conf done }