#!/bin/sh

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

# arg_summary is the summary on the command line except for the "-w|--wait" option
arg_summary="\"<message>\""
# arg_help is the help displayed at the end of the help.
arg_help="<message>	the message we want to display."

#
# 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"
###########################
WAIT=0
RET=0
msg=""

[[ $# -eq 0 ]] && RET=1 && set -- -h

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

: "Check the arguments"
#######################
[ "${msg-__none}" == "__none" ] && echoerror "No message to display !!!" && RET=1 && exit $RET

: "Presending"
##############
# As we does not wait for the exit we overwite it here
WAIT=0

: "Send command"
################
send "$WAIT" "${tmpfile:-}" event string:init_message string:"string:$msg"
RET=$?

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

exit $RET
