#! /bin/sh
#
# This script loads and unloads the realtime kernel module
# Configuration can be put into /etc/default/realtime
#
# Author:	Guenter Geiger <geiger@debian.org>
#
#
# Version:	0.1
#

PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=realtime
DESC="Realtime Linux Security Module"

# Gracefully exit if the package has been removed.
if test ! -e "/lib/modules/`uname -r`/kernel/security/realtime.ko"
then
  echo Loading $DESC: not found
  exit 0
fi

# Read config file if it is present.
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# The module has to be enabled 
if test "$ENABLE" != "yes" 
then
   echo Loading $DESC: disabled
   exit 0
fi


CAPLOADED=`lsmod | grep capability`

set -e

case "$1" in
  start)
        if [ "$CAPLOADED" != "" ]
	then
	  echo Realtime Linux Security Module: Unloading capability LSM
	  rmmod capability
        fi
	echo -n "Loading $DESC: $NAME"
	modprobe $NAME $PARAMETERS
	echo "."
	;;
  stop)
	echo -n "Unloading $DESC: $NAME "
	modprobe -r $NAME
	echo "."
	;;
  restart|force-reload)
	echo -n "Restarting $DESC: $NAME"
	modprobe -r $NAME
	sleep 1
	modprobe $NAME $PARAMETERS
	echo "."
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
