#!/bin/sh
#
# Changelog:
#	- Wed June 09 2010 - Michal SCHOTT <michael.schott@alcatel-lucent.com>
#	* Script creation 

#
# CONFIG VARIABLES
##################
HELPERPATH=/usr/lib/send_infra

# arg_summary is the summary on the command line except for the "-w|--wait" option
#
# FUNCTION DEFINITION
#####################
source $HELPERPATH/.functions

############
### MAIN ###
############
: "Overwrite configuration varibles"
####################################
# sendAndWait will send a message and check the existence of the file each $sleeptime and at most for $timeout microseconds

# timeout in seconds
#timeout=5

# sleeptime in microseconds
#sleeptime=1000000

: "PROCESSING COMMAND LINE"
###########################
RET=0
while [ $# -ne 0 ]; do
    case "$1" in 
        -h|--help) : "help"
            help
            exit $RET
        ;;
        -w|--wait) : "will wait"
            WAIT=1
        ;;
      	*) : "none"
            
            shift $#
        ;;
    esac
    shift
done


: "Send command"
################
cmd_res=`dbus-send --print-reply --dest=com.alcatel.ICTouch.SettingsManagerService /SettingsManager com.alcatel.ICTouch.ICTInterface.reboot 2>/dev/null`
callret=$?
if [ $callret -eq 1 ]; then
	echo "ERROR : Failed to call SettingsManager reboot" >&2
	RET=2
else
	res=`echo $cmd_res|sed 's/^.* boolean //'`
	if [ $res == "true" ]; then
#		echo "Reboot in progress"
		RET=1
	else
		RET=0
	fi
fi


: "Post sending"
################

exit $RET
