#!/bin/sh
#
# realcap	Load the realtime capabilities kernel module
#               by Fernando Lopez-Lezcano
#
# chkconfig: 2345 87 14
# description:	Loads and unloads the realcap kernel module
#
# config: /etc/sysconfig/realcap
#         define REALCAP_OPTS to desired options

# Source function library.
. /etc/init.d/functions

REALCAP_CONFIG=/etc/sysconfig/realcap

/sbin/modinfo realcap &>/dev/null
if [ "$?" != "0" ] ; then
    echo -n $"the realcap kernel modules does not exist."; warning; echo
    exit 0
fi

# Load realcap configuration
[ -f "$REALCAP_CONFIG" ] && . "$REALCAP_CONFIG"

start() {
    # default to allcaps=1
    if [ -z "$REALCAP_OPTS" ] ; then
	REALCAP_OPTS="allcaps=1"
    fi
    echo -n $"Loading realcap module (${REALCAP_OPTS}): "
    ret=0
    /sbin/modprobe realcap ${REALCAP_OPTS} &>/dev/null
    ret=$?
    [ $ret -eq 0 ] && success || failure
    echo
    touch /var/lock/subsys/realcap
    return $ret
}

stop() {
    echo -n $"Unloading realcap modules: "
    ret=0
    /sbin/rmmod realcap &>/dev/null
    ret=$?;
    [ $ret -eq 0 ] && success || failure
    echo
    rm -f /var/lock/subsys/realcap
    return $ret
}

case "$1" in
    start)
	start
	RETVAL=$?
	;;
    stop)
	stop
	RETVAL=$?
	;;
    restart)
	stop
	start
	RETVAL=$?
	;;
    *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
	;;
esac

exit $RETVAL
