:
#
# aodrdset (Online Diagnostics)
#


# check for superuser id

if [ `logname` != "root" ]
then
	echo "Must be super-user to execute aodsetdef script"
	exit 2
fi

################################################################################

#define file equates to shorten shell script lines
xfile=/usr/lib/err.xref
tfile=/usr/lib/err.thresh

# we need to get device/error definitions and current thresholds settings from 
#	err.xref (error-desc cross-reference) and err.thresh (settings)
#	files.

# first check if thresholds settings file exists
# check first if cross-ref files is present
if [ ! -f $xfile ]
then
	# cross-reference file doesn't exist; make default one
	/usr/lib/aodmkxref $HEADINGS
	RETVAL=$?
	if [ $RETVAL -ne 0 ]
	then
		exit `expr 8 + $RETVAL`
	fi
fi

# now read the error types for each kind of device being monitored
#
# get current settings for all types of devices on system
#
if [ "$HEADINGS" ]
then
	echo
	echo "Reading error definitions & descriptions file...\c"
fi
#
# get hard drive settings
#
hdfields=`awk 'BEGIN{FS=";";cnt=0}{if($1=="hd"){cnt++;printf("%d ",cnt);}}' $xfile`; 
for i in $hdfields
do
	eval "hdval$i='`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"hd\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$2\)\;\}\}\} $xfile`'"
	eval "hdstr$i=\"`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"hd\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$3\)\;\}\}\} $xfile`\""
done; 

#
# get floppy drive settings
#
fdfields=`awk 'BEGIN{FS=";";cnt=0}{if($1=="fd"){cnt++;printf("%d ",cnt);}}' $xfile`; 
for i in $fdfields
do
	eval "fdval$i='`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"fd\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$2\)\;\}\}\} $xfile`'"
	eval "fdstr$i=\"`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"fd\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$3\)\;\}\}\} $xfile`\""
done; 

#
# get tape drive settings
#
tpfields=`awk 'BEGIN{FS=";";cnt=0}{if($1=="tp"){cnt++;printf("%d ",cnt);}}' $xfile`; 
for i in $tpfields
do
	eval "tpval$i='`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"tp\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$2\)\;\}\}\} $xfile`'"
	eval "tpstr$i=\"`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"tp\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$3\)\;\}\}\} $xfile`\""
done; 

#
# get multidrop board settings
#
mdcfields=`awk 'BEGIN{FS=";";cnt=0}{if($1=="mdc"){cnt++;printf("%d ",cnt);}}' $xfile`; 
for i in $mdcfields
do
	eval "mdcval$i='`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"mdc\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$2\)\;\}\}\} $xfile`'"
	eval "mdcstr$i=\"`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"mdc\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$3\)\;\}\}\} $xfile`\""
done; 

#
# get sio board settings
#
siofields=`awk 'BEGIN{FS=";";cnt=0}{if($1=="sio"){cnt++;printf("%d ",cnt);}}' $xfile`; 
for i in $siofields
do
	eval "sioval$i='`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"sio\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$2\)\;\}\}\} $xfile`'"
	eval "siostr$i=\"`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"sio\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$3\)\;\}\}\} $xfile`\""
done; 

#
# get Kernel settings
#
krnfields=`awk 'BEGIN{FS=";";cnt=0}{if($1=="krn"){cnt++;printf("%d ",cnt);}}' $xfile`; 
for i in $krnfields
do
	eval "krnval$i='`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"krn\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$2\)\;\}\}\} $xfile`'"
	eval "krnstr$i=\"`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"krn\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$3\)\;\}\}\} $xfile`\""
done; 

#
# get Miscellaneous settings
#
misfields=`awk 'BEGIN{FS=";";cnt=0}{if($1=="mis"){cnt++;printf("%d ",cnt);}}' $xfile`; 
for i in $misfields
do
	eval "misval$i='`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"mis\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$2\)\;\}\}\} $xfile`'"
	eval "misstr$i=\"`awk BEGIN\{FS=\\"\;\\"\;cnt=0\}\{if\(\\$1==\\"mis\\"\)\{cnt++\;if\(cnt=="$i"\)\{printf\(\\"%s\\",\\$3\)\;\}\}\} $xfile`\""
done; 

if [ "$HEADINGS" ]
then
	echo "done"
fi
