Blame scripts/ibcheckportwidth.in

Packit db064d
#!/bin/sh
Packit db064d
Packit db064d
IBPATH=${IBPATH:-@IBSCRIPTPATH@}
Packit db064d
Packit db064d
usage() {
Packit db064d
	echo Usage: `basename $0` "[-h] [-v] [-N | -nocolor] [-G]" \
Packit db064d
	   "[-C ca_name] [-P ca_port] [-t(imeout) timeout_ms] <lid|guid> <port>"
Packit db064d
	exit -1
Packit db064d
}
Packit db064d
Packit db064d
green() {
Packit db064d
	if [ "$bw" = "yes" ]; then
Packit db064d
		if [ "$verbose" = "yes" ]; then
Packit db064d
			echo $1
Packit db064d
		fi
Packit db064d
		return
Packit db064d
	fi
Packit db064d
	if [ "$verbose" = "yes" ]; then
Packit db064d
		echo -e "\\033[1;032m" $1 "\\033[0;39m"
Packit db064d
	fi
Packit db064d
}
Packit db064d
Packit db064d
red() {
Packit db064d
	if [ "$bw" = "yes" ]; then
Packit db064d
		echo $1
Packit db064d
		return
Packit db064d
	fi
Packit db064d
	echo -e "\\033[1;031m" $1 "\\033[0;39m"
Packit db064d
}
Packit db064d
Packit db064d
guid_addr=""
Packit db064d
bw=""
Packit db064d
verbose=""
Packit db064d
ca_info=""
Packit db064d
suppress_deprecated="no"
Packit db064d
Packit db064d
while [ "$1" ]; do
Packit db064d
	case $1 in
Packit db064d
	-G)
Packit db064d
		guid_addr=yes
Packit db064d
		;;
Packit db064d
	-nocolor|-N)
Packit db064d
		bw=yes
Packit db064d
		;;
Packit db064d
	-v)
Packit db064d
		verbose=yes
Packit db064d
		;;
Packit db064d
	-S)
Packit db064d
		suppress_deprecated="yes"
Packit db064d
		;;
Packit db064d
	-P | -C | -t | -timeout)
Packit db064d
		case $2 in
Packit db064d
		-*)
Packit db064d
			usage
Packit db064d
			;;
Packit db064d
		esac
Packit db064d
		if [ x$2 = x ] ; then
Packit db064d
			usage
Packit db064d
		fi
Packit db064d
		ca_info="$ca_info $1 $2"
Packit db064d
		shift
Packit db064d
		;;
Packit db064d
	-*)
Packit db064d
		usage
Packit db064d
		;;
Packit db064d
	*)
Packit db064d
		break
Packit db064d
		;;
Packit db064d
	esac
Packit db064d
	shift
Packit db064d
done
Packit db064d
Packit db064d
if [ $# -lt 2 ]; then
Packit db064d
	usage
Packit db064d
fi
Packit db064d
Packit db064d
portnum=$2
Packit db064d
Packit db064d
if [ "$suppress_deprecated" = "no" ]; then
Packit db064d
echo "*** WARNING ***: this command is deprecated\n\n" 1>&2
Packit db064d
fi
Packit db064d
Packit db064d
if [ "$guid_addr" ]; then
Packit db064d
	if ! lid=`$IBPATH/ibaddr $ca_info -G -L $1 | awk '/failed/{exit -1} {print $3}'`; then
Packit db064d
		echo -n "guid $1 address resolution: "
Packit db064d
		red "FAILED"
Packit db064d
		exit -1
Packit db064d
	fi
Packit db064d
	guid=$1
Packit db064d
else
Packit db064d
	lid=$1
Packit db064d
	if ! temp=`$IBPATH/ibaddr $ca_info -L $1 | awk '/failed/{exit -1} {print $1}'`; then
Packit db064d
		echo -n "lid $1 address resolution: "
Packit db064d
		red "FAILED"
Packit db064d
		exit -1
Packit db064d
	fi
Packit db064d
fi
Packit db064d
Packit db064d
Packit db064d
text="`eval $IBPATH/smpquery $ca_info portinfo $lid $portnum`"
Packit db064d
rv=$?
Packit db064d
if echo "$text" | awk -v mono=$bw -F '[.:]*' '
Packit db064d
function blue(s)
Packit db064d
{
Packit db064d
	if (mono)
Packit db064d
		printf s
Packit db064d
	else if (!quiet) {
Packit db064d
		printf "\033[1;034m" s
Packit db064d
		printf "\033[0;39m"
Packit db064d
	}
Packit db064d
}
Packit db064d
Packit db064d
# Only check LinkWidthActive if LinkWidthSupported is not 1X
Packit db064d
/^LinkWidthSupported/{ if ($2 == "1X") { exit } }
Packit db064d
/^LinkWidthActive/{ if ($2 == "1X") warn = warn "#warn: Link configured as 1X  lid '$lid' port '$portnum'\n"}
Packit db064d
Packit db064d
/^ib/	{print $0; next}
Packit db064d
/ibpanic:/	{print $0}
Packit db064d
/ibwarn:/	{print $0}
Packit db064d
/iberror:/	{print $0}
Packit db064d
Packit db064d
END {
Packit db064d
	if (err != "") {
Packit db064d
		blue(err)
Packit db064d
		exit -1
Packit db064d
	}
Packit db064d
	if (warn != "") {
Packit db064d
		blue(warn)
Packit db064d
		exit -1
Packit db064d
	}
Packit db064d
	exit 0
Packit db064d
}' 2>&1 && test $rv -eq 0 ; then
Packit db064d
	if [ "$verbose" = "yes" ]; then
Packit db064d
		echo -n "Port check lid $lid port $portnum: "
Packit db064d
		green "OK"
Packit db064d
	fi
Packit db064d
	exit 0
Packit db064d
else
Packit db064d
	echo -n "Port check lid $lid port $portnum: "
Packit db064d
	red "FAILED"
Packit db064d
	exit -1
Packit db064d
fi