#!/bin/sh
#
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)i.ssdconf	1.2	09/04/15 SMI"
#

PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

add_self_identifying_entry() {
cat >> $dest <<EOF

#
# The following stub node is needed for pathological bottom-up
# devid resolution on a self-identifying transport. 
#
name="ssd" class="scsi-self-identifying";
EOF
}

while read src dest; do
	if [ ! -f $dest ]; then
		cp $src $dest
	else
		# Remove obsoleted drivers
		grep -v 'name="ssd" parent="SUNW,pln" port=' $dest > /tmp/d.$$
		grep -v 'name="ssd" parent="scsi_vhci" target=0;' /tmp/d.$$ > /tmp/d.$$
		mv /tmp/d.$$ $dest

		# Process conf files for missing entries
		while read confline; do
			if echo "$confline" | egrep "^[\t| ]*#|^[\t| ]*$" > /dev/null; then
				continue
			fi

			grep "$confline" $dest > /dev/null
			if [ $? -ne 0 ]; then
				echo $confline >> $dest
			fi
		done < $src
		echo `cat $dest` | grep "scsi-self-identifying" > /dev/null

		if [ $? -ne 0 ]; then
			add_self_identifying_entry
		fi
	fi
done

exit 0
