OpenSolaris_b135/pkgdefs/common_files/i.ibnexconf

#!/bin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"%Z%%M%	%I%	%E% SMI"

PATH=/usr/bin:$PATH

#
# The IB Nexus driver (ib(7d)), requires the following lines :
#       name="ib" class="root";
# in /kernel/drv/ib.conf file.
#
# This script adds the required line and relevant comments,
# if the lines are not already present in the ib.conf file.
#

#
# Search for the line containing
#	name="ib" class="root";
# in ib.conf file. This returns 0 on a successful search.
#
search_ibconf()
{
	TGT_IBCONFFILE=$1

	grep "$IB_SEARCH_STRING" $TGT_IBCONFFILE  > /dev/null 2>&1
	search_result=$?
	return $search_result
}

#
# Update ib.conf just adds the line containing :
#	name="ib" class="root";
#    and the adjoining comments in target ib.conf file.
#
update_ibconf()
{
	TGT_IBCONFFILE=$2

	echo $IB_STR1 >> $TGT_IBCONFFILE
	echo $IB_STR2 >> $TGT_IBCONFFILE
	echo $IB_STR3 >> $TGT_IBCONFFILE
}

#
# Search Pattern and additional lines for ib.conf
#
IB_STR1="# The name and class property are required to indicate that IB nexus"
IB_STR2="# driver is a child of the root nexus driver. DO NOT DELETE LINE BELOW"
IB_STR3="name=\"ib\" class=\"root\";"
IB_SEARCH_STRING="^[ 	]*name=\"ib\"[ 	]*class=\"root\"[ 	]*;"

while read src dest; do
	if [ -f $dest ]; then
		#
		# 1. Search the $dest file for relevant line 
		# 2. If search fails, add the required lines to $dest
		#
		search_ibconf $dest
		if [ "$?" -ne 0 ]; then
			update_ibconf $src $dest
		fi

	else
		#
		# If no ib.conf file is present on the target system,
		# just copy over the one from the package.
		#
		cp -p $src $dest
	fi
done
exit 0