#!/bin/sh
#
# lenbwrm
#	remove an lenbw printer description
#
#	Usage: lenbwrm <queue name>
#
# 
# All rights reserved.
#
# Version 1.12		2012/03/01
#

if [ $# -ne 1 ]
then
	echo "Usage: $0 <queue name>"
	exit 1
fi

osType=`uname -s`

if [ $osType = "AIX" ]
then
	echo "Doing LENBW removal for $1 on AIX"

	printer="$1"
	device="dev_"$1

	rm /opt/lenovo/tap/filter/$printer
	rm /opt/lenovo/tap/filter/$printer.conf
	rmquedev -q$printer -d$device
	rmque -q$printer
elif [ $osType = "SCO_SV" ]
then
	echo "Doing LENBW removal for $1 on SCO_SV"

	/usr/lib/lpadmin -x $1

	printer_conf=/usr/spool/lp/admins/lp/interfaces/$1.conf

	if [ -f "${printer_conf}" ]
	then
		rm ${printer_conf}
	fi

elif [ $osType = "SunOS" ]
then
	echo "Doing LENBW removal for $1 on SunOS"

	lpadmin -x $1

	printer_conf=/etc/lp/interfaces/$1.conf

	if [ -f "${printer_conf}" ]
	then
		rm ${printer_conf}
	fi
elif [ $osType = "HP-UX" ]
then
	echo "Doing LENBW removal for $1 on HP-UX"

	#
	# check if the schedule is running and if it
	# is we have to stop it and then restart it.
	#
	ps -ef | grep lpsched | grep -iv grep > /dev/null 2>&1
	nosched=$?

	if [ $nosched = 0 ]
	then
		/usr/sbin/lpshut > /dev/null 2>&1
	fi

	/usr/sbin/lpadmin -x$1		# delete the printer

	printer_conf=/etc/lp/interface/$1.conf

	if [ -f "${printer_conf}" ]
	then
		rm ${printer_conf}
	fi

	#
	# If it was running then start it again
	#
	if [ $nosched = 0 ]
	then
		/usr/sbin/lpsched > /dev/null 2>&1
	fi
elif [ $osType = "Linux" ]
then
	echo "Doing LENBW removal for $1 on Linux"

	printer="$1"

#
#	Remove the filter and config file then remove the
#	entry from the printcap file
#
	rm /opt/lenovo/tap/interface/$printer
	rm /opt/lenovo/tap/interface/$printer.conf
	/opt/lenovo/tap/bin/modPrintcap -d $printer
	if [ -f /opt/lenovo/tap/bin/flag_$printer ]
	then
		/opt/lenovo/tap/bin/printconf_import -d $printer
		rm /opt/lenovo/tap/bin/flag_$printer
	fi
	echo "Please restart lpd !"
else        #Default Caldera OpenUNIX ?
	echo "Doing LENBW removal for $1 on Caldera OpenUNIX ?"

	lpadmin -x $1

	printer_conf=/etc/lp/interfaces/$1.conf

	if [ -f "${printer_conf}" ]
	then
		rm ${printer_conf}
	fi
fi


