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

# Copyright (c) 2000 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


# This startup script runs very early in the boot sequence to
# configure the / and /usr volumes as needed.

opts=

# comment-out or uncomment any of the following lines to enable or
# disable the corresponding feature in vxconfigd.

#opts="$opts -x syslog"			# use syslog for console messages
#opts="$opts -x log"			# messages to /var/vxvm/vxconfigd.log
#opts="$opts -x logfile=/foo/bar"	# specify an alternate log file
#opts="$opts -x timestamp"		# timestamp console messages

# to turn on debugging console output, uncomment the following line.
# The debug level can be set higher for more output.  The higest debug
# level is 9.

#debug=1				# enable debugging console ouptut

[ -n "$debug" ] && {
	opts="$opts -x $debug"		# set debugging to the requested level
}

vxconfigd_opts=$opts

# By default, the restore daemon will check the health of
# only disabled paths with a polling interval of 300sec.

restore_daemon_opts="interval=300 policy=check_disabled"

# Uncomment the following line to turn on checking for all
# the paths on the system with polling interval of 300sec.

# restore_daemon_opts="interval=300 policy=check_all"

# do not start if the upgrade_start script was run and the upgrade_finish
# has not be run yet, because /etc/vx/slib does not have right libraries
# till the upgrade_finish is run

if [ -f /VXVM3.0-UPGRADE/.start_runed ]
then
	exit 0
fi

# check whether vxconfigd must succeed in order for / and /usr to
# work correctly.
vold_must_succeed=
[ -f /etc/system ] && {
	exec < /etc/system
	while read sysline
	do
		case $sysline in
		"set vxio:vol_rootdev_is_volume=1")
			vold_must_succeed=yes;;
		esac
	done
	exec < /dev/null
}
exec < /etc/vfstab
while read dev rdev mpoint more
do
	case $dev in
	\#*)    continue
		;;
	esac
	if [ "X$mpoint" = X/usr ]
	then
		case $dev in
		/dev/vx/dsk/*)
			startusrvol=:start=$dev
			vold_must_succeed=yes;;
		esac
	fi
done
exec < /dev/null
if [ -z "$vold_must_succeed" ] && [ -f /etc/vx/reconfig.d/state.d/install-db ]
then
	exit 0
fi

vxdmpadm doioctl 2>/dev/null

echo "Starting VxVM restore daemon..."

vxdmpadm start restore $restore_daemon_opts

echo "VxVM starting in boot mode..."

LD_LIBRARY_PATH=/etc/lib:/etc/vx/slib vxconfigd $vxconfigd_opts -m boot
ret=$?
if [ $ret = 0 ] ; then
	exit 0
fi
if [ $ret -eq 9 ]
then
	if [ -x /etc/vx/sbin/vxaltstale ]
	then
		/etc/vx/sbin/vxaltstale
	else
		sync;sync;uadmin 2 0
	fi
elif [ -n "$vold_must_succeed" ]
then
	msg="
Errors were encountered in starting the root disk group, as a result
VxVM is unable to configure the root and/or /usr volumes.  If you have
mirrored the root disk, you can try booting from that disk.  Please
refer to Appendix C of the Installation Guide for more details.

If you cannot boot from the root disk, you can try to repair the problem
using a network-mounted root file system or some other alternate root
file system.  Again, see the Installation Guide for more details.

Would you like a shell prompt right now? [no] "
	if [ -d /usr/lib ]
	then
		egettxt "$msg" vxvmshm:44
	else
		echo "$msg\c"
	fi
	exec < /dev/console
	read yorn
	case $yorn in
	y|yes)	/sbin/sh
		echo "Continue with system boot? [no] \c"
		read yorn
		case $yorn in
		y|yes)	exit 0;;
		esac
		;;
	esac
	echo "Halting system..."
	sync;sync;uadmin 2 0
fi
