#!/bin/ksh
#
# mv-setup version 1.2 - 12/11/95 (jlc)
#
# configuration script to add MarkVision & Lexmark MarkNet adaptors to
# NetView/6000 for AIX version 3 or 4
#
(
ErrCode=0

if [ `whoami` != "root" ]
then
	print "This configuration script must be run by root."
	exit 1
fi

/usr/OV/bin/vfy_access ovtopofix

case $? in
	1) # ERROR
		print "Error: cannot verify access."
		exit 1
		;;
	2) # user not logged in
		print "User not logged in" 
		exit 1
		;;
	3) # cannot connect to nvsecd
		print "Error: cannot connect to nvsecd"
		exit 1
		;;
	4) # user logged in but not authorized
		print "Your user ID not authorized to reconfigure NetView."
		exit 1
		;;
	0) # OK
		;;
esac


if [ -L "/usr/markvision" ]
then
	mvlevel='2.0'
else
	if [ -f "/etc/mv_printers" ]
	then
		mvlevel='1.0'
	fi
fi

if [ -z "$mvlevel" ]
then
	print "ERROR:0 Could not determine version number of markvision.client."
	exit 1
fi

if [ "$mvlevel" -gt 1.1 ]
then
	MVWD=/usr/markvision/
else
	MVWD=/usr/lpp/markvision/
fi

cd "/usr/lpp/mv4nv"
if [ $? -ne 0 ]
then
	print "ERROR:1 Could not change to working directory /usr/lpp/mv4nv."
	exit 1
fi


print "Loading lexmark1.mib into Netview"
# load lexmark1.mib into Netview
if [ "$mvlevel" -gt 1.1 ]
then
	/usr/OV/bin/xnmloadmib -load $MVWD/etc/lexmark1.mib
else
	/usr/OV/bin/xnmloadmib -load $MVWD/lexmark1.mib
fi

MIBSTATUS=$?
if [ "$MIBSTATUS" -ne 0 ]
then
	if [ "$MIBSTATUS" -eq 3 ]
	then
	print "Note:81 Netview app xnmloadmib reported lexmark1.mib already loaded"
	else
	print "Error:82 Netview app xnmloadmib reported an error loading lexmark1.mib"
	ErrCode=1
	fi
fi

#  add "IR/Cleared" trap lines to trapd.conf
#  /usr/OV/bin/addtrap -n lexmark -l label -i 1.3.6.1.4.1.641 -g 6 -s 1 -o source-id -t status-type -c catagory -F format -S severity
#
#  IR Cleared
/usr/OV/bin/addtrap -n lexmark -l MarkNet_IRC -i 1.3.6.1.4.1.641 -g 6 -s 0 -o A -t 2 -c "Status Events" -F "Printer IR Cleared" -S 0 
if [ $? -ne 0 ]
then
	print "ERROR:11 could not add IR Cleared to trapd configuration."
	ErrCode=1
fi
#  IR Received
/usr/OV/bin/addtrap -n lexmark -l MarkNet_IRR -i 1.3.6.1.4.1.641 -g 6 -s 1 -o A -t 4 -c "Status Events" -F "Printer Intervention Required: $+2 $%1" -S 2 
if [ $? -ne 0 ]
then
	print "ERROR:12 could not add IR Received to trapd configuration."
	ErrCode=1
fi

cp ./mv2.gif /usr/OV/icons/gifs/
cp ./mvx.xbm.m /usr/OV/icons/drag-bitmaps/
cp ./mvx.xbm.p /usr/OV/icons/drag-bitmaps/

########################################3
# make sure Netview is not running
# alternate command: /usr/OV/bin/ovstop -v
/usr/OV/bin/nv6000_smit stopdaemons 
if [ $? -ne 0 ]
then
	print ""
	print "ERROR:2 could not stop Netview daemons."
	exit 1
fi


#  add "...641.1:Lexmark:Lexmark MarkNet" to oid_to_type
grep -q '641.1:Lexmark:Lexmark MarkNet' /usr/OV/conf/oid_to_type
if [ $? -eq 1 ]
then

	mv /usr/OV/conf/oid_to_type  /usr/OV/conf/oid_to_type.mvbak
	if [ $? -ne 0 ]
	then
		print "ERROR:21 could not move oid_to_type - no update occurred."
		ErrCode=1
	else
		cat /usr/OV/conf/oid_to_type.mvbak ./oid_to_type.add > /usr/OV/conf/oid_to_type
		if [ $? -ne 0 ]
		then
			print "ERROR:22 could not create new oid_to_type file."
			print "         you must correct /usr/OV/conf/oid_to_type"
			print "         by using ./oid_to_type.add and /usr/OV/conf/oid_to_type.mvbak"
			ErrCode=1
		fi
	fi
fi

#  add "...641.1:device:printer" to oid_to_sym
grep -q '641.1:device:printer' /usr/OV/conf/C/oid_to_sym
if [ $? -eq 1 ]
then

	mv /usr/OV/conf/C/oid_to_sym  /usr/OV/conf/C/oid_to_sym.mvbak
	if [ $? -ne 0 ]
	then
		print "ERROR:31 could not move oid_to_sym - no update occurred."
		ErrCode=1
	else
		cat /usr/OV/conf/C/oid_to_sym.mvbak ./oid_to_sym.add > /usr/OV/conf/C/oid_to_sym 
		if [ $? -ne 0 ]
		then
			print "ERROR:32 could not create new oid_to_sym file."
			print "         you must correct /usr/OV/conf/C/oid_to_sym"
			print "         by using ./oid_to_sym.add and /usr/OV/conf/C/oid_to_sym.mvbak"
			ErrCode=1
		fi
	fi
fi

#  add tool and action item "MarkVision"
#  once Version 2 is released, markvision f.action should be changed 
#  from:  Command "/usr/bin/markvision -h $OVwSelections";
#  to  :  Command "/usr/bin/markvision -G $OVwSelections";
if [ "$mvlevel" -gt 1.1 ]
then
	cp ./markvision2 /usr/OV/registration/C/markvision
else
	cp ./markvision1 /usr/OV/registration/C/markvision
fi
if [ $? -ne 0 ]
then
	print "ERROR:41 could not register markvision tool."
	ErrCode=1
fi

#  add vendor "lexmark" and snmp agent "Lexmark MarkNet" to fields
cp ./lexmark_fields /usr/OV/fields/C/lexmark_fields
if [ $? -ne 0 ]
then
	print "ERROR:51 could not add 'lexmark_fields'."
	ErrCode=1
fi

#restart ovtopmd so ovtopofix will work
/usr/OV/bin/ovstart ovtopmd

/usr/OV/bin/ovw -fields
if [ $? -ne 0 ]
then
	print "ERROR:61 ovw failed to load new fields."
	ErrCode=1
fi

# change symbols for MarkNet adaptors to "Device:Printer"
/usr/OV/bin/ovtopofix -a

# restart all daemons
/etc/netnmrc

print ""

if [ $ErrCode -eq 0 ]
then
print "mvsetup completed successfully."
exit 0
else
print "WARNING: mvsetup did not complete all functions."
print "         see ./mvsetup.log for details."
exit 1
fi
)  2>&1 | tee /usr/lpp/mv4nv/mvsetup.log
