#! /bin/bash
#
# Johannes Meixner <jsmeix@suse.de>, 2004, 2005, 2006

#set -x

export PATH="/sbin:/usr/sbin:/usr/bin:/bin"
export LC_ALL="POSIX"
export LANG="POSIX"
umask 022

# The hplip service and the ptal service exclude each other.
# Disable the ptal service if it exists:
if [ -x /etc/init.d/ptal ]
then /etc/init.d/ptal stop
     insserv -r ptal
fi

# Setup the hplip services:
# HPLIP version 0.x and 1.x require the hplip services (hpiod and hpssd) to be up and running.
# For HPLIP version 2.x there is no longer a hpiod and hpssd is only optional.
# Therefore it is only for version 0.x and 1.x an error if /etc/init.d/hplip cannot be executed.
# Some functionality (e.g. faxing from applications requires a running hpssd).
# Therefore it might be better when hpssd is started in any case during boot
# so that we may have a /etc/init.d/hplip in version 2.x to start hpssd during boot.
if [ -x /etc/init.d/hplip ] 
then insserv hplip || { echo "failed: insserv hplip" 1>&2 ; exit 2 ; }
     /etc/init.d/hplip restart || { echo "failed: /etc/init.d/hplip restart" 1>&2 ; exit 3 ; }
else echo "cannot execute /etc/init.d/hplip" 1>&2
     rpm -q hplip | egrep -q '^hplip-0\.|^hplip-1\.' && exit 1
fi

exit 0

