#!/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 [ ! -s /kernel/drv/vxio ]
	then	
		echo "could not find /kernel/drv/vxio"
		return 1
fi 


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

		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
		

# Check if it is OK to install DMP
# Solaris 2.4 does not support DMP. So Do not attempt to copy vxdmp for solaris 2.4
# Do not install DMP if AP is present
# If Check if DMP already disabled, if so do not install DMP 

dmpokay="yes"

# Check if AP installed, if yes do not finish DMP install
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 finish DMP install
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 finish DMP install
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
				case ${TMP_OS_VERS} in
					5.5)
						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

# copy the debug utility vxautoconfig according to OS version

DIAGDIR=/usr/lib/vxvm/diag.d
cp $DIAGDIR/config.d/vxautoconfig.${OS_VEND}_${TMP_OS_VERS} $DIAGDIR/vxautoconfig > /dev/null 2>&1


echo
echo " NOTE: The System must be rebooted for this patch to work. "
echo " Please reboot the system once the patch is installed."
echo


