#!/sbin/sh -
# %W% %G% %U% - %Q%
#ident "%Z%unixvm:%M% %I%"

# Copyright (c) 2001 VERITAS Software Corporation.  ALL RIGHTS RESERVED.
# UNPUBLISHED -- RIGHTS RESERVED UNDER THE COPYRIGHT
# LAWS OF THE UNITED STATES.  USE OF A COPYRIGHT NOTICE
# IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
# OR DISCLOSURE.
# 
# THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND
# TRADE SECRETS OF VERITAS SOFTWARE.  USE, DISCLOSURE,
# OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR
# EXPRESS WRITTEN PERMISSION OF VERITAS SOFTWARE.
# 
#               RESTRICTED RIGHTS LEGEND
# USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT IS
# SUBJECT TO RESTRICTIONS AS SET FORTH IN SUBPARAGRAPH
# (C) (1) (ii) OF THE RIGHTS IN TECHNICAL DATA AND
# COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013.
#               VERITAS SOFTWARE
# 1600 PLYMOUTH STREET, MOUNTAIN VIEW, CA 94043


PATH=$PATH:/sbin

#
# Need to force C locale setting so that
# english text is processed.
#
LANG=C
export LANG

#
# Start in background to prevent hang (unlikely case of driver being stuck).
#
vxdctl -k stop >/dev/null 2>&1 &
PIDS=$!
sleep 2

#
# If vxdctl didn't succeed try the brute force method to stop vxconfigd.
# With -k vxdctl also sends -9, so this is possibly redundant (almost
# always vxdctl will kill vxconfigd and terminate itself, leaving us
# nothing to do. However if vxdctl got stuck, kill both vxdctl and vxconfigd.
# vxdctl is still the preferred option, since the deamon could have been
# named something other than vxconfigd.
#
PIDS="$PIDS `ps -e -o pid,comm | grep vxconfigd | sed 's/[^ 	]*$//'`"
kill -9 ${PIDS} 2>/dev/null

#
# It is highly unlikely that modunload will hang, but just in case it does
# (in case driver gets stuck), we will start it in background, wait for a
# little while and terminate (to allow shutdown to complete).
#
for v in vxspec vxio vxdmp
do
	mid=`/usr/sbin/modinfo|/usr/bin/grep -w "$v"|/usr/bin/awk '{print $1}'`
	[ -n "$mid" ] && {
		/usr/sbin/modunload -i $mid >/dev/null 2>&1 || break
	}
done &
sleep 3

# Need to make sure Veritas private slib stuff is up to date.
# Long term solution is to eliminate these shared
# library dependency altogether.

# Copy all library files needed for vxconfigd from /usr/lib to /etc/vx/slib
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; }'`;

for SO_LIB in ${SO_LIBS};
do
	name=`basename ${SO_LIB}`
	cmp -s ${SO_LIB} /etc/vx/slib/${name} || cp -f ${SO_LIB} /etc/vx/slib;
done

# libraries libthread.so.1 and libc.so.1 are incompatible for
# Solaris 2.5 and 2.4, if the root is encapsulated and if a user
# does a upgrade of Solaris from 2.4 to 2.5 the libraries existing
# in /etc/vx/slib are not valid anymore. So we should copy 2.5 libraries
# from /usr/lib to /etc/vx/slib after checking if the OS was upgraded
# the above is just an example. The libraries should always be copied
# to ensure that the correct libraries are available at all times.
#
# Incident 71754/Sun bug ID 4479171, pending a patch to libthread.so,
# we need to use /usr/lib/lwp/libthread.so for Solaris 8/9 . Since this
# library doesn't exist in 2.6/7, check if it exists. Compare if the files
# differ, if so copy from system. Should administrator want to use the
# library from /usr/lib instead, they should comment out relevant portion.
#

if [ -f /usr/lib/lwp/libthread.so.1 ]
then
	cmp -s /usr/lib/lwp/libthread.so.1 /etc/vx/slib/libthread.so.1 ||
		cp /usr/lib/lwp/libthread.so.1 /etc/vx/slib/libthread.so.1
elif [ -f /usr/lib/libthread.so.1 ]
then
	cmp -s /usr/lib/libthread.so.1 /etc/vx/slib/libthread.so.1 ||
		cp /usr/lib/libthread.so.1 /etc/vx/slib/libthread.so.1
fi
	
exit 0
