#! /bin/sh #---------------------------------------------------------------------------- # /etc/init.d/lprng - init lprng # # usage: /etc/init.d/lprng {start|forcestart|status|stop|restart|reload} # # Creation : 2002-10-06 tb # Last Update: $Id$ # # Copyright (c) 2002-2020 Thomas Bork, tom(at)eisfair(dot)net # Copyright (c) 2020-@@YEAR@@ the eisfair team, team(at)eisfair(dot)org # # 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. #---------------------------------------------------------------------------- ### BEGIN INIT INFO # Provides: lprng # Required-Start: $network $remote_fs $syslog # Required-Stop: $network $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: lpd Daemon to allow printing # Description: lpd is the print daemon required for lpr to work properly. # It is basically a server that arbitrates print jobs to printer(s). ### END INIT INFO # set -x . /etc/config.d/lprng . /etc/init.d/functions lpdbin='/usr/sbin/lpd' parportconf_exists='false' usb_exists='false' lprngpidfile=/run/lpd.515 modprobebin='/sbin/modprobe' rmmodbin='/sbin/rmmod' lsmodbin='/sbin/lsmod' if [ -f /etc/parport.conf ] then . /etc/parport.conf parportconf_exists='true' fi do_create_devices() { if ! grep -q 'devtmpfs /dev devtmpfs' /proc/mounts then # adding usblp$idx devices mkdir -p /dev/usb chown root:root /dev/usb chmod 0755 /dev/usb idx=0 while [ ${idx} -le 15 ] do if [ ! -c "/dev/usb/lp$idx" ] then mknod /dev/usb/lp$idx c 180 $idx fi chown lp:lp /dev/usb/lp$idx chmod 0660 /dev/usb/lp$idx idx=$((${idx} + 1)) done # adding parport$idx devices idx=0 while [ ${idx} -le 3 ] do if [ ! -c "/dev/parport$idx" ] then mknod /dev/parport$idx c 99 $idx fi chown root:root /dev/parport$idx chmod 0660 /dev/parport$idx idx=$((${idx} + 1)) done # adding lp$idx devices idx=0 while [ ${idx} -le 2 ] do if [ ! -c "/dev/lp$idx" ] then mknod /dev/lp$idx c 6 $idx fi chown lp:lp /dev/lp$idx chmod 0640 /dev/lp$idx idx=$((${idx} + 1)) done fi } do_check_par() { # muss wieder weg # rm /etc/parport_found if [ -f /etc/parport_found ] then all_parports_configured='true' for port in `cat /etc/parport_found` do if ! `echo $io | grep -q "$port"` then all_parports_configured='false' boot_mesg " Cannot find existing parport $port in LPRng configuration." echo_failure fi done if [ "$all_parports_configured" = "false" ] then boot_mesg " Please configure _all_ existing parports in LPRng configuration." echo_failure fi correct_parports_configured='true' for port in `IFS=','; echo $io` do if ! `grep -q "$port" /etc/parport_found` then correct_parports_configured='false' boot_mesg " Cannot find configured parport $port in existing parports." echo_failure fi done if [ "$correct_parports_configured" = "false" ] then boot_mesg " Please configure only _existing_ parports." echo_failure fi else boot_mesg " No parallel port(s) found." echo_failure fi } do_check_usb() { idx=1 usb_any_active='no' while [ ${idx} -le ${LPRNG_LOCAL_USBPORT_PRINTER_N:-0} ] do eval active='$LPRNG_LOCAL_USBPORT_PRINTER_'$idx'_ACTIVE' if [ "$active" = "yes" ] then usb_any_active='yes' fi idx=$((${idx} + 1)) done if [ "$usb_any_active" = "yes" ] then if grep -q 'devtmpfs /dev devtmpfs' /proc/mounts then # eudev is handling usblp if [ -n "`$lsmodbin | grep '^usblp '`" ] then usb_exists='true' fi else # USB configuration is handling usblp . /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 fi fi } do_parport() { for modul in parport ppdev do if [ -z "`$lsmodbin | grep "^$modul "`" ] then $modprobebin $modul >/dev/null 2>&1 if [ $? -ne 0 ] then boot_mesg " Cannot load $modul." echo_failure fi fi done } do_parport_pc() { $modprobebin parport_pc >/dev/null 2>&1 if [ $? -ne 0 ] then boot_mesg " Cannot load parport_pc without options." echo_failure fi } do_lp() { if [ -z "`$lsmodbin | grep '^lp '`" ] then $modprobebin lp parport=$parport >/dev/null 2>&1 if [ $? -ne 0 ] then boot_mesg " Cannot load lp on parport $parport." echo_failure fi fi } do_modules_load() { for modul in parport parport_pc lp do if [ -z "`$lsmodbin | grep "^$modul "`" ] then $modprobebin $modul >/dev/null 2>&1 if [ $? -ne 0 ] then boot_mesg " Cannot preload $modul." echo_failure else if [ "$modul" = "parport_pc" ] then rm -f /etc/parport_found if [ -d /proc/sys/dev/parport ] then for i in $(ls -1 /proc/sys/dev/parport | grep -v default) do base=$(cat /proc/sys/dev/parport/$i/base-addr | cut -f1) base=`echo "obase=16; $base" | bc` done if [ -n "$base" ] then for i in $(ls -1 /proc/sys/dev/parport | grep -v default) do base=$(cat /proc/sys/dev/parport/$i/base-addr | cut -f1) base=`echo "obase=16; $base" | bc` echo "0x$base" >>/etc/parport_found done fi fi fi fi fi done } do_modules_del() { for modul in lp ppdev parport_pc parport do if [ -n "`$lsmodbin | grep "^$modul "`" ] then $rmmodbin $modul >/dev/null 2>&1 if [ $? -ne 0 ] then boot_mesg " Cannot preunload $modul." echo_failure fi fi done } do_lprngstatus() { lprngpid=`cat $lprngpidfile 2>/dev/null` lprngstatus=dead if [ -n "$lprngpid" ] then /bin/kill -0 $lprngpid if [ $? -eq 0 ] then lprngstatus=alive else rm -f $lprngpidfile fi fi } do_startlprng() { boot_mesg " * Starting LPRng ..." do_lprngstatus if [ "$lprngstatus" = "alive" ] then boot_mesg " Warning: LPRng is already running." echo_warning else do_create_devices if [ "$parportconf_exists" = "true" ] then do_modules_del do_modules_load do_modules_del do_parport do_parport_pc do_lp do_check_par fi do_check_usb if [ "$usb_any_active" = "yes" -a "$usb_exists" = "false" ] then boot_mesg " USB printer support is not properly installed." echo_failure fi /usr/sbin/checkpc -af boot_mesg " - Starting lpd ..." $lpdbin evaluate_retval fi } case "$1" in 'start') if [ "$START_LPRNG" = "yes" ] then do_startlprng fi ;; 'forcestart') do_startlprng ;; 'status') /usr/local/bin/colecho "Checking status of LPRng ..." gn do_lprngstatus if [ "$lprngstatus" = "alive" ] then echo "LPRng is running." else echo "LPRng is not running." fi if [ "$parportconf_exists" = "true" ] then for modul in parport ppdev parport_pc lp do if [ -n "`$lsmodbin | grep "^$modul "`" ] then echo "$modul is loaded." else echo "$modul is not loaded." fi done do_check_par fi do_check_usb if [ "$usb_any_active" = "yes" -a "$usb_exists" = "false" ] then /usr/local/bin/colecho "USB printer support is not properly installed." rd w brinv fi if [ "$usb_any_active" = "yes" ] then usb_modules='usb_common usbcore ehci_hcd ehci_pci uhci_hcd ohci_hcd ohci_pci xhci xhci_hcd xhci_pci usblp' for modul in $usb_modules do if [ -n "`$lsmodbin | grep "^$modul "`" ] then echo "$modul is loaded." fi done fi ;; 'stop') boot_mesg " * Stopping LPRng ..." do_lprngstatus if [ "$lprngstatus" = "alive" ] then for signal in "TERM" "INT" "HUP" "KILL" do /usr/bin/killall -$signal lpd if [ $? -eq 0 ] then echo_ok break fi boot_mesg " Warning: killall -$signal lpd failed." echo_warning sleep 1 done rm -f $lprngpidfile else boot_mesg " Warning: LPRng is not running." echo_warning fi for modul in lp ppdev parport_pc parport do if [ -n "`$lsmodbin | grep "^$modul "`" ] then $rmmodbin $modul >/dev/null 2>&1 if [ $? -ne 0 ] then boot_mesg " Cannot unload $modul." echo_failure fi fi done do_check_usb ;; 'restart') $0 stop && $0 forcestart ;; 'reload') boot_mesg " * Reloading LPRng ..." do_lprngstatus if [ $lprngstatus = "alive" ] then for pid in `ps ax | grep 'lpd ' | grep -v grep | cut -c1-6` do boot_mesg " - Reloading lpd with pid $pid ..." /bin/kill -SIGHUP $pid evaluate_retval done else echo " LPRng is not running, performing restart ..." $0 restart fi ;; *) echo "usage: /usr/sbin/service {start|forcestart|status|stop|restart|reload} $(basename $0)" >&2 exit 1 ;; esac set +x