#!/bin/bash
# file: load_device
# loads module, creates device in /dev
# User specifies PCI vendor ID, PCI device ID, device_name
# example: load_device 1307 1d pci-das6402

arg_str=`awk -f find_device vendor=$1 device=$2 /proc/bus/pci/devices`

# just a test
echo "load_device: trying: modprobe $3 $arg_str ..."

modprobe $3 $arg_str

# add your own device loading here
# FIXME: add dynamic minor number support
if [ "$3" = "pci-das6402" ] ; then
    our_major=`cat /proc/devices | awk '$2=="pci-das6402" {print $1}'`
    if [ -n "$our_major" ]
    then
        /bin/echo "load_device: Success, $3 major number $our_major" #>>/tmp/load_device.txt
        /bin/rm -f /dev/$3*
        /bin/mknod /dev/$3 c $our_major 0
        if [ -e /dev/pci-das6402 ]; then
            echo "load_device: created /dev/$3"
        else
            echo "load_device: failed to create /dev/$3"
        fi
    else
        /bin/echo "load_device: couldn't find device major for $3"
    fi
    #/bin/rm -f /dev/$3*
    #/bin/mknod /dev/$3 c $our_major 0
#elif [ "$3" = "test" ] ; then
#    our_major=`cat /proc/devices | awk '$2=="test" {print $1}'`
#    /bin/echo "found $3 major number $our_major" #>>/tmp/load_device.txt
#    /bin/rm -f /dev/$3*
#    /bin/mknod /dev/$3 c $our_major 0
fi
