#!/bin/ksh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# ident	"%Z%%M%	%I%	%E% SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

	[ -f /usr/lib/lp/local/lpsched ] || exit 1

# Get command line options and set them in print service
# -f num_filters
# -n num_notifiers
# -p fd_limit
# -r reserved_fds

# Check to see if lpsched is already running

state=`svcprop -p restarter/state svc:/application/print/server:default`
if [ "$state" = "online" ] ; then
	/bin/gettext "Print services already active.\n"
	exit 1
fi

OPTS=$*

# no options set

if [ "$OPTS" = "" ]  ; then
	/usr/sbin/svcadm enable -t svc:/application/print/server:default
	if [ $? = 0 ] ; then
		/bin/gettext "Print services started.\n"
		exit 0
	else
		exit 1
	fi

else

# Get and set the options

	/usr/sbin/svccfg <<-EOF 2>/dev/null
		select svc:/application/print/server:default
		addpg cmd_opts count P

	EOF

num_filters=0
num_notifiers=0
fd_limit=0
reserved_fds=0

while getopts :f:n:p:r: arg; do
	case $arg in
	f) 
		num_filters=$OPTARG 

		/usr/sbin/svccfg <<-EOF 2>/dev/null
		select svc:/application/print/server:default
		setprop cmd_opts/num_filters = count: ${num_filters}

		EOF
	
		;;

	n) 
		num_notifiers=$OPTARG 

		/usr/sbin/svccfg <<-EOF 2>/dev/null
		select svc:/application/print/server:default
		setprop cmd_opts/num_notifiers = count:  ${num_notifiers}

		EOF
	
		;;

	p)
		fd_limit=$OPTARG 

		/usr/sbin/svccfg <<-EOF 2>/dev/null
		select svc:/application/print/server:default
		setprop cmd_opts/fd_limit = count:  ${fd_limit}

		EOF
	
		;;

	r)
		reserved_fds=$OPTARG 

		/usr/sbin/svccfg <<-EOF 2>/dev/null
		select svc:/application/print/server:default
		setprop cmd_opts/reserved_fds = count:  ${reserved_fds}

		EOF
	
		;;

	*)	echo "Invalid flag -$OPTARG. Exiting"
			exit 1
	esac
done

	/usr/sbin/svcadm enable -t svc:/application/print/server:default
	if [ $? = 0 ] ; then
		/bin/gettext "Print services started.\n"
		exit 0
	else
		exit 1
	fi
	
fi
		
