#!/bin/bash

# Check that DiaLogger has started correctly and that previous indicators have been set
# and then set the LED status.

. /etc/init.d/functions
. /etc/rc.d/init.d/init_functions
. /etc/profile.d/SetNNEnvVar.sh

/sbin/pidof DiaLogger 
RC1=$?

# make sure that the network interfaces are up
inetaddr="inet addr"
eth0Status=`/sbin/ifconfig eth0 | grep "$inetaddr"`
eth1Status=`/sbin/ifconfig eth1 | grep "$inetaddr"`
loStatus=`/sbin/ifconfig lo | grep "$inetaddr"`

ifConfigured=0
if [ "$eth0Status" != "" ] && [ "$eth1Status" != "" ] &&
    [ "$loStatus" != "" ]; then
    ifConfigured=1
fi

# make sure that /etc/hosts file is configured properly
hostsConfigured=0
if [ -s /etc/hosts ]; then
    hostnameRC=`hostname`
    hostnameiRC=`hostname -i`
    hostnamedRC=`hostname -d`

    if [ "$hostnameRC" != "" ] && [ "$hostnameiRC" != "" ] && [ "$hostnamedRC" != "" ]; then
        hostsConfigured=1
    fi
fi

if [ $RC1 -eq 0 ] && [ -f /var/run/DiaLogger.ini ] &&
    [ $ifConfigured -eq 1 ] && [ $hostsConfigured -eq 1 ]; then
    touch /var/run/hc_sanity2
    
    if  [ -f /var/run/hc_sanity1 ];then
        /nn/bin/AddNnuDiagLog -mStartupSequence -lStartupSequence.log -wR -sI -v10906 "System Startup - DiaLogger managing LEDs"
    else
        /nn/bin/AddNnuDiagLog -mStartupSequence -lStartupSequence.log -wR -sI -v10932 "hc_sanity2 passed - previous condition failed"
    fi
else
    /nn/bin/AddNnuDiagLog -mStartupSequence -lStartupSequence.log -wR -sI -v10933 "hc_sanity2 failed"
fi

exit 0
