:
#ident	"@(#)idtune	1.6	91/03/25"
#ident "@(#)idtune	1.2 89/09/29"
#	@(#) idtune 21.1 89/10/10 
#
#
#	      UNIX is a registered trademark of AT&T
#		Portions Copyright 1976-1989 AT&T
#	Portions Copyright 1980-1989 Microsoft Corporation
#    Portions Copyright 1983-1989 The Santa Cruz Operation, Inc
#		      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=$ROOT/etc/conf/cf.d/stune

force=
min=

case "$1" in
	-f)	force=y;  shift;;
	-m)	min=y;  shift;;
esac

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

name=$1
new_value=$2

if [ ! -f $STUNE ]
then
	echo "$name\t$new_value" >$STUNE
	exit $?
fi

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 "
	Tuneable Parameter \"$name\" is currently set to ${old_value}.
	Is it OK to change it to $new_value? (y/n):  \c"
		read ans
		case $ans in
			y*|Y*)	;;
			*)	echo "
	\"$name\" left at ${old_value}.
"
				exit 0;;
		esac
		echo
	fi
	ed - $STUNE >/dev/null 2>&1 <<-!
		/^$name[ 	]/c
		$name	$new_value
		.
		w
	!
	exit $?
else
	echo "$name\t$new_value" >>$STUNE
	exit $?
fi
