#!/sbin/sh -
# @(#)src/scripts/vxvm/solaris/fixit/fixstartup.sh	1.1.4.1 14 Apr 1997 20:36:15 - 
#ident	"@(#)vxvm:src/scripts/vxvm/solaris/fixit/fixstartup.sh	1.1.4.1"

# Copyright(C)1996 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

yes_or_no()
{
	while :
	do
		echo "\n$1? [$2] \c"
		ANS=
		read ANS
		case $ANS in
		"")	ANS=$2; break;;
		n|no)	ANS=no; break;;
		y|yes)	ANS=yes; break;;
		*)	echo "\nPlease answer \"yes\" or \"no\"."
			continue;;
		esac
	done
	[ $ANS = yes ]
}

doit()
{
	echo "!$*" >&2
	"$@"
}

abort()
{
	echo "
VxVM could not be started.  Aborting.  If you need further help
contact Solaris or VERITAS customer support.
"
	exit 1
}

[ -z "$__VXVM_ROOT_DIR" ] && {
	echo "
You must first run the fixsetup script.  Run fixsetup using the
form:

	. fixsetup

so that environment variables set by fixsetup will be available to
the shell and to other scripts that you run.
"
	exit 1
}

VXR=$__VXVM_ROOT_DIR

echo "
This script can be used to start VxVM running from the VxVM CDROM.  It
needs some information that VxVM would normally get from the root file
system.  If you know the device containing your root file system, or
one of the mirrors of your root file system volume, then you can run
the command:

	fixmountroot

The fixmountroot command will ask you for a disk containing a copy of
the root file system, and will use the file system on that disk to get
the necessary startup files.
"

yes_or_no "Would you like to run fixmountroot instead" no && {
	echo "
Executing fixmountroot ..."
	exec fixmountroot
	echo "
Could not run fixmountroot.  Exiting.
"
	exit 1
}

echo "
You will need to supply the host ID used by the volume manager in the
/etc/vx/volboot file.  This is normally the hostname of your machine,
but could have been changed to some other value with the vxdctl hostid
or vxdctl init commands.  Also, if you changed the name of your host,
then VxVM may still be using the old name.
"
hostname=`sed -n 's/^hostid \(.*\)/\1/p' $VXR/etc/vx/volboot 2> /dev/null`
[ -n "$hostname" ] || hostname=`uname -n`
echo "Enter the VxVM host ID: [$hostname] \c"
read hostid
[ -n "$hostid" ] || hostid=$hostname

echo "
If you are using a SPARCstorage Array controller (and your currently
booted operating system has the SSA drivers loaded), then you do not
need a license key.  However, if you are not running a SPARCstorage
Array Controller, or your current boot environment does not support
loading the SSA drivers, then you need a license key.  You can obtain
a special license key, if necessary, from VERITAS customer support.
If you remember your old license key, then you can use that.  To
recover any RAID-5 volumes you will need an additional license key for
that.
"

echo "Licensing information:"
echo " System host ID: `hostid`"
echo " Host type: `prtconf | sed -n -e '/^$/{' -e n -e p -e q -e '}'`"
if ls -l /dev/dsk/c*s2 2> /dev/null | grep '/SUNW,pln@' > /dev/null
then
	def=no
	echo " SPARCstorage Array: Attached (no license required)"
elif [ -c /dev/ff ]; then
        def=no
        echo " SPARCstorage Array: No array found but Sun cluster Failfast drive
r found (no license required)"
else
	def=yes
	echo " SPARCstorage Array: No array found (license is required)"
fi
ls $VXR/etc/vx/elm/9[0-9] 2> /dev/null | grep . > /dev/null && {
	def=no
	yes_or_no \
	    "Some licenses are already installed.  Do you wish to review them" \
	    yes && vxserial -p
}
ask="Do you need a license key"
while :
do
	yes_or_no "$ask" $def || break
	vxserial -c || continue
	ask="Do you need another license key"
	def=no
done

echo "Starting up VxVM"
vxdctl -k stop 2> /dev/null
doit vxconfigd -m disable || abort
doit vxdctl init $hostid || abort
doit vxdctl enable || {
	echo "
VxVM could not be enabled.  Perhaps your rootdg configuration is
corrupt.  Perhaps some disk drives in your rootdg configuration are
not accessible.
"
	exit 1
}

yes_or_no "Do you wish to start volumes in the rootdg disk group" yes || {
	echo "
You can start volumes in rootdg yourself using the command:

	vxrecover -svn -g rootdg
"
	exit 0
}
doit vxrecover -svn -g rootdg

yes_or_no "Do you wish to start volumes in all other disk groups" no || {
	echo "
You can start all volumes in all known disk groups using the command:

	vxrecover -svn
"
	exit 0
}
doit vxrecover -svn
