#!/bin/bash
#
# modules Remove the kernel loadable modules if called with any argument 
#

RETVAL=0
RC=0

# See how we were called.
  
. /etc/rc.d/init.d/functions
. /etc/rc.d/init.d/init_functions
. /etc/profile.d/SetNNEnvVar.sh

sanityLog()
{
    /nn/bin/AddNnuDiagLog "$@"
    if [ $? -ne 0 ];then
        echo `date` $0 sanity script failed to log message using AddNnuDiagLog "$@" >> /var/log/StartupSequence.log
    fi
}

start() {
        stop
        return 0 
}

stop() {

	# LED Treatment - identify via LEDs that shutdown is in progress
	sanityLog -mShutdownSequence -lStartupSequence.log -wR -sI -v11503 "Graceful Shutdown in progress. Power LED = solid green; Status LED = flash yellow"

	# Check for the existence of the reset_request UBoot environment variable.
	# If it does not exist, create it with the value of mainos.
	/nn/bin/fw_printenv reset_request | grep "reset_request="
	if [ $? -ne 0 ]; then
	    /nn/bin/fw_setenv reset_request mainos
	fi

	# Notify the sanity module that system shutdown should be complete within 180s
	# The system will reset if the shutdown takes longer than this.
#	echo "Notifying the HW sanity module that a shutdown sequence has started."
#	echo 180 > /proc/nn/sanity

        return 0 
}        

restart() {
        stop
}        

reload() {
        restart
}        

case "$1" in
  start)
          start
        ;;
  stop)
          stop
        ;;
  restart)
          restart
        ;;
  reload)
          reload
        ;;
  condrestart)
          [ -f /var/lock/subsys/$prog ] && restart || :
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|condrestart}"
        exit 1
esac

exit $?
