# This script creates the backout package for a patch package
#
# directory format options.
#
# @(#) postinstall 1.13 01/01/12 SMI
#
# Copyright (c) 1995 by Sun Microsystems, Inc.
# All rights reserved
#

# Description:
#       Set the TYPE parameter for the remote file
#
# Parameters:
#       none
#
# Globals set:
#	TYPE

set_TYPE_parameter () {
	if [ ${PATCH_UNDO_ARCHIVE:?????} = "/dev" ]; then
		# handle device specific stuff
		TYPE="removable"
	else
		TYPE="filesystem"
	fi
}

#
# Description:
#       Build the remote file that points to the backout data
#
# Parameters:
#       $1:	the un/compressed undo archive
#
# Globals set:
#	UNDO, STATE

build_remote_file () {
	remote_path=$PKGSAV/$SUNW_PATCHID/remote
	set_TYPE_parameter
	STATE="active"

	if [ $1 = "undo" ]; then
		UNDO="undo"
	else
		UNDO="undo.Z"
	fi

	cat > $remote_path << EOF
# Backout data stored remotely
TYPE=$TYPE
FIND_AT=$ARCHIVE_DIR/$UNDO
STATE=$STATE
EOF
}

PATH=/usr/sadm/bin:$PATH

if [ "$PKG_INSTALL_ROOT" = "/" ]; then
	PKG_INSTALL_ROOT=""
fi

if [ -n "$PATCH_BUILD_DIR" -a -d "$PATCH_BUILD_DIR" ]; then
	BUILD_DIR="$PATCH_BUILD_DIR/$SUNW_PATCHID.$PKGINST"
else
	BUILD_DIR="$PKG_INSTALL_ROOT/var/tmp/$SUNW_PATCHID.$PKGINST"
fi

if [ ! -n "$PATCH_UNDO_ARCHIVE" ]; then
	PATCH_UNDO_ARCHIVE="none"
fi

FILE_DIR=$BUILD_DIR/files
RELOC_DIR=$FILE_DIR/reloc
ROOT_DIR=$FILE_DIR/root
BO_Deletes=$FILE_DIR/deletes
THIS_DIR=`dirname $0`
PROTO_FILE=$BUILD_DIR/prototype
TEMP_REMOTE=$PKGSAV/$SUNW_PATCHID/temp

if [ "$PATCH_PROGRESSIVE" = "true" ]; then
        # remove the scripts that are left behind
        install_scripts=`dirname $0`
        rm $install_scripts/checkinstall $install_scripts/patch_checkinstall $install_scripts/patch_postinstall

	# If this is being used in an old-style patch, insert
	# the old-style script commands here.

	#XXXOld_CommandsXXX#

	exit 0
fi

#
# At this point we either have a deletes file or we don't. If we do,
# we create a prototype entry.
#
if [ -f $BO_Deletes ]; then
	echo "i deletes=$BO_Deletes" >> $BUILD_DIR/prototype
fi

#
# Now delete everything in the deletes list after transferring
# the file to the backout package and the entry to the prototype
# file. Remember that the pkgmap will get the CLIENT_BASEDIR path
# but we have to actually get at it using the BASEDIR path. Also
# remember that removef will import our PKG_INSTALL_ROOT
#
Our_Deletes=$THIS_DIR/deletes
if [ -f $Our_Deletes ]; then
	cd $BASEDIR

	cat $Our_Deletes | while read path; do
		Reg_File=0

		if valpath -l $path; then
			Client_Path="$CLIENT_BASEDIR/$path"
			Build_Path="$RELOC_DIR/$path"
			Proto_Path=$BASEDIR/$path
		else	# It's an absolute path
			Client_Path=$path
			Build_Path="$ROOT_DIR$path"
			Proto_Path=$PKG_INSTALL_ROOT$path
		fi

		# If BASEDIR/CLIENTBASEDIR = "/", then the previous prepends
		# an extra / i.e. //. The sed command later can't find a
		# Proto_Path with // and therefore will not substitute the
		# correct build_Path resulting in the backout pkg not being
		# created.

		if [ "$CLIENT_BASEDIR" = "/" ]; then
			Client_Path=`echo $Client_Path | sed 's|^\/\/|\/|'`
			Proto_Path=`echo $Proto_Path | sed 's|^\/\/|\/|'`
		fi
			
		# Note: If the file isn't really there, pkgproto
		# doesn't write anything but displays an error
		# so check for the file before processing.

		if [ -f "$Proto_Path" ]; then
			LINE=`pkgproto $Proto_Path=$path`
		else
			continue
		fi

		ftype=`echo $LINE | nawk '{ print $1 }'`
		if [ "$ftype" = "f" ]; then
			Reg_File=1
		fi

		if [ $Reg_File = 1 ]; then
			# Add source file to the prototype entry
			if [ "$Proto_Path" = "$path" ]; then
				LINE=`echo $LINE | sed -e "s|$Proto_Path|$Build_Path|2"`
			else
				LINE=`echo $LINE | sed -e "s|$Proto_Path|$Build_Path|"`
			fi

			DirName=`dirname $Build_Path`
			# make room in the build tree
			mkdir -p $DirName
			cp -p $Proto_Path $Build_Path
		fi

		# Insert it into the prototype file
		echo $LINE 1>>$PROTO_FILE 2>/dev/null

		# Remove the file only if it's OK'd by removef
		rm `removef $PKGINST $Client_Path` 1>/dev/null 2>&1
	done
	removef -f $PKGINST

	rm $Our_Deletes
fi

#
# Unless specifically denied, make the backout package.
#
if [ "$PATCH_NO_UNDO" != "true" ]; then
	cd $BUILD_DIR	# We have to build from here.

	if [ "$PATCH_UNDO_ARCHIVE" != "none" ]; then
		STAGE_DIR="$PATCH_UNDO_ARCHIVE"
		ARCHIVE_DIR="$PATCH_UNDO_ARCHIVE/$SUNW_PATCHID/$PKGINST"
		mkdir -p $ARCHIVE_DIR
		mkdir -p $PKGSAV/$SUNW_PATCHID
	else
		if [ -d $PKGSAV/$SUNW_PATCHID ]; then
			rm -r $PKGSAV/$SUNW_PATCHID
		fi
		STAGE_DIR=$PKGSAV
		ARCHIVE_DIR=$PKGSAV/$SUNW_PATCHID
		mkdir $ARCHIVE_DIR
	fi

	pkgmk -o -d $STAGE_DIR 1>/dev/null 2>&1
	pkgtrans -s $STAGE_DIR $ARCHIVE_DIR/undo $PKG 1>/dev/null 2>&1
	compress $ARCHIVE_DIR/undo
	retcode=$?
	if [ "$retcode" != 0 ]; then
		echo "compress(1) returned error code $retcode"
		echo "The $PKGINST backout package will not be compressed."
		echo "Continuing to process backout package."
	fi
	if [ "$PATCH_UNDO_ARCHIVE" != "none" ]; then
		if [ $retcode != 0 ]; then
			build_remote_file "undo"
		else
			build_remote_file "undo.Z"
		fi
	fi
	rm -r $STAGE_DIR/$PKG

	cd ..
	rm -r $BUILD_DIR
	# remove the scripts that are left behind
	install_scripts=`dirname $0`
	rm $install_scripts/checkinstall $install_scripts/patch_checkinstall $install_scripts/patch_postinstall
fi

#
# Since this apparently worked, we'll mark as obsoleted the prior
# versions of this patch - installpatch deals with explicit obsoletions.
#
cd ${PKG_INSTALL_ROOT:-/}
cd var/sadm/pkg

active_base=`echo $SUNW_PATCHID | nawk '
	{ print substr($0, 1, match($0, "-")-1) } '`

List=`ls -d $PKGINST/save/${active_base}* 2>/dev/null`
if [ $? -ne 0 ]; then
	List=""
fi

for savedir in $List; do
        patch=`basename $savedir` 
        if [ $patch = $SUNW_PATCHID ]; then
		break
	fi

        # If we get here then the previous patch gets deleted
	if [ -f $savedir/undo ]; then
		mv $savedir/undo $savedir/obsolete
		echo $SUNW_PATCHID >> $savedir/obsoleted_by
	elif [ -f $savedir/undo.Z ]; then
		mv $savedir/undo.Z $savedir/obsolete.Z
		echo $SUNW_PATCHID >> $savedir/obsoleted_by
        elif  [ -f $savedir/remote ]; then
                `grep . $PKGSAV/$patch/remote | sed 's|STATE=.*|STATE=obsolete|' > $TEMP_REMOTE` 
                rm -f $PKGSAV/$patch/remote 
                mv $TEMP_REMOTE $PKGSAV/$patch/remote  
                rm -f $TEMP_REMOTE 
                echo $SUNW_PATCHID >> $savedir/obsoleted_by
	elif  [ -f $savedir/obsolete -o -f $savedir/obsolete.Z ]; then
		echo $SUNW_PATCHID >> $savedir/obsoleted_by
	fi
done

# If additional operations are required for this package, place
# those package-specific commands here.

#XXXSpecial_CommandsXXX#

#
# script to run vxenablef in all releases of solaris.
# This command needs to be run to load the avalaible
# licensing info into VxFS kernel module.
# copy the script to /etc/init.d and make links from rc2.d
#

SCRIPT=VXFSLDLIC
VXLICTEST=/sbin/vxlictest

rm -f ${BASEDIR}/etc/init.d/${SCRIPT} ${BASEDIR}/etc/rc2.d/S01${SCRIPT}
/usr/sbin/install -s -f ${BASEDIR}/etc/init.d -m 744 -u root -g sys \
                ${INST_DATADIR}/VRTSvxfs/install/${SCRIPT}
ln ${BASEDIR}/etc/init.d/${SCRIPT} ${BASEDIR}/etc/rc2.d/S01${SCRIPT}

TMP=/tmp/devlink.tab.$$
ETC_SYSTEM=${BASEDIR}/etc/system
TMP_SYSTEM=${BASEDIR}/tmp/system.$$
AWK=/usr/bin/nawk
BC="/usr/bin/bc -l"
VXLICTEST=/sbin/vxlictest

check_basedir()
{
	if [ "${BASEDIR}" = "/" -o -z "${BASEDIR}" ]
	then
		echo 0
	else
		echo 1
	fi
}

if [ `check_basedir` -eq 1 ]
then
	add_drv -n -b ${BASEDIR} -m '* 0640 root sys' vxportal
	add_drv -n -b ${BASEDIR} fdd
	echo "IMPORTANT: because BASEDIR is set, you are probably doing"
	echo "an installation to a client. You must reboot the client"
	echo "system before using VxFS."
else
	add_drv -n vxportal
	rem_drv vxportal
	add_drv -n -m '* 0640 root sys' vxportal
	add_drv -n fdd
	rem_drv fdd
	add_drv -n fdd
fi

#
# Check that QuickLog is not already loaded or installed on the system.
# Then add QuickLog.
#
modinfo | grep qlog 2>&1 > /dev/null
if [ $? -eq 0 -a `check_basedir` -eq 0 ]
then
	modunload -i `modinfo | grep qlog | cut -f1,2 -d' '`
#	if [ $? -ne 0 ]
#	then
#		echo "The QuickLog kernel module 'qlog' could not be unloaded."
#		echo "You may proceed with the patchadd, but you may have to"
#		echo "reboot your system afterwards."
#		echo
#		echo "Do you want to proceed with addition of VRTSvxfs [y/n]?\c"
#		read ans
#		if [ "X" = "X$ans" ]
#		then
#			ans="n"
#		fi
#		if [ $ans = "N" -o $ans = "n" ]
#		then
#			exit 1
#		fi
#	fi
fi
if [ `check_basedir` -eq 1 ]
then
	add_drv -n -b ${BASEDIR} qlog > /dev/null 2>&1
else
	add_drv -n qlog
	rem_drv qlog
	add_drv -n qlog
fi

#
# Update /etc/devlink.tab
#
grep -v fdd $BASEDIR/etc/devlink.tab > $TMP
cat >> $TMP << EOT
type=ddi_pseudo;name=fdd	\D
EOT
mv -f $TMP $BASEDIR/etc/devlink.tab

$BASEDIR/usr/sbin/devlinks -r $BASEDIR > /dev/null 2>&1
if [ $? != 0 ]
then
	echo "Error creating device links; removing driver"
	if [ "$BASEDIR" = "" -o "$BASEDIR" = "/" ] ; then
		rem_drv fdd >/dev/null 2>&1
	else
		rem_drv -b $BASEDIR fdd >/dev/null 2>&1
	fi
	exit 1
fi

grep -v vxportal $BASEDIR/etc/devlink.tab > $TMP
cat >> $TMP << EOT
type=ddi_pseudo;name=vxportal	\D
EOT
mv -f $TMP $BASEDIR/etc/devlink.tab

$BASEDIR/usr/sbin/devlinks -r $BASEDIR > /dev/null 2>&1
if [ $? != 0 ]
then
	echo "Error creating device links; removing driver"
	if [ "$BASEDIR" = "" -o "$BASEDIR" = "/" ] ; then
		rem_drv vxportal >/dev/null 2>&1
	else
		rem_drv -b $BASEDIR vxportal >/dev/null 2>&1
	fi
	exit 1
fi

grep -v qlog ${BASEDIR}/etc/devlink.tab > ${BASEDIR}/etc/NEW1_devlink.tab
sed -e '$ a\
type=ddi_pseudo;name=qlog;minor=0,raw	qlog/admin\
type=ddi_pseudo;name=qlog;minor=1,raw	qlog/vxlog1\
type=ddi_pseudo;name=qlog;minor=2,raw	qlog/vxlog2\
type=ddi_pseudo;name=qlog;minor=3,raw	qlog/vxlog3\
type=ddi_pseudo;name=qlog;minor=4,raw	qlog/vxlog4\
type=ddi_pseudo;name=qlog;minor=5,raw	qlog/vxlog5\
type=ddi_pseudo;name=qlog;minor=6,raw	qlog/vxlog6\
type=ddi_pseudo;name=qlog;minor=7,raw	qlog/vxlog7\
type=ddi_pseudo;name=qlog;minor=8,raw	qlog/vxlog8\
type=ddi_pseudo;name=qlog;minor=9,raw	qlog/vxlog9\
type=ddi_pseudo;name=qlog;minor=10,raw	qlog/vxlog10\
type=ddi_pseudo;name=qlog;minor=11,raw	qlog/vxlog11\
type=ddi_pseudo;name=qlog;minor=12,raw	qlog/vxlog12\
type=ddi_pseudo;name=qlog;minor=13,raw	qlog/vxlog13\
type=ddi_pseudo;name=qlog;minor=14,raw	qlog/vxlog14\
type=ddi_pseudo;name=qlog;minor=15,raw	qlog/vxlog15\
type=ddi_pseudo;name=qlog;minor=16,raw	qlog/vxlog16\
type=ddi_pseudo;name=qlog;minor=17,raw	qlog/vxlog17\
type=ddi_pseudo;name=qlog;minor=18,raw	qlog/vxlog18\
type=ddi_pseudo;name=qlog;minor=19,raw	qlog/vxlog19\
type=ddi_pseudo;name=qlog;minor=20,raw	qlog/vxlog20\
type=ddi_pseudo;name=qlog;minor=21,raw	qlog/vxlog21\
type=ddi_pseudo;name=qlog;minor=22,raw	qlog/vxlog22\
type=ddi_pseudo;name=qlog;minor=23,raw	qlog/vxlog23\
type=ddi_pseudo;name=qlog;minor=24,raw	qlog/vxlog24\
type=ddi_pseudo;name=qlog;minor=25,raw	qlog/vxlog25\
type=ddi_pseudo;name=qlog;minor=26,raw	qlog/vxlog26\
type=ddi_pseudo;name=qlog;minor=27,raw	qlog/vxlog27\
type=ddi_pseudo;name=qlog;minor=28,raw	qlog/vxlog28\
type=ddi_pseudo;name=qlog;minor=29,raw	qlog/vxlog29\
type=ddi_pseudo;name=qlog;minor=30,raw	qlog/vxlog30\
type=ddi_pseudo;name=qlog;minor=31,raw	qlog/vxlog31\
type=ddi_pseudo;name=qlog;minor=32,raw	qlog/cvxlog1\
type=ddi_pseudo;name=qlog;minor=33,raw	qlog/cvxlog2\
type=ddi_pseudo;name=qlog;minor=34,raw	qlog/cvxlog3\
type=ddi_pseudo;name=qlog;minor=35,raw	qlog/cvxlog4\
type=ddi_pseudo;name=qlog;minor=36,raw	qlog/cvxlog5\
type=ddi_pseudo;name=qlog;minor=37,raw	qlog/cvxlog6\
type=ddi_pseudo;name=qlog;minor=38,raw	qlog/cvxlog7\
type=ddi_pseudo;name=qlog;minor=39,raw	qlog/cvxlog8\
type=ddi_pseudo;name=qlog;minor=40,raw	qlog/cvxlog9\
type=ddi_pseudo;name=qlog;minor=41,raw	qlog/cvxlog10\
type=ddi_pseudo;name=qlog;minor=42,raw	qlog/cvxlog11\
type=ddi_pseudo;name=qlog;minor=43,raw	qlog/cvxlog12\
type=ddi_pseudo;name=qlog;minor=44,raw	qlog/cvxlog13\
type=ddi_pseudo;name=qlog;minor=45,raw	qlog/cvxlog14\
type=ddi_pseudo;name=qlog;minor=46,raw	qlog/cvxlog15\
type=ddi_pseudo;name=qlog;minor=47,raw	qlog/cvxlog16\
type=ddi_pseudo;name=qlog;minor=48,raw	qlog/cvxlog17\
type=ddi_pseudo;name=qlog;minor=49,raw	qlog/cvxlog18\
type=ddi_pseudo;name=qlog;minor=50,raw	qlog/cvxlog19\
type=ddi_pseudo;name=qlog;minor=51,raw	qlog/cvxlog20\
type=ddi_pseudo;name=qlog;minor=52,raw	qlog/cvxlog21\
type=ddi_pseudo;name=qlog;minor=53,raw	qlog/cvxlog22\
type=ddi_pseudo;name=qlog;minor=54,raw	qlog/cvxlog23\
type=ddi_pseudo;name=qlog;minor=55,raw	qlog/cvxlog24\
type=ddi_pseudo;name=qlog;minor=56,raw	qlog/cvxlog25\
type=ddi_pseudo;name=qlog;minor=57,raw	qlog/cvxlog26\
type=ddi_pseudo;name=qlog;minor=58,raw	qlog/cvxlog27\
type=ddi_pseudo;name=qlog;minor=59,raw	qlog/cvxlog28\
type=ddi_pseudo;name=qlog;minor=60,raw	qlog/cvxlog29\
type=ddi_pseudo;name=qlog;minor=61,raw	qlog/cvxlog30\
type=ddi_pseudo;name=qlog;minor=62,raw	qlog/cvxlog31\
type=ddi_pseudo;name=qlog;minor=63,raw	qlog/cvxlog32\
type=ddi_pseudo;name=qlog;minor=64,raw	qlog/frlog' \
< ${BASEDIR}/etc/NEW1_devlink.tab > ${BASEDIR}/etc/NEW2_devlink.tab
mv ${BASEDIR}/etc/NEW2_devlink.tab ${BASEDIR}/etc/devlink.tab
rm ${BASEDIR}/etc/NEW1_devlink.tab

#
# Make qlog nodes in /dev/qlog
#
rm -fr ${BASEDIR}/dev/qlog >/dev/null 2>&1
mkdir ${BASEDIR}/dev/qlog >/dev/null 2>&1
QL_MAJOR=`grep qlog ${BASEDIR}/etc/name_to_major | awk '{print $2}'`
mknod ${BASEDIR}/dev/qlog/admin c $QL_MAJOR 0
mknod ${BASEDIR}/dev/qlog/vxlog1 c $QL_MAJOR 1
mknod ${BASEDIR}/dev/qlog/vxlog2 c $QL_MAJOR 2
mknod ${BASEDIR}/dev/qlog/vxlog3 c $QL_MAJOR 3
mknod ${BASEDIR}/dev/qlog/vxlog4 c $QL_MAJOR 4
mknod ${BASEDIR}/dev/qlog/vxlog5 c $QL_MAJOR 5
mknod ${BASEDIR}/dev/qlog/vxlog6 c $QL_MAJOR 6
mknod ${BASEDIR}/dev/qlog/vxlog7 c $QL_MAJOR 7
mknod ${BASEDIR}/dev/qlog/vxlog8 c $QL_MAJOR 8
mknod ${BASEDIR}/dev/qlog/vxlog9 c $QL_MAJOR 9
mknod ${BASEDIR}/dev/qlog/vxlog10 c $QL_MAJOR 10
mknod ${BASEDIR}/dev/qlog/vxlog11 c $QL_MAJOR 11
mknod ${BASEDIR}/dev/qlog/vxlog12 c $QL_MAJOR 12
mknod ${BASEDIR}/dev/qlog/vxlog13 c $QL_MAJOR 13
mknod ${BASEDIR}/dev/qlog/vxlog14 c $QL_MAJOR 14
mknod ${BASEDIR}/dev/qlog/vxlog15 c $QL_MAJOR 15
mknod ${BASEDIR}/dev/qlog/vxlog16 c $QL_MAJOR 16
mknod ${BASEDIR}/dev/qlog/vxlog17 c $QL_MAJOR 17
mknod ${BASEDIR}/dev/qlog/vxlog18 c $QL_MAJOR 18
mknod ${BASEDIR}/dev/qlog/vxlog19 c $QL_MAJOR 19
mknod ${BASEDIR}/dev/qlog/vxlog20 c $QL_MAJOR 20
mknod ${BASEDIR}/dev/qlog/vxlog21 c $QL_MAJOR 21
mknod ${BASEDIR}/dev/qlog/vxlog22 c $QL_MAJOR 22
mknod ${BASEDIR}/dev/qlog/vxlog23 c $QL_MAJOR 23
mknod ${BASEDIR}/dev/qlog/vxlog24 c $QL_MAJOR 24
mknod ${BASEDIR}/dev/qlog/vxlog25 c $QL_MAJOR 25
mknod ${BASEDIR}/dev/qlog/vxlog26 c $QL_MAJOR 26
mknod ${BASEDIR}/dev/qlog/vxlog27 c $QL_MAJOR 27
mknod ${BASEDIR}/dev/qlog/vxlog28 c $QL_MAJOR 28
mknod ${BASEDIR}/dev/qlog/vxlog29 c $QL_MAJOR 29
mknod ${BASEDIR}/dev/qlog/vxlog30 c $QL_MAJOR 30
mknod ${BASEDIR}/dev/qlog/vxlog31 c $QL_MAJOR 31
mknod ${BASEDIR}/dev/qlog/cvxlog1 c $QL_MAJOR 32
mknod ${BASEDIR}/dev/qlog/cvxlog2 c $QL_MAJOR 33
mknod ${BASEDIR}/dev/qlog/cvxlog3 c $QL_MAJOR 34
mknod ${BASEDIR}/dev/qlog/cvxlog4 c $QL_MAJOR 35
mknod ${BASEDIR}/dev/qlog/cvxlog5 c $QL_MAJOR 36
mknod ${BASEDIR}/dev/qlog/cvxlog6 c $QL_MAJOR 37
mknod ${BASEDIR}/dev/qlog/cvxlog7 c $QL_MAJOR 38
mknod ${BASEDIR}/dev/qlog/cvxlog8 c $QL_MAJOR 39
mknod ${BASEDIR}/dev/qlog/cvxlog9 c $QL_MAJOR 40
mknod ${BASEDIR}/dev/qlog/cvxlog10 c $QL_MAJOR 41
mknod ${BASEDIR}/dev/qlog/cvxlog11 c $QL_MAJOR 42
mknod ${BASEDIR}/dev/qlog/cvxlog12 c $QL_MAJOR 43
mknod ${BASEDIR}/dev/qlog/cvxlog13 c $QL_MAJOR 44
mknod ${BASEDIR}/dev/qlog/cvxlog14 c $QL_MAJOR 45
mknod ${BASEDIR}/dev/qlog/cvxlog15 c $QL_MAJOR 46
mknod ${BASEDIR}/dev/qlog/cvxlog16 c $QL_MAJOR 47
mknod ${BASEDIR}/dev/qlog/cvxlog17 c $QL_MAJOR 48
mknod ${BASEDIR}/dev/qlog/cvxlog18 c $QL_MAJOR 49
mknod ${BASEDIR}/dev/qlog/cvxlog19 c $QL_MAJOR 50
mknod ${BASEDIR}/dev/qlog/cvxlog20 c $QL_MAJOR 51
mknod ${BASEDIR}/dev/qlog/cvxlog21 c $QL_MAJOR 52
mknod ${BASEDIR}/dev/qlog/cvxlog22 c $QL_MAJOR 53
mknod ${BASEDIR}/dev/qlog/cvxlog23 c $QL_MAJOR 54
mknod ${BASEDIR}/dev/qlog/cvxlog24 c $QL_MAJOR 55
mknod ${BASEDIR}/dev/qlog/cvxlog25 c $QL_MAJOR 56
mknod ${BASEDIR}/dev/qlog/cvxlog26 c $QL_MAJOR 57
mknod ${BASEDIR}/dev/qlog/cvxlog27 c $QL_MAJOR 58
mknod ${BASEDIR}/dev/qlog/cvxlog28 c $QL_MAJOR 59
mknod ${BASEDIR}/dev/qlog/cvxlog29 c $QL_MAJOR 60
mknod ${BASEDIR}/dev/qlog/cvxlog30 c $QL_MAJOR 61
mknod ${BASEDIR}/dev/qlog/cvxlog31 c $QL_MAJOR 62
mknod ${BASEDIR}/dev/qlog/cvxlog32 c $QL_MAJOR 63
mknod ${BASEDIR}/dev/qlog/frlog c $QL_MAJOR 64

sync; sleep 1; sync; sleep 1; sync

#
# Recreate the man pages windex database
#
# this is commented out because it takes too long.
# catman -w > /dev/null 2>&1

# prints warning msg if no license pkg (VRTSvlic) is installed
warn_no_vlic_pkg()
{
	echo
	echo "WARNING:  Cannot determine license information."
	echo
	echo "    Make sure that the VERITAS license package (VRTSvlic)"
	echo "    is installed on your system."
	echo
	echo "    To view license information after installing the license"
	echo "    package, run the following command:"
	echo
	echo "    /sbin/vxlicrep"
	echo
}

# prints warning msg if no valid license key detected
warn_invalid_lic()
{
	warningMsg="${1}"
	echo
	echo "WARNING: ${warningMsg}"
	echo
	echo "    Refer to the VERITAS File System Installation Guide for"
	echo "    information on licensing."
	echo
	echo "    To install the license after obtaining the license key,"
	echo "    run the following command:"
	echo
	echo "    /sbin/vxlicinst"
	echo
}

# check_lic returns 1 if any of the feature in featerList
# is enabled in system; prints warning message and returns 0
# otherwise
check_lic()
{
	evalProg="${1}"
	featureList="${2}"
	warningMsg="${3}"

	while [ ! -z "${featureList}" ]
	do
		feature=`echo "${featureList}" | cut -d',' -f1`
		eval "${evalProg} ${feature}" > /dev/null 2>&1
		if [ $? = 0 ]
		then
			return 1
		fi
		featureList=`echo "${featureList}" | cut -d',' -f2-`
		if [ "${feature}" = "${featureList}" ]
		then
			featureList=""
		fi
	done

	warn_invalid_lic "${warningMsg}"
	return 0
}

if [ "yes" = "yes" -o "yes" = "beta" ]
then
	# featureList is a minimal requirement of features to run VxFS
	# features in featureList is deliminated by commas
	featureList=""

	warningMsg=""
	if [ -f ${VXLICTEST} ]
	then
		if [ "yes" = "beta" ]
		then
			featureList="FSBETA"
			warningMsg="You must install an FSBETA license before using VxFS."
		else
			featureList="VXFS,VXFS BASE"
			warningMsg="You must install a VXFS or VXFS BASE license key before using VxFS."
		fi
		check_lic "${VXLICTEST} -i 25 -f" "${featureList}" "${warningMsg}"
	else
		warn_no_vlic_pkg
	fi
fi

exit 0
