#!/bin/bash # ---------------------------------------------------------------------------- # /var/install/config.d/cui-lprng.sh - configuration generator script for LPRng # # Copyright (c) 2002-2013 Thomas Bork, tom(at)eisfair(dot)net # # Creation : 2002-10-06 tb # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # ---------------------------------------------------------------------------- #set -x . /var/install/include/eislib . /etc/config.d/base . /etc/config.d/lprng irq='' io='' parport='' lpdir='/var/spool/lpd' parportconf='/etc/parport.conf' generate='/etc/printcap' version=`cat /usr/share/doc/lprng/version` usb_exists='false' parport_any_active=no usb_any_active=no remote_any_active=no lsmodbin='/sbin/lsmod' eisfair_system=`cat /etc/eisfair-system` rm -f ${parportconf} do_check_parport () { idx='1' while [ "${idx}" -le "$LPRNG_LOCAL_PARPORT_PRINTER_N" ] ; do active='' eval active='$LPRNG_LOCAL_PARPORT_PRINTER_'${idx}'_ACTIVE' if [ "$active" = "yes" ] ; then parport_any_active=yes fi idx=`expr ${idx} + 1` done } do_check_usbport () { idx='1' while [ "${idx}" -le "$LPRNG_LOCAL_USBPORT_PRINTER_N" ] ; do active='' eval active='$LPRNG_LOCAL_USBPORT_PRINTER_'${idx}'_ACTIVE' if [ "$active" = "yes" ] ; then usb_any_active=yes fi idx=`expr ${idx} + 1` done if [ -f /etc/config.d/usb ] ; then # eisfair-1 with kernel 2.6 . /etc/config.d/usb if [ "$START_USB" = "yes" ] ; then if [ "$USB_PRINTER" = "yes" ] ; then if [ -n "`${lsmodbin} | grep '^usblp '`" ] ; then usb_exists="true" fi fi fi else # eisfair-2 with kernel 2.6 or 3.x usb_exists='true' fi } do_check_remote () { idx='1' while [ "${idx}" -le "$LPRNG_REMOTE_PRINTER_N" ] ; do active='' eval active='$LPRNG_REMOTE_PRINTER_'${idx}'_ACTIVE' if [ "$active" = "yes" ] ; then remote_any_active=yes fi idx=`expr ${idx} + 1` done } if [ -f "$generate" ] ; then /var/install/bin/backup-file ${generate} sic fi { echo "# ----------------------------------------------------------------------------" echo "# LPRng configuration file generated by /var/install/config.d/lprng.sh" echo "#" echo "# Version of LPRng for eisfair is $version" echo "#" echo "# Do not edit this file, use" echo "#" echo "# 'Edit LPRng Configuration'" echo "#" echo "# in LPRng Services Menu!" echo "#" echo "# Creation date: ${EISDATE} ${EISTIME}" echo "# ----------------------------------------------------------------------------" } > "$generate" if [ "$LPRNG_LOCAL_PARPORT_PRINTER_N" != 0 ] ; then do_check_parport if [ "$parport_any_active" = "yes" ] ; then { echo echo "# ----------------------------------------------------------------------------" echo "# configuration for local parallel printers" echo "# ----------------------------------------------------------------------------" } >> "$generate" idx='1' idy='0' while [ "${idx}" -le "$LPRNG_LOCAL_PARPORT_PRINTER_N" ] ; do active='' port='' interrupt='' eval active='$LPRNG_LOCAL_PARPORT_PRINTER_'${idx}'_ACTIVE' eval port='$LPRNG_LOCAL_PARPORT_PRINTER_'${idx}'_IO' eval interrupt='$LPRNG_LOCAL_PARPORT_PRINTER_'${idx}'_IRQ' eval comment='$LPRNG_LOCAL_PARPORT_PRINTER_'${idx}'_COMMENT' eval notify='$LPRNG_LOCAL_PARPORT_PRINTER_'${idx}'_NOTIFY' port=`echo ${port} | tr [:upper:] [:lower:]` create_printer=true if [ "$active" != "yes" ] ; then mecho --std "LPRNG_LOCAL_PARPORT_PRINTER_"${idx}" is not active -" mecho --std " skipping LPRNG_LOCAL_PARPORT_PRINTER_"${idx}" ..." create_printer=false fi if [ -z "$port" -a "$create_printer" = "true" ] ; then mecho --error "LPRNG_LOCAL_PARPORT_PRINTER_"${idx}"_IO is not defined -" mecho --error " skipping LPRNG_LOCAL_PARPORT_PRINTER_"${idx}" ..." create_printer=false fi if [ "$create_printer" = "true" ] ; then if [ "$interrupt" = "yes" ] ; then interrupt=auto else interrupt=none fi if [ -z "$irq" ] ; then irq=${interrupt} else irq=${irq},${interrupt} fi if [ -z "$parport" ] ; then parport=${idy} else parport=${parport},${idy} fi if [ -z "$io" ] ; then io=${port} else io=${io},${port} fi { echo "pr${idx}:" echo " :done_jobs=0" echo " :mc=0" echo " :rw@" echo " :sh" echo " :lp=/dev/lp${idy}" echo " :sd=$lpdir/pr${idx}" echo " :fx=flp" echo " :filter_options=\$P \$b \$e \$j \$t \$f \$n \$h \$S" echo " :filter=/var/install/bin/lprng-filter" echo " :cm=$comment" echo " :smbinfo=$notify" echo } >> "$generate" idy=`expr ${idy} + 1` fi idx=`expr ${idx} + 1` done if [ -n "$io" ] ; then { echo "io=$io" echo "irq=$irq" echo "parport=$parport" } > ${parportconf} fi else mecho --std "No parport printers active." fi else mecho --std "No parport printers active." fi if [ "$LPRNG_LOCAL_USBPORT_PRINTER_N" != 0 ] ; then do_check_usbport if [ "$usb_any_active" = "yes" ] ; then if [ "$usb_exists" = "true" ] ; then { echo echo "# ----------------------------------------------------------------------------" echo "# configuration for local USB printers" echo "# ----------------------------------------------------------------------------" } >> "$generate" idx='1' idy='0' while [ "${idx}" -le "$LPRNG_LOCAL_USBPORT_PRINTER_N" ] ; do active='' eval active='$LPRNG_LOCAL_USBPORT_PRINTER_'${idx}'_ACTIVE' eval comment='$LPRNG_LOCAL_USBPORT_PRINTER_'${idx}'_COMMENT' eval notify='$LPRNG_LOCAL_USBPORT_PRINTER_'${idx}'_NOTIFY' create_printer=true if [ "$active" != "yes" ] ; then mecho --std "LPRNG_LOCAL_USBPORT_PRINTER_"${idx}" is not active -" mecho --std " skipping LPRNG_LOCAL_USBPORT_PRINTER_"${idx}" ..." create_printer=false fi if [ "$create_printer" = "true" ] ; then { echo "usbpr${idx}:" echo " :done_jobs=0" echo " :mc=0" echo " :rw@" echo " :sh" if [ "$eisfair_system" = "eisfair-1" ] ; then echo " :lp=/dev/usb/lp$idy" else echo " :lp=/dev/usblp$idy" fi echo " :sd=$lpdir/usbpr${idx}" echo " :fx=flp" echo " :filter_options=\$P \$b \$e \$j \$t \$f \$n \$h \$S" echo " :filter=/var/install/bin/lprng-filter" echo " :cm=$comment" echo " :smbinfo=$notify" echo } >> "$generate" fi idx=`expr ${idx} + 1` idy=`expr ${idy} + 1` done else if [ -f /etc/config.d/usb ] ; then mecho --error "If you want to print to USB printers, you have to set" mecho --error "\"START_USB\" and \"USB_PRINTER\" to 'yes' in USB configuration" mecho --error "skipping USB printers ..." else mecho --error "USB modules are not properly loaded," mecho --error "skipping USB printers ..." fi fi else mecho --std "No usbport printers active." fi else mecho --std "No usbport printers active." fi if [ "$LPRNG_REMOTE_PRINTER_N" != 0 ] ; then do_check_remote if [ "$remote_any_active" = "yes" ] ; then { echo echo "# ----------------------------------------------------------------------------" echo "# configuration for remote printers" echo "# ----------------------------------------------------------------------------" } >> "$generate" idx='1' while [ "${idx}" -le "$LPRNG_REMOTE_PRINTER_N" ] ; do eval active='$LPRNG_REMOTE_PRINTER_'${idx}'_ACTIVE' eval remotequeuename='$LPRNG_REMOTE_PRINTER_'${idx}'_QUEUENAME' eval remoteip='$LPRNG_REMOTE_PRINTER_'${idx}'_IP' eval remoteport='$LPRNG_REMOTE_PRINTER_'${idx}'_PORT' eval comment='$LPRNG_REMOTE_PRINTER_'${idx}'_COMMENT' eval notify='$LPRNG_REMOTE_PRINTER_'${idx}'_NOTIFY' create_printer=true if [ "$active" != "yes" ] ; then mecho --std "LPRNG_REMOTE_PRINTER_"${idx}" is not active -" mecho --std " skipping LPRNG_REMOTE_PRINTER_"${idx}" ..." create_printer=false fi if [ -z "$remoteip" -a "$create_printer" = "true" ] ; then mecho --error "LPRNG_REMOTE_PRINTER_"${idx}"_IP is not defined -" mecho --warn " skipping LPRNG_REMOTE_PRINTER_"${idx}" ..." create_printer=false fi if [ "$create_printer" = "true" ] ; then if [ -n "$remotequeuename" ] ; then lpvar="$remotequeuename@" else lpvar='' fi if [ -n "$remoteip" ] ; then lpvar="$lpvar$remoteip" else lpvar="$lpvar" fi if [ -n "$remoteport" ] ; then lpvar="$lpvar%$remoteport" else lpvar="$lpvar" fi { echo "repr${idx}:" echo " :done_jobs=0" echo " :mc=0" echo " :connect_grace=1" echo " :connect_retry=100" echo " :connect_interval=100" echo " :max_connect_interval=200" echo " :send_try=0" echo " :send_failure_action=retry" echo " :rw@" echo " :sh" echo " :lp=$lpvar" echo " :sd=$lpdir/repr${idx}" echo " :fx=flp" echo " :filter_options=\$P \$b \$e \$j \$t \$f \$n \$h \$S" echo " :filter=/var/install/bin/lprng-filter" echo " :cm=$comment" echo " :smbinfo=$notify" echo } >> "$generate" fi idx=`expr ${idx} + 1` done else mecho --std "No remote printers active." fi else mecho --std "No remote printers active." fi mkdir -p /var/spool/lprng chmod 0777 /var/spool/lprng if [ ! -f /var/spool/lprng/log.lprng ] ; then touch /var/spool/lprng/log.lprng chown lp:lp /var/spool/lprng/log.lprng fi chmod 0644 "$generate" chown root:root "$generate"