#!/sbin/sh -
# @(#)src/sol/cmd/vxvm/voladm/vxinstall.sh	1.9.7.10 09/27/00 15:58:25 - Copyright (c) 1999 VERITAS Software Corp.
#ident "@(#)unixvm:src/sol/cmd/vxvm/voladm/vxinstall.sh 1.9.7.10"

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


: ${VOLROOT_DIR:=$__VXVM_ROOT_DIR}
. ${VOL_SCRIPTS_LIB:-$VOLROOT_DIR/usr/lib/vxvm/lib}/vxcommon

bail()
{
	exit 2
}

VOLADM_CURRENT_MENU=
export VOLADM_CURRENT_MENU

rm -rf $RDIR/disks $RDIR/disk.d

check_exclude_files
if [ $? -ne 0 ]
then
	ewritemsg -M vxvmshm:251 \
"Please correct the problem listed above before re-running vxinstall."
	quit 0
fi

#
# If vxlicense can't be found, is not executable, or is zero length
# assume that the package has been created without licensing.
#

vxlicense=`type vxlicense | awk '{ print $3 }'`
LICCHK=/usr/lib/vxvm/bin/vxliccheck
storage_array=
photon_array=
SUNArray=
ses_device=

# check for presence of SSA 
if ls -l /dev/dsk/c*s2 2> /dev/null | grep '/SUNW,pln@' > /dev/null
then
	storage_array=yes
fi

# check for presence of A5000 (SENA)
if [ -d /dev/es ]
then
	for ses_device in `ls /dev/es/ses* 2> /dev/null`
	do
		# vxchksundev will return 0 on match
		vxchksundev $ses_device SENA > /dev/null 2>&1
		if [ "$?" -eq 0 ]
		then
			photon_array=yes
			break
		fi
	done
	if [ -z "$photon_array" ]
	then
		for ses_device in `ls /dev/es/ses* 2> /dev/null`
		do
			# Check for PHOTON devices
			a5k_chk=`$LICCHK -a 2>&1`
			echo $a5k_chk | grep "An A5x00 disk array is detected on this host" > /dev/null

			if [ "$?" -eq 0 ]
			then
				photon_array=yes
				break
			fi
		done
	fi
fi

if [ "$storage_array" = "yes" -o "$photon_array" = "yes" ]
then
	SUNArray=yes
fi
	
if [ -x "$vxlicense" -a -s "$vxlicense" -a "$SUNArray" != "yes" ]
then
	HOSTID=`hostid`
	PLATFORM=`uname -i`

	if [ "$PLATFORM" = "i86pc" ]
	then
		ewritemsg "\
Please consult VxVM Release Notes to determine if a license key is necessary
  for your system.  If it is, please use the information below to request a
  key.  Installation will not be successful if a license key is required and
  not present."
		def=n
	else
		def=y
	fi
	ewritemsg "\
VxVM uses license keys to control access.  If you have a SPARCstorage
  Array (SSA) controller or a Sun Enterprise Network Array (SENA) controller 
  attached to your system, then VxVM will grant you a limited use license 
  automatically.  The SSA and/or SENA license grants you unrestricted use 
  of disks attached to an SSA or SENA controller, but disallows striping,
  RAID-5, and DMP on non-SSA and non-SENA disks.  If you are not running an
  SSA or SENA controller, then you must obtain a license key to operate."
	
	voladm_help_push yorn.help
	ask="Are you prepared to enter a license key"

	ewritemsg "Licensing information:
    System host ID: $HOSTID
    Host type: $PLATFORM
    SPARCstorage Array or Sun Enterprise Network Array: No arrays found"

	# check that basic functionality feature is enabled
	[ -x $LICCHK ] && $LICCHK -f 90
	if [ $? -eq 0 ]
	then
		def=n
		ask="Do you wish to enter another license key"
		voladm_yorn \
"Some licenses are already installed.  Do you wish to review them" \
		    y && vxlicense -p
	else
		ewritemsg "No valid licenses found."
	fi	

	while true
	do
		voladm_yorn "$ask" $def || {
			[ "X$def" = Xy ] && {
				ewritemsg "Cannot continue installation."
				exit 1
			}
			break
		}
		vxlicense -c || continue
		ask="Do you wish to enter another license key"
		def=n
	done
	echo 
fi

if [ -f $mkdbfile ]
then
        xcmd $VOLD -k -m disable > /dev/null 2>&1
        xcmd vxdctl init > /dev/null 2>&1
        vxdg init rootdg > /dev/null 2>&1
        ret=$?
        if [ $ret = 12 ]
        then
                xcmd vxdctl enable
		voldmode=`vxdctl mode 2>/dev/null`
		if [ "X$voldmode" != "Xmode: enabled" ]
		then
	 		ewritemsg -M vxvmshm:879 \
			"vold can not be enabled, quitting"
			quit 10
		fi
	elif [ $ret != 0 ]
	then
		quit $ret
	fi
else
	xcmd vxconfigd -k -m disable > /dev/null 2>&1
	xcmd vxdctl init > /dev/null 2>&1
	xcmd vxdctl enable
	voldmode=`vxdctl mode 2>/dev/null`
	if [ "X$voldmode" != "Xmode: enabled" ]
	then
		ewritemsg -M vxvmshm:879 \
		"vold can not be enabled, quitting"
		quit 10
	fi
fi

voladm_menu_push VolumeManager
doit "$VOLADM_BIN/inst.top" $v_opt
ret=$?
if [ $ret = 0 -a -f $pcapfile ]; then
        ewritemsg -M vxvmshm:391 \
"The system now must be shut down and rebooted in order to continue
the reconfiguration."
         voladm_help_push inst.shut.help
         voladm_yorn -M vxvmshm:306 "Shutdown and reboot now" n
	if [ $? -ne 0 ]
	then
        	ewritemsg -M vxvmshm:257 \
"Please shutdown before you perform any additional Volume Manager
or disk reconfiguration.  To shutdown your system cd to / and type
	 
        	shutdown -g0 -y -i6"
        	echo ""
        	quit 0
	else
		cd /
		doit shutdown -g0 -y -i6
		quit 0
	fi
fi

if [ $ret = 0 ] ; then
	doit /etc/init.d/vxvm-reconfig now
	echo ""
	 ewritemsg -M vxvmshm:391 \
"The system now must be shut down and rebooted in order to continue
the reconfiguration."
         voladm_help_push inst.shut.help
         voladm_yorn -M vxvmshm:306 "Shutdown and reboot now" n
	if [ $? -ne 0 ]
	then
        	ewritemsg -M vxvmshm:257 \
"Please shutdown before you perform any additional Volume Manager
or disk reconfiguration.  To shutdown your system cd to / and type
	 
        	shutdown -g0 -y -i6"
        	echo ""
        	quit 0
	else
		cd /
		doit shutdown -g0 -y -i6
		quit 0
	fi
fi
quit $ret
