#!/bin/bash
### BEGIN INIT INFO
# Provides:          pesnet
# Required-Start:    $syslog $time
# Required-Stop:     $syslog $time
# Should-Start:      
# Default-Start:     2
# Default-Stop:
# Short-Description: Start pesnet driver.
# Description:       Start pesnet driver.
### END INIT INFO

PATH=/lib/init:/sbin:/bin:/usr/bin
. /lib/lsb/init-functions

module="pesnet"
device="pesnet"
mode="664"
# invoke insmod with all arguments we got
# and use a pathname, as newer modutils don't look in . by default
/sbin/insmod /root/pesnet.ko || exit 1
# remove stale nodes
rm -f /dev/${device}[0-3]
major=$(awk '$2 == "pesnet" {print $1}' /proc/devices)
#major=`awk '$$2 == "$(mymodule)" {print $$1}' /proc/devices` 
echo $major

#mknod /dev/${device}0 c $major 0

mkdir /dev/pesnet0
for i in $(seq 1 1 31)
do
   mknod /dev/pesnet0/pesnet_aut$((i-1)) c $major $i
done

mknod /dev/pesnet0/pesnet_list c $major 0

#mknod /dev/${device}1 c $major 1
#mknod /dev/${device}2 c $major 2
#mknod /dev/${device}3 c $major 3

# give appropriate group/permissions, and change the group.
# Not all distributions have staff, some have "wheel" instead.
group="staff"
grep -q '^staff:' /etc/group || group="wheel"
chgrp $group /dev/${device}[0-3]
chmod $mode /dev/${device}[0-3]
sleep 10
echo OK
sleep 5
