#!/bin/bash

date > /usr/share/sv2/sv2-createnodes.log

if [ -f /usr/sbin/lspci ]; then
	count=$(/usr/sbin/lspci -n | grep 102b:0550 | wc -l)
elif [ -f /sbin/lspci ]; then
        count=$(/sbin/lspci -n | grep 102b:0550 | wc -l)
else
	which lspci
	if [ ! $? -eq 0 ]; then
	    echo error:: cannot find lspci. >> /usr/share/sv2/sv2-createnodes.log
	fi
	count=$(lspci -n | grep 102b:0550 | wc -l)
fi

major=$(awk '$2=="sv2" {print $1}' /proc/devices)
if [[ $major ]]; then
	echo create nodes...
	echo major == $major >> /usr/share/sv2/sv2-createnodes.log
	echo count == $count >> /usr/share/sv2/sv2-createnodes.log

	for (( i=0; i < count; i++ ))
	do
		if [ -e /dev/sv2$i ]; then
			rm /dev/sv2$i
		fi

                mknod -m 666 /dev/sv2$i c $major $i

	done

	# unload driver if there is no hardware
	if [ ! -c /dev/sv20 ]; then
		rmmod sv2
	fi
fi
