#!/bin/bash
#
# phiondeferred This shell script takes care of dumping the post kernel-ring 
# bootlog into a phion conformant log file. 
#
# chkconfig: 2 98 6
# description: phiondeferred converts activity logs pertaining to a system \
#              bootstrap to phion format

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


# Source networking configuration.
. /etc/sysconfig/network


PMODPATH="/opt/phion/modules/box/boxsys"
[ -f ${PMODPATH}/moddefs.conf ] && source ${PMODPATH}/moddefs.conf  
MYLOGFLE="${logfile_phiondeferred:-"box_System_boot"}"

if [ -f /etc/phion/functions ]; then
        . /etc/phion/functions   
        logerror="LogError $MYLOGFLE"
else
	exit 1
fi

# Check that networking is up.


# See how we were called.
case "$1" in
  start)
        echo  -n "Creating CloudGen Firewall log records: "
	if [ -s /var/log/bootphion.log ]; then
        	$logerror "Info" "init(): ------- START ------------------------"
        	cat /var/log/bootphion.log |grep -v "phionrc" |{
        	while read line; do
                	set -f
			set -- $line
			ODATE="$1 $2 $3"
			shift 4
                	$logerror "Info" "$* [${ODATE}]"
        	done
        	} #  < /var/log/bootphion.log
        	set +f
		echo -n > /var/log/bootphion.log	
		killall -HUP syslogd
	fi 
	echo_success
	echo

	[ -s /opt/phion/preserve/swupdate.op ] && source /opt/phion/preserve/swupdate.op

	RELCHECK=${box_RELCHECK:-y}
	

	[ -x /epb/phionRelCheck -a ${RELCHECK} = y ] && {
		echo -n "Triggering release consistency check: "
        	$logerror "Info" "init(): check of release consistency started"
		/epb/phionRelCheck &>/dev/null &
		echo_success
		echo
		
	}
        $logerror "Info" "init(): -------- END -------------------------"
		touch /var/lock/subsys/phiondeferred
		/opt/phion/bin/bootstatusled.sh endboot
        ;;
  stop)
        echo  -n "Clearing ground for next boot sequence:"
#	if [ -s /var/log/bootphion.log ]; then
#		cat /var/log/bootphion.log >> /var/log/bootphion.log.1
#		echo -n  > /var/log/bootphion.log
#		killall -HUP syslogd
#	fi
	echo_success
	/opt/phion/bin/bootstatusled.sh startshutdown
	echo
	;;	
  *)
        echo "Usage: phiondeferred {start}"
        exit 1
esac

exit 0
