:
#	@(#) idtune 25.1 92/06/19 
#
#	Copyright (C) 1988-1992 The Santa Cruz Operation, Inc.
#		All Rights Reserved.
#	The information in this file is provided for the exclusive use of
#	the licensees of The Santa Cruz Operation, Inc.  Such users have the
#	right to use, modify, and incorporate this code into other products
#	for purposes authorized by the license agreement provided they include
#	this notice and the associated copyright notice with any such product.
#	The information in this file is provided "AS IS" without warranty.
#
#	      UNIX is a registered trademark of AT&T
#		Portions Copyright 1976-1989 AT&T
#		      All Rights Reserved
#
#ident	"@)#(idcmd:idtune	1.3"
#
#	idtune  [ -f | -m ]  name  value
#	Attempt to set the value of tuneable parameter 'name' to 'value'
#	If a value is already given to this parameter (via stune), the user
#	will be asked to confirm the change unless the -f option is used.
#	If the -m option is used, we silently accept existing values greater
#	than the new value.
#

STUNE=../cf.d/stune
MTUNE=../cf.d/mtune
[ "$ROOT" ] && cd $ROOT/etc/conf/cf.d || {
	cd `dirname $0`
	[ -f $STUNE ] || cd /etc/conf/cf.d
}

force=
min=

while case "$1" in
	-f)	force=y;; 
	-m)	min=y;;
	 *) break;;
	esac
do
	shift
done

if [ $# != 2 ]
then
	echo >&2 "Usage: idtune [ -f | -m ] parameter value"
	exit 99
fi

name=$1
new_value=$2

if line=`grep "^$name[ 	]" $STUNE 2>/dev/null`
then
	set - $line
	old_value=$2
	if [ "$old_value" = "$new_value" ]
	then
		exit 0
	fi
	if [ "$min" ]
	then
		if expr "$old_value" \> "$new_value"  >/dev/null
		then
			exit 0
		fi
	fi
	if [ ! "$force" ]
	then
		echo "\nTuneable Parameter \"$name\" is currently set to ${old_value}."
		echo "Is it OK to change it to $new_value? (y/n) \c"
		read ans
		case $ans in
			y*|Y*)	;;
			*)	echo "\n\"$name\" left at ${old_value}.\n"
				exit 0;;
		esac
		echo
	fi
	ed - $STUNE >/dev/null 2>&1 <<-!
		/^$name[ 	]/c
		$name	$new_value
		.
		w
	!
	exit $?
else
	if [ "$min" ]
	then
		if line=`grep "^$name[ 	]" $MTUNE 2>/dev/null`
		then
			set - $line
			old_value=$2
			if expr "$old_value" \>= "$new_value"  >/dev/null
			then
				exit 0
			fi
		fi
	fi
	echo "$name\t$new_value" >>$STUNE
	exit $?
fi
