#!/sbin/sh -
# $Id: vxinstall.sh,v 1.33.45.9 2002/08/07 12:48:15 kirubak Exp $
#ident "$Source: /project/unixvm-cvs/src/sol/cmd/vxvm/voladm/Attic/vxinstall.sh,v $"

# 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


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

bail()
{
	exit 2
}

# Terminate the "show progress" twirling cursor
kill_show_prog()
{
        prog_pid=`ps -ef | fgrep inst.show_prog | fgrep $$  | awk '{ print $2 }'`
        if [ "X$prog_pid" != "X" ]
        then
                kill -ABRT $prog_pid
        fi
}

# Function to check for emc license VXSYM_LIC.
check_emc_lic()
{
	[ -x $LICCHK ] && $LICCHK -f VXSYM_LIC 
	if [ $? -eq 0 -a -s /usr/lib/libarray.so ]
	then
		strings /usr/lib/libarray.so | grep \
			"EMC foundation suite" >/dev/null 2>&1
		return $?
	fi
	return 1
}

VOLADM_CURRENT_MENU=
export VOLADM_CURRENT_MENU

# Make sure the localized messages are not turned off in subsequent Shell Scripts (e.g. vxvm-reconfig)
L10N_CMD=0
export L10N_CMD

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

# create the files vxvm.exclude and vxdmp.exclude in /etc/vx
create_exclude_files

#
# 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 2>/dev/null | awk '{ print $3 }'`
LICCHK=/usr/lib/vxvm/bin/vxliccheck
A5KCHK=/usr/lib/vxvm/bin/vxa5kchk
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)
$A5KCHK 2>/dev/null
if [ "$?" -eq 1 ]
then
        photon_array=yes
fi

if [ "$storage_array" = "yes" -o "$photon_array" = "yes" ]
then
	SUNArray=yes
fi

# check to see if a VM Beta license is required, and if so, if a valid VM
# BETA license is installed already
beta_pkg=1
beta_chk=
beta_lic_exists=0
if [ -x $LICCHK ]
then
	beta_chk=`$LICCHK -b 2>&1`
	echo $beta_chk | grep "VERITAS VxVM BETA license package" > /dev/null
	beta_pkg=$?	# if 0, then this is VM BETA licensed package
fi
if [ "$beta_pkg" -eq 0 ]
then
	# if this is a VM BETA package, then check to see of a VM valid
	# BETA license is installed
	$LICCHK -f 79
	[ $? -eq 0 ] && beta_lic_exists=1
fi

# if this is a VM BETA package, and if no valid VM BETA license is installed
# then prompt the user now to enter a VM BETA license
if [ "$beta_pkg" -eq 0 -a "$beta_lic_exists" -eq 0 ]
then
	ewritemsg -M vxvmshm:1383 "\
VxVM uses license keys to control access.  This VM package requires you to
  enter a valid VM BETA license to operate."

	def=y
	ask="`egettxt \"Are you prepared to enter a VM BETA license key\" vxvmshm:1333`"
	while true
	do
		voladm_yorn "$ask" $def || {
			[ "X$def" = Xy ] && {
				ewritemsg -M vxvmshm:1271 "Cannot continue installation."
				exit 1
			}
			break
		}
		vxlicense -c || continue
		ask="`egettxt \"Do you wish to enter another license key\" vxvmshm:1315`"
		def=n
	done
	echo
fi
if [ "$beta_pkg" -eq 0 -a "$beta_lic_exists" -eq 1 ]
then
	ewritemsg -M vxvmshm:1382 "\
VxVM uses license keys to control access.  A VM BETA license is found
  on this system."
	def=n
	ask="`egettxt \"Do you wish to enter another license key\" vxvmshm:1315`"
	voladm_yorn -M vxvmshm:1280 \
"Some licenses are already installed.  Do you wish to review them" \
		y && vxlicense -p
	while true
	do
		voladm_yorn "$ask" $def || {
			[ "X$def" = Xy ] && {
				ewritemsg -M vxvmshm:1271 "Cannot continue installation."
				exit 1
			}
			break
		}
		vxlicense -c || continue
		ask="`egettxt \"Do you wish to enter another license key\" vxvmshm:1315`"
		def=n
	done
	echo
fi

if [ "$beta_pkg" -ne 0 -a  -x "$vxlicense" -a -s "$vxlicense" -a \
		"$SUNArray" != "yes" ]
then
	HOSTID=`hostid`
	PLATFORM=`uname -i`

	if [ "$PLATFORM" = "i86pc" ]
	then
		ewritemsg -M vxvmshm:1275 "\
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 -M vxvmshm:1276 "\
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="`egettxt \"Are you prepared to enter a license key\" vxvmshm:1310`"

	export HOSTID PLATFORM; ewritemsg -M vxvmshm:1273 "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="`egettxt \"Do you wish to enter another license key\" vxvmshm:1315`"
		voladm_yorn -M vxvmshm:1280 \
"Some licenses are already installed.  Do you wish to review them" y && vxlicense -p
	else
		ewritemsg -M vxvmshm:1274 "No valid licenses found."
	fi	

	while true
	do
		voladm_yorn "$ask" $def || {
			[ "X$def" = Xy ] && {
				ewritemsg -M vxvmshm:1271 "Cannot continue installation."
				exit 1
			}
			break
		}
		vxlicense -c || continue
		ask="`egettxt \"Do you wish to enter another license key\" vxvmshm:1315`"
		def=n
	done

	# check that basic functionality feature is enabled
	[ -x $LICCHK ] && $LICCHK -f 90
	if [ $? -ne 0 ]
	then
		ewritemsg -M vxvmshm:1274 "No valid licenses found."
		ewritemsg -M vxvmshm:1271 "Cannot continue installation."
		exit 1
	fi	
	echo 

	#Running RPC daemon host_infod and vxnetd,
	#so that users don't need to run them explicitly.
	#No harm :
	#(i) If SRVM license has not been installed, or
	#(ii)If host_infod is already running,
	# vxnm-host_infod script takes care of both the
	# problems.

	/usr/sbin/vxstart_vvr > /dev/null

fi

# Download the exclude list into DMP. This has to be done here also because
# the VxVM startup scripts are not executed if the install-db file exists
vxdmpadm doioctl 2>/dev/null

voladm_menu_push VolumeManager
voladm_menu_push Install
voladm_help_push yorn.help
voladm_begin_screen -M vxvmshm:488 "Volume Manager Installation"
ewritemsg -M vxvmshm:1406 \
"VxVM will use the following format to name disks on the host:

  	<enclosurename>_<diskno>

  In the above format, <enclosurename> is the logical name of the enclosure
  to which the disk belongs. VxVM assigns default enclosure names which can
  be changed according to the user requirements.

  Some examples would be:

	hitachi0_2	- second disk detected in enclosure 'hitachi0'
	enggdept_2      - second disk detected in enclosure 'enggdept'
	dgc1_1       	- first disk detected in enclosure 'dgc1'
	jbod_1          - first disk detected in the jbod category

  For non-public loop disks (Ex. FC disks directly connected to the host
  or through hubs), you could choose to use the c#t#d#s# naming format."

rm -f $NEWNAMES_FILE
ask="`egettxt \"Do you want to use enclosure based names for all disks ?\" vxvmshm:1341`"
voladm_yorn "$ask" n && {
	touch $NEWNAMES_FILE
}

inst.show_prog&
trap 'kill_show_prog' INT TERM QUIT EXIT

#
# Start vxconfigd for vxdmpadm getsubpaths to work.
# 
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
			kill_show_prog
	 		ewritemsg -M vxvmshm:879  \
			"vold can not be enabled, quitting"
			quit 10
		fi
	elif [ $ret != 0 ]
	then
		kill_show_prog
		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
		kill_show_prog
		ewritemsg -M vxvmshm:879 \
		"vold can not be enabled, quitting"
		quit 10
	fi
fi

kill_show_prog

doit "$VOLADM_BIN/inst.top" $v_opt
ret=$?

if [ -f $excltmpfile1 -o -f $excltmpfile2 ]
then
	rm -f $excltmpfile1
	rm -f $excltmpfile2
	ewritemsg -M vxvmshm:1171 \
"If you have excluded any devices, the system must be shut down and rebooted
  for the device exclusion to take effect. After the system reboots you can
  run vxinstall and continue installation."
	exit 0
fi

if [ -f $excltmpfile3 ]
then
	rm -f $excltmpfile3
	exit 0
fi

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
	check_emc_lic
	if [ $? -eq 0 ]
	then
		doit /etc/init.d/vxvm-reconfig now vxtf_flag
	else
		doit /etc/init.d/vxvm-reconfig now
	fi

	if [ $? = 1 ]
	then
		quit 1
	fi

	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
