#!/sbin/sh -


# strlen - return length of given string
strlen()
{
        echo $1 | awk '{ printf("%d",length($1)) }'
}


#
# cp the correct driver 
# 

#
# Get the OS and revision information...
#

OS_VERS=`eval uname -r`
OS_VEND=`eval uname -s` 

# if this is this Vm 2.3, there is no need to copy vxio, vxspec and
# vxconfigd over.

VM_VERS=`eval pkginfo -l SUNWvxvm | grep "VERSION:  2.3"`



TMP_OS_VERS=${OS_VERS}

if [ "${VM_VERS}" = "" ]
	then
                VM_VERS=`eval pkginfo -l SUNWvxvm | grep VERSION`
		echo "Vxvm${VM_VERS}"

		if [ ! -s /kernel/drv/vxio ]
			then	
			echo "could not find /kernel/drv/vxio"
			return 1
		fi 
	
# Prior to 105463-03, The vxio and vxspec ment for solaris 2.5 was used in
# Solaris 2.5.1 also... So take account of this and backout accordingly.

#case ${TMP_OS_VERS} in
#                5.5.1)
#                        TMP_OS_VERS=5.5
#esac

#if [ -s /kernel/drv/vxio.SunOS_5.5.1 ]
#then
#	TMP_OS_VERS=5.5.1
#fi

		if [ -s /kernel/drv/vxio.${OS_VEND}_${TMP_OS_VERS} ]
			then
			echo "copying /kernel/drv/vxio.${OS_VEND}_${TMP_OS_VERS} /kernel/drv/vxio"
			cp /kernel/drv/vxio.${OS_VEND}_${TMP_OS_VERS} /kernel/drv/vxio
			else
			echo "could not find /kernel/drv/vxio.${OS_VEND}_${TMP_OS_VERS}"
			return 1
		fi 

	
		if [ -s /kernel/drv/vxspec.${OS_VEND}_${TMP_OS_VERS} ]
			then
			echo "copying /kernel/drv/vxspec.${OS_VEND}_${TMP_OS_VERS} /kernel/drv/vxspec "
			cp /kernel/drv/vxspec.${OS_VEND}_${TMP_OS_VERS} /kernel/drv/vxspec
			else
			echo "could not find /kernel/drv/vxspec.${OS_VEND}_${TMP_OS_VERS}"
			return 1
		fi
	

# Since Solaris 2.4 does not have DMP, Do not attemp to Backout DMP.
# Also if AP is present, do not restore DMP.

dmpokay="yes"

# Check if AP installed, if yes do not restore DMP 
APDRV="$BASEDIR/kernel/drv/ap"

if [ -f "$APDRV" ]
 then
        echo "NOTICE: AP driver detected, DMP driver will not be enabled...."
        dmpokay=
fi

# Check if AP or ATF installed, if yes do not restore DMP 
ATFDRV="$BASEDIR/kernel/drv/atf"
if [ -f "$ATFDRV" ]
 then
        echo "NOTICE: ATF driver detected, DMP driver will not be enabled...."
        dmpokay=
fi

# Check if DMP already disabled, if so do not restore DMP 
if [ -h $BASEDIR/dev/vx/dmp ]
 then
        echo "NOTICE: DMP driver was previously disabled, so will not be enabled...."
        dmpokay=
fi


		if [ -s /kernel/drv/vxdmp.${OS_VEND}_${TMP_OS_VERS} -a "$dmpokay" = "yes" ]
			then
			echo "copying /kernel/drv/vxdmp.${OS_VEND}_${TMP_OS_VERS} /kernel/drv/vxdmp "
			cp /kernel/drv/vxdmp.${OS_VEND}_${TMP_OS_VERS} /kernel/drv/vxdmp
			else
			if [ $TMP_OS_VERS != "5.4" -a "$dmpokay" = "yes" ]
                        then
			echo "could not find /kernel/drv/vxdmp.${OS_VEND}_${TMP_OS_VERS}"
			return 1
			fi
		fi

		if [ -s /sbin/vxconfigd.${OS_VEND}_${TMP_OS_VERS} ]
			then	
			echo "copying /sbin/vxconfigd.${OS_VEND}_${TMP_OS_VERS} /sbin/vxconfigd "
			cp /sbin/vxconfigd.${OS_VEND}_${TMP_OS_VERS} /sbin/vxconfigd
			else
	
# this may be an old version with only 5.4 and 5.6 versions of vxconfigd...
# vxconfigd 5.4 was used for Solaris 2.4, 2.5 and 2.5.1....
	
			case ${TMP_OS_VERS} in
		        	5.5|5.5.1) TMP_OS_VERS=5.4
					echo "copying /sbin/vxconfigd.${OS_VEND}_${TMP_OS_VERS} /sbin/vxconfigd "
					cp /sbin/vxconfigd.${OS_VEND}_${TMP_OS_VERS} /sbin/vxconfigd
		        		;;
			esac
	
		fi
	
	else
		echo "Vxvm${VM_VERS}"

fi
	
# Remove the debug utility that was introduced during patch install

DIAGDIR=/usr/lib/vxvm/diag.d
rm $DIAGDIR/vxautoconfig > /dev/null 2>&1

