#!/bin/bash # Init file for the CUPS server daemon # # chkconfig: 2345 60 60 # description: The Common UNIX Printing System (CUPS), an \ # advanced printer spooling system which \ # allows setting of printer options and \ # automatic availability of a printer \ # configured on one server in the whole \ # network. Default printing system of Linux \ # Mandrake. # # processname: cupsd # config: /etc/cups/cupsd.conf # config: /etc/cups/client.conf # config: /etc/cups/classes.conf # config: /etc/cups/printers.conf # config: /etc/cups/mime.types # config: /etc/cups/mime.convs # config: /etc/cups/ppds.dat # source function library . /etc/rc.d/init.d/functions RETVAL=0 case "$1" in start) # Do some checks, I hope they make CUPS really idiot-proof now ... # CUPS needs the loopback device to run correctly, make sure that # it is running and abort the CUPS startup when the loopback device # cannot be started if !(export LC_ALL=C; /sbin/ifconfig | /bin/egrep "^lo +[^ ]+.*Loopback" > /dev/null 2>&1); then gprintf "Loopback device ('lo', 127.0.0.1) needed by CUPS, starting it ...\n" /sbin/ifconfig lo 127.0.0.1 > /dev/null 2>&1 RETVAL=$? if [ $RETVAL -ne 0 ]; then echo gprintf "Cannot start loopback device, start of CUPS aborted" fi fi if [ $RETVAL -eq 0 ]; then # Add the "route" entry for the loopback device if it is missing if !(export LC_ALL=C; /sbin/route -n | /bin/egrep "^127\.0\.0\.0 +.* +lo$" > /dev/null 2>&1); then gprintf "Adding loopback device to routing table ...\n"; /sbin/route add -net 127.0.0.0 netmask 255.0.0.0 dev lo if [ $? -ne 0 ]; then echo gprintf "WARNING: Could not add loopback device to routing table,\n" gprintf " CUPS may not work properly.\n" echo fi fi # Check, if we have a real network, if not, let the hostname be # "localhost" #if !(export LC_ALL=C; /sbin/ifconfig | /bin/egrep -v "^lo +[^ ]+.*Loopback" | /bin/egrep "^[a-zA-Z0-9]" > /dev/null 2>&1); then #/bin/hostname localhost #fi # Check whether the loopback device entry (127.0.0.1) in the # /etc/hosts file is correct # Is there an /etc/hosts file? #if (! [ -f /etc/hosts ]); then # gprintf "Creating /etc/hosts ...\n"; # touch /etc/hosts #fi # Is there a correct "localhost" line? #if !(/bin/egrep "^127\.0\.0\.1[[:space:]]+localhost\.localdomain[[:space:]]+localhost" /etc/hosts > /dev/null 2>&1); then # gprintf "Correcting 'localhost' line in /etc/hosts ...\n"; # # Correct "localhost" line with wrong IP # perl -p -i -e "s/^\s*[\d\.]+\s+.*localhost.*$/127.0.0.1\t\tlocalhost.localdomain\tlocalhost/" /etc/hosts # # Correct line with address "127.0.0.1" but wrong name # perl -p -i -e "s/^\s*127.0.0.1\s+.*$/127.0.0.1\t\tlocalhost.localdomain\tlocalhost/" /etc/hosts # # Add "localhost" line if missing # if !(/bin/egrep "^127\.0\.0\.1" /etc/hosts > /dev/null 2>&1); then # echo -en "127.0.0.1\t\tlocalhost.localdomain\tlocalhost\n" >> /etc/hosts # fi #fi # Turn off the CUPS-LPD mini-daemon when LPD is running if [ -x /etc/rc.d/init.d/lpd ]; then if (export LC_ALL=C; /sbin/service lpd status | /bin/egrep "running" > /dev/null 2>&1); then if (export LC_ALL=C; /sbin/chkconfig --list cups-lpd | /bin/egrep "on$" > /dev/null 2>&1); then gprintf "Turning off CUPS-LPD mini daemon ...\n" /sbin/chkconfig --del cups-lpd if [ -x /usr/sbin/xinetd ]; then /sbin/service xinetd condrestart fi fi fi fi # Check whether a parallel printer is configured and if so, but # if the parallel printer kernel module not being loaded, load the # module. if (/bin/egrep "^[^#]*/dev/lp" /etc/cups/printers.conf > /dev/null 2>&1); then if (!(export LC_ALL=C; /sbin/lsmod | /bin/egrep "^lp +" > /dev/null 2>&1) || \ !(export LC_ALL=C; /sbin/lsmod | /bin/egrep "^parport_pc +" > /dev/null 2>&1)); then gprintf "Loading parallel port printer kernel modules ...\n" modprobe parport_pc > /dev/null 2>&1; RET=$? if [ $RET -eq 0 ]; then modprobe lp > /dev/null 2>&1; RET=$? fi if [ $RET -ne 0 ]; then echo gprintf "WARNING: Parallel printer kernel modules could not be loaded, your parallel\n" gprintf " printer may not work.\n" echo fi fi fi # Check whether a USB printer is configured and if so, but if the # USB printer kernel module not being loaded, load the module. if (/bin/egrep "^[^#]*/dev/usb" /etc/cups/printers.conf > /dev/null 2>&1); then if !(export LC_ALL=C; /sbin/lsmod | /bin/egrep "^printer +" > /dev/null 2>&1); then gprintf "Loading USB printer kernel module ...\n" modprobe printer > /dev/null 2>&1; if [ $? -ne 0 ]; then echo gprintf "WARNING: USB printer kernel module could not be loaded, your USB printer may\n" gprintf " not work.\n" echo fi fi fi # Check whether an HP multifunction device is configured with HPOJ # and if so, but if the HPOJ daemons not being running, start the # daemons. if (/bin/egrep "^[^#]*/dev/ptal-" /etc/cups/printers.conf > /dev/null 2>&1 || /bin/egrep "^[^#]*ptal:/" /etc/cups/printers.conf > /dev/null 2>&1); then if !(/bin/ps auxwww | /bin/grep -v "grep" | /bin/grep "ptal-" > /dev/null 2>&1); then gprintf "Starting HPOJ daemons ...\n" chkconfig --add hpoj /sbin/service hpoj start fi fi # Check whether an OKI winprinter is configured with and if so, # but if the oki4daemon not being running, start the oki4daemon. if (/bin/egrep "^[^#]*/dev/oki4drv" /etc/cups/printers.conf > /dev/null 2>&1); then if !(/bin/ps auxwww | /bin/grep -v "grep" | /bin/grep "oki4daemon" > /dev/null 2>&1); then gprintf "Starting oki4daemon ...\n" chkconfig --add oki4daemon /sbin/service oki4daemon start fi fi # Do automatic correction of CUPS configuration to avoid # /etc/printcap from LPD/LPRng being overwritten and also # to avoid printer info with hostname "localhost" being # broadcasted. Can be turned off in printerdrake if [ -x /usr/sbin/correctcupsconfig ]; then /usr/sbin/correctcupsconfig fi gprintf "Starting CUPS printing system: " daemon cupsd RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/cups else echo_failure echo fi ;; stop) gprintf "Stopping CUPS printing system: " killproc cupsd RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/cups ;; restart) $0 stop $0 start RETVAL=$? ;; status) status cupsd RETVAL=$? ;; condrestart) if [ -f /var/lock/subsys/cups ]; then $0 stop $0 start RETVAL=$? fi ;; reload) gprintf "Reinitializing CUPS printing system: " killproc cupsd -HUP RETVAL=$? echo ;; *) gprintf "Usage: cups {start|stop|restart|reload|status|condrestart}\n" exit 1 esac exit $RETVAL