#!/bin/sh

if [ $# = 0 ]
then
 if [ -f kb_bells.ko ]
 then
  echo "cleaning up old modules"
  rm kb_bells.ko
  rm kb_bells.o
  rm kb_bells.mod.c
  rm kb_bells.mod.o
  rm Module.symvers
  rm /opt/kb/kb_bells.ko
 fi
 make modules
else
 echo "skipping compilation"
fi
if [ -f kb_bells.ko ]
then
 if ! [ -d /opt/kb ]
 then
  echo "making directory /opt/kb"
  mkdir /opt/kb
  echo "editing /etc/init.d/boot.local"
  echo "mknod /dev/kb_bells c 42 0" >> /etc/init.d/boot.local
  echo "chmod 666 /dev/kb_bells" >> /etc/init.d/boot.local
  echo "insmod /opt/kb/kb_bells.ko" >> /etc/init.d/boot.local
 fi
 echo "copying kb_bells.ko to /opt/kb/kb_bells.ko"
 if cp kb_bells.ko /opt/kb/kb_bells.ko
 then
  echo "setting permissions on /opt/kb/kb_bells.ko"
  if chmod 755 /opt/kb/kb_bells.ko
  then
   echo "reboot for changes to take effect"
  fi
 fi
else
 echo "kb_bells.ko not found!"
fi

exit 0
