# RE_SID: @(%)/tmp_mnt/vol/pnw/sundance_SCCS/sun/cmd/sconsole/scripts/SCCS/s.edcfg.sh 1.4 93/10/29 13:54:53 SMI
# *************************************************************************
#
# Copyright 1992, Sun Microsystems, Inc.  All Rights Reserved.
#
# (c) Copyright 1992, Sun Microsystems, Inc.  All Rights Reserved.
# Derived from UNIX(R) and Berkeley 4.3 BSD licensed from UNIX System
# Laboratories, Inc. and the Regents of the University of California,
# respectively. Sun considers its source code as an unpublished, proprietary
# trade secret, and it is available only under strict license provisions.
# This copyright notice is placed here only to protect Sun in the event the
# source is deemed a published work.  Disassembly, decompilation, or other
# means of reducing the object code to human readable form is prohibited by
# the license agreement under which this code is provided to the user or
# company in possession of this copy.
#
# RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
# Government is subject to restrictions as set forth in subparagraph
# (c)(1)(ii) of the Rights in Technical Data and Computer Software
# Clause at DFARS 252.227-7013 (Oct. 1988) and FAR 52.227-19 (c)
# (June 1987). Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain
# View, California 94043
#
# **************************************************************************
#!/bin/sh

#
# Copyright 1989, 1991 Novell, Inc. All Rights Reserved.
#
# THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
# TREATIES.  NO PART OF THIS WORK MAY BE USED, PRACTICED, PERFORMED,
# COPIED, DISTRIBUTED, REVISED, MODIFIED, TRANSLATED, ABRIDGED,
# CONDENSED, EXPANDED, COLLECTED, COMPILED, LINKED, RECAST,
# TRANSFORMED OR ADAPTED WITHOUT THE PRIOR WRITTEN CONSENT
# OF NOVELL.  ANY USE OR EXPLOITATION OF THIS WORK WITHOUT
# AUTHORIZATION COULD SUBJECT THE PERPETRATOR TO CRIMINAL AND
# CIVIL LIABILITY.
#
#    @(#)cmd/sconsole/scripts/edcfg.sh 1.5 (Novell) 10/14/91
#


filename=$1
cmd=$2
field=$3
prevValue=$4
newValue=$5

case $cmd in
[Aa])
	if [ $field = "volume" ]
	then
		ed $filename >/dev/null 2>&1 <<!EOF1
			$
			?^volume
			.a
volume = "$prevValue"
.
			w
			q
!EOF1
	else
		A0="^$field"
		if grep "$A0" $filename >/dev/null
		then
			ed $filename >/dev/null 2>&1 <<!EOF5
				/$A0
				.,.d
				w
				q
!EOF5
		fi
		ed $filename >/dev/null 2>&1 <<!EOF4
			\$a
$field = $prevValue
.
			w
			q
!EOF4
	fi
	;;
[Cc])
	if [ $field = "volume" ]
	then
		A0="$prevValue"
	else
		A0="^$field[ 	]*=[ 	]*"
	fi
	if grep "$A0" $filename >/dev/null
	then
		if grep "$A0[0-9][0-9]*[ 	]*[-*/+][ 	]*[0-9][0-9]*" $filename 
		then
			# we need to handle the case where the number in the config file
			# is represented by a numeric expression
			ed $filename >/dev/null 2>&1 <<!EOF2A
				/$A0
				.,.s@=[ 	]*[0-9][0-9]*[ 	]*[-*/+][ 	]*[0-9][0-9]*@= $newValue@
				w
				q
!EOF2A
		else
			ed $filename >/dev/null 2>&1 <<!EOF2B
				/$A0
				.,.s@$prevValue@$newValue@
				w
				q
!EOF2B
		fi
	else
		exit 1
	fi
	;;
[Dd])
	if [ $field = "volume" ]
	then
		A0="$prevValue"
	else
		A0="^$field[= 	]"
	fi
	if grep "$A0" $filename >/dev/null
	then
		ed $filename >/dev/null 2>&1 <<!EOF3
			/$A0
			.,.d
			w
			q
!EOF3
	fi
	;;
esac
exit 0
