#!/bin/sh
# Kvaser CAN driver                     
# usbcanII - start/stop usbcan and create/delete inodes  
# Copyright (C) 2005 Kvaser AB - support@kvaser.com - www.kvaser.com  

#     
# test kernel version
#     
kernel_ver=`uname -r |awk -F . '{print $2}'` 

case $kernel_ver in
   "6") kv_module_install=modprobe
        ;;
   *)   kv_module_install=insmod
        ;;
esac

#
# 
#

#-------------------------------------------------------------------------------------------

# we are adding the usbcanII
if test $ACTION = 'add'
then
    /sbin/$kv_module_install usbcanII || exit 1
    nrchan=`cat /proc/usbcanII | grep 'total channels' | awk '{print $3}'`
    major=`cat /proc/devices | grep 'usbcanII' | awk '{print $1}'`
    rm -f /dev/usb/usbcanII*
    for (( minor=0 ; minor<$nrchan; minor++ )) ; do
        mknod /dev/usbcanII$minor c $major $minor
    done

    # the file $REMOVER vill be called by the HOTPLUG system on removal
    # so we have to write the uninstall script to it
    echo "/sbin/rmmod usbcanII || exit 1" > $REMOVER
    echo "rm -f /dev/usbcanII*" >> $REMOVER
    chmod +x $REMOVER
    #qqq this will only work with one device
fi

exit 0
