#!/bin/sh

PATH=/usr/bin:$PATH
export PATH

if [ "$ROOTDIR" = "/" ]; then
   rel=`uname -r`
elif [ -n "$PATCH_CLIENT_VERSION" ]; then
   rel=$PATCH_CLIENT_VERSION
else
   release_file=$ROOTDIR/var/sadm/system/admin/INST_RELEASE
   if [ -f "$release_file" ]; then
      rel=`grep VERSION $release_file | nawk -F= '{print $2}'`
   else
      echo "It's not clear the OS version of the system. Patch Terminating.."
      echo
      exit 1   
   fi
fi

echo

case ${rel} in
   5.6|2.6|5.7|2.7|7|5.8|2.8|8)
		SUFFIX="SunOS_5.`expr ${rel} : '.*\(.\)'`"
	;;
   *)	echo
        echo " This OS version is not supported by this patch"
        echo " Patch terminating.."
	echo
	exit 1
	;;
esac

DRVDIR=${ROOTDIR}/kernel/drv
DRVDIR64=${DRVDIR}/sparcv9
mv ${ROOTDIR}/sbin/vxconfigd.${SUFFIX} ${ROOTDIR}/sbin/vxconfigd
cp -p ${ROOTDIR}/sbin/vxconfigd ${ROOTDIR}/sbin/vxconfigd.${SUFFIX}

for driver_to_cp in vxio vxdmp vxspec ; do
   mv ${DRVDIR}/${driver_to_cp}.${SUFFIX} ${DRVDIR}/${driver_to_cp}
   cp -p ${DRVDIR}/${driver_to_cp} ${DRVDIR}/${driver_to_cp}.${SUFFIX}
   if [ -f ${DRVDIR64}/${driver_to_cp}.${SUFFIX} ]
   then
      mv ${DRVDIR64}/${driver_to_cp}.${SUFFIX} ${DRVDIR64}/${driver_to_cp}
      cp -p ${DRVDIR64}/${driver_to_cp} ${DRVDIR64}/${driver_to_cp}.${SUFFIX}
   fi
done

# Make sure our slib stuff is up to date.
# Stop vxconfigd before copying libraries as to avoid corruption.
LD_LIBS=/etc/lib:/usr/lib/lwp:/usr/lib:/usr/platform/`uname -i`/lib;
SO_LIBS=`LD_LIBRARY_PATH=$LD_LIBS ldd /sbin/vxconfigd \
                | awk '$NF ~ /\/usr\// { print $NF; }'`;
stop_vold=0;
for SO_LIB in ${SO_LIBS};
do
        name=`basename ${SO_LIB}`
        cmp -s ${SO_LIB} /etc/vx/slib/${name} || {
                [ $stop_vold -eq 0 ] && {
                        stop_vold=1; vxdctl stop;
                }
                cp -f ${SO_LIB} /etc/vx/slib;
        }
done;
[ $stop_vold -eq 1 ] && vxconfigd;

exit 0
