#!/bin/sh
#
# installation routine for RMS HP-OV
#

PATH=$PATH:/usr/ucb
export PATH

if [ -z "$OV_BIN" ]; then
	 echo "Openview environment variables are not set up correctly."
	 echo "Exiting."
	 exit 1
fi
	 
if [ "`whoami`" != "root" ]; then
	 echo "Installation should run as root."
    echo "Continue ? (y/n)"
	 read query
	 if [ "$query" != "y" ]; then
		  echo "Exiting."
		  exit 0
	 fi
fi

echo "RMS HP-Openview Integration"

VERSION=`$OV_BIN/ovnnmversion`

case $VERSION in
	 5.01) ;;
	 *)  echo "Currently only Version 5.01 is supported. You may continue at"
		  echo "your own risk"
		  echo "continue ? (y/n)"
		  read query
		  if [ "$query" != "y" ] ; then
				echo "Exiting."
				exit 0
        fi
		  ;;
esac

# Load mib

echo
echo "Loading RMS mib..."
$OV_BIN/xnmloadmib -event -replace -load ./rms.mib

if [ $? -ne 0 ] ; then
	 echo " Mib Load failed"
else
	 echo " Done."
fi

# Integrate Vendor Fields

if [ ! -f rms.fields ] ; then
	 echo "File rms.fields is missing";
fi

if [ -z "$OV_FIELDS" ] ; then
	echo "Openview environment variables are not set up correctly (OV_FIELDS)."
	echo "Exiting."
	exit 1
fi

if [ -f $OV_FIELDS/C/rms.fields ] ; then
	 rm -f $OV_FIELDS/C/rms.fields
fi

cp rms.fields $OV_FIELDS/C/rms.fields
chmod a+r $OV_FIELDS/C/rms.fields

echo "rereading fields"
$OV_BIN/ovw -fields >/dev/null
if [ $? -ne 0 ] ; then
	 echo " failed."
fi

# add symbols

if [ -d $OV_SYMBOLS/C/RMSDev ]; then
	rm $OV_SYMBOLS/C/RMSDev/*
fi

if [ -d $OV_BITMAPS/C/rmsdev ]; then
	rm $OV_BITMAPS/C/rmsdev
fi

cp -r RMSDev $OV_SYMBOLS/C
cp -r rmsdev $OV_BITMAPS/C
chmod a+r $OV_SYMBOLS/C/RMSDev/*
chmod a+r $OV_BITMAPS/C/rmsdev/*

# add trap format

# $OV_BIN/xnmevents -delete rmsFilterTrap
$OV_BIN/xnmevents -merge rms.conf

# oid_to_sym

if [ -f /tmp/rms.$$ ]; then
	 rm -f /tmp/rms.$$
fi

sed '/^1\.3\.6\.1\.4\.1\.2769\.10\.1:/d' < $OV_CONF/oid_to_sym > /tmp/rms.$$
echo "1.3.6.1.4.1.2769.10.1:Device:Generic # RMS" >> /tmp/rms.$$
mv $OV_CONF/oid_to_sym $OV_CONF/oid_to_sym.1
cp /tmp/rms.$$ $OV_CONF/oid_to_sym
rm -f /tmp/rms.$$

# oid_to_type

if [ -f /tmp/rms.$$ ]; then
	 rm -f /tmp/rms.$$
fi

sed '/^1\.3\.6\.1\.4\.1\.2769\.10\.1:/d' < $OV_CONF/oid_to_type > /tmp/rms.$$
echo "1.3.6.1.4.1.2769.10.1:Knuerr:Knuerr RMS:" >> /tmp/rms.$$
mv $OV_CONF/oid_to_type $OV_CONF/oid_to_type.1
cp /tmp/rms.$$ $OV_CONF/oid_to_type
rm -f /tmp/rms.$$

# restart netmon to reread oid_to_sym

$OV_BIN/ovstop netmon
$OV_BIN/ovtopofix -u -o 1.3.6.1.4.1.2769.10.1
$OV_BIN/ovstart netmon

# add some graphs

# application to show inputs

echo "Done"
echo
echo "Please restart your ovw-sessions for the changes to take effekt"
