#!/bin/ksh
#
# ident	"@(#)vlan_check_ccr.sh	1.2	05/03/04 SMI"
#
# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# Determines if Tagged VLAN (802.1Q) is being used on cluster interconnects.
# Returns 0 if no Tagged vlan; 1 otherwise.
#
# Used by pre-backout script during patch removal to decide if the removal
# can proceed.

PATH=/usr/bin:/usr/sbin

# Check if an alternate root has been provided as an argument.
# If so, use the paths relative to the alternate root, else
# use the paths as they are.
if [[ -n $1 ]]; then
	CCRDIR=$1/etc/cluster/ccr
	SCINSTALL=$1/usr/cluster/bin/scinstall
	export TEXTDOMAINDIR=$1/usr/cluster/lib/locale
else
	CCRDIR=/etc/cluster/ccr
	SCINSTALL=/usr/cluster/bin/scinstall
	export TEXTDOMAINDIR=/usr/cluster/lib/locale
fi

INFRASTRUCTURE=$CCRDIR/infrastructure

VLAN_ID_NAME="vlan_id"

# I18N
export TEXTDOMAIN=SUNW_SC_CMD
export LC_COLLATE=C

#
# Versions where feature is not supported
#
bad_versions="3.1 3.1u1 3.1u2 3.1u3"

version=`$SCINSTALL -p | cut -f1 -d'_'`

echo "$bad_versions" | grep -w $version >/dev/null
if [ $? != 0 ]; then
	#
	# Downgrading to a version that Tagged VLAN is supported,
	# i.e. 3.1u4 or later. Backout can proceed.
	#
	exit 0
fi

[ ! -f $INFRASTRUCTURE ] && exit 0

#
# Look for the vlan_id property. It does not exist if tagged vlan is not
# configured. Or if it's set to 0, its effect is the same as not having
# configured it and should be allowed.
#
grep "properties.${VLAN_ID_NAME}	" $INFRASTRUCTURE |
while read line; do
	set -- $line
	if [ "$2" != 0 ]; then
		found_vlan_id=true
	fi
done

if [[ "$found_vlan_id" == "" ]]; then
	exit 0
else
	printf "$(gettext '\
The transport adapter(s) are configured to use tagged VLANs. You must\
unconfigure these adapters and configure dedicated transport adapters before\
proceeding with the patch removal.\
')\n"
	echo
	exit 1
fi
