#! /bin/sh
### BEGIN INIT INFO
# Provides:          rppl-nip
# Required-Start:    $network
# Required-Stop:
# Default-Start:     2
# Default-Stop:
# Short-Description: NIP Update and Startup Utility
### END INIT INFO
. /lib/lsb/init-functions

verify_rppl_drivers()
{
    if [ -z "`lsmod | grep nipc`" ]; then
        log_warning_msg "NIP drivers not loaded, cannot start NIP framework"
        exit 1;
    fi
}

verify_nipexec_not_running()
{
    if [ -n "`ps -A | grep nipexec`" ]; then
        log_warning_msg "NIP framework already running"
        exit 1;
    fi
}

verify_nipexec_exists()
{
    if [ ! -x /usr/rppl/nipexec ]; then
        log_warning_msg "NIP framework startup not configured"
        exit 1;
    fi
}

case "$1" in
    start)
        verify_rppl_drivers
        verify_nipexec_not_running
        verify_nipexec_exists
        log_begin_msg "Starting NIP framework..."
            /usr/rppl/nipexec > /dev/tty8 &
        log_end_msg 0
        exit 0
        ;;
    stop)
        log_begin_msg "Stopping NIP framework..."
            pkill nipexec
        log_end_msg 0
        exit 0
        ;;
    *)
        echo "Usage: $0 {start|stop}"
        exit 1
	;;
esac

