#! /bin/sh
### BEGIN INIT INFO
# Provides:             serverkillcommand
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:      6
# Short-Description: Msg the excite to reboot the ARM
# Description:
### END INIT INFO



do_stop () {
        # If slowBaud is not defined use our best guess.
        if [ -z "$slowBaud" ]
        then
                echo "Warning! slowBaud undefined."
                slowBaud=57600
        fi
        log_action_msg "Attempting message at $slowBaud"
        stty -F /dev/ttyS1 $slowBaud min 1 time 5 -ignbrk -brkint -icrnl \
                                        -imaxbel -opost -onlcr -isig  \
                                        -icanon -iexten -echo -echoe  \
                                        -echok -echoctl -echoke
        stty -F /dev/ttyS1
        cat /etc/init.d/reboot_arm.bin > /dev/ttyS1
        sleep 1
        # If turboBaud is not defined use our best guess.
        if [ -z "$turboBaud" ]
        then
                echo "Warning! turboBaud undefined."
                turboBaud=460800
        fi
        log_action_msg "Attempting message at $turboBaud"
        stty -F /dev/ttyS1 $turboBaud min 1 time 5 -ignbrk -brkint -icrnl \
                                        -imaxbel -opost -onlcr -isig  \
                                        -icanon -iexten -echo -echoe  \
                                        -echok -echoctl -echoke
        stty -F /dev/ttyS1
        cat /etc/init.d/reboot_arm.bin > /dev/ttyS1
        log_action_msg "Reboot command sent, rebooting."
}

case "$1" in
  start)
        # No-op
        ;;
  restart|reload|force-reload)
        echo "Error: argument '$1' not supported" >&2
        exit 3
        ;;
  stop)
        do_stop
        ;;
  *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac

