#!/bin/sh

# chkconfig: 35 90 10
# description: TSM JBB kernel module
#
### BEGIN INIT INFO
# Provides:       filepath
# Required-Start: $local_fs
# Required-Stop:  $local_fs
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Short-Description: TSM JBB kernel module
### END INIT INFO

module="filepath"
device=$module
homedir="/opt/"$module
group="sys"
mode="664"

case "$1" in
   'start')
      cd $homedir >> /dev/null 2>&1
      rmmod $module >> /dev/null 2>&1
      /sbin/insmod $module".ko" jbbMaxBuffer=256 jbbAllowWaitIfFull=0 || exit 1
      cd - >> /dev/null 2>&1
      major=`cat /proc/devices | awk "\\$2==\"$device\" {print \\$1}"`

      # Remove stale nodes and replace them, then give gid and perms
      rm -f /dev/${device}0 /dev/${device}
      mknod /dev/${device}0 c $major 0
      ln -sf ${device}0 /dev/${device}
      chgrp $group /dev/${device}0 
      chmod $mode  /dev/${device}0

      exit 0
   ;;

   'stop')
      rmmod $module >> /dev/null 2>&1
   ;;

   *)
      echo "usage: $0 {start|stop}"
   ;;
esac
