#!/bin/sh
MethodName=$1
if [ $# -eq 2  ]; then
/usr/bin/ICTApplication/ICTCliGateLite --call LoggerModule:defence --args $1 $2

else if [ $# -eq 1  ]; then
	case $1 in --help) 
	echo " _______________________________________________________________________________ "
	echo "|                                                                               |"
	echo "|                                                                               |"
	echo "|  OBJECT : defence command is made to access to the defence flash              |"
	echo "|           sector in read or delete access mode                                |"
	echo "|                                                                               |"
	echo "|  ======================================                                       |"
	echo "|  |    defence with one parameter      |                                       |"
	echo "|  ======================================                                       |"
	echo "|                                                                               |"
	echo "| ==> COMMAND :defence --help                                                   |"
	echo "|                                                                               |"
	echo "|  Print the help on the terminal                                               |"
	echo "|                                                                               |"
	echo "| ==> COMMAND :defence delete                                                   |"
	echo "|                                                                               |"
	echo "|  Delete both defence.* and Defence.* log files in /log flash sector           |"
	echo "|                                                                               |"
	echo "| ==> COMMAND :defence size                                                     |"
	echo "|                                                                               |"
	echo "|  Return the number of log messages in /log/Defence.log file                   |"
	echo "|                                                                               |"
	echo "|  ======================================                                       |"
	echo "|  |    defence with two parameters     |                                       |"
	echo "|  ======================================                                       |"
	echo "|                                                                               |"
    echo "|  COMMAND :defence <number> <access type>                                      |"
	echo "|                                                                               |"
	echo "|  <number>: number of lignes to read or delete from the end of                 |"
	echo "|            the defence log file                                               |"
	echo "|  <access type>    :                                                           |"
	echo "|  - command read   :  print the last <number> lines from the defence log file  |"
	echo "|  - command delete : delete the last <number> lines from the defence log file  |" 
	echo "|                                                                               |"
	echo "|  Example :                                                                    |"
	echo "|  defence 100 read   -->  print the last 100 lignes from /log/defence.log file |"
	echo "|  defence 100 delete --> delete the last 100 lignes from /log/defence.log file |"
	echo "|                                                                               |"
	echo "|                   ------------ End of Help ----------------                   |"
	echo "|                                                                               |"
	echo "|_______________________________________________________________________________|"
	;;

	
	delete) 
	cd /log/
	find -name Defence.* -name Defence.*.*  > /dev/null 2>&1
	echo "Delete Defence.*  files in /log directory"
	
	rm Defence.*    > /dev/null 2>&1    
	rm Defence.*.*  > /dev/null 2>&1
	
	echo "Create an empty Defence.log file"
	touch Defence.log
	
	echo "Preview Defence file deleted : DATE=`date +%e-%m-%y`" > /log/Defence.log
	
	echo "restart Syslog-ng deamon"
	/bin/kill -HUP `cat /var/run/syslog-ng.pid 2> /dev/null` 2> /dev/null || true
	;;
	
	size)
	/usr/bin/ICTApplication/ICTCliGateLite --call LoggerModule:defence --args 0 size
	;;
	
	 *)
	echo "invalid parameter"
	;;

	esac
	else echo "invalid parameters"
	fi
fi

