#!/bin/sh
PROCESSOR=Hager-ARMv7

# dirname could be missing, so prevent changing dir to $HOME
MBSA_DIR=`dirname $0 2>/dev/null`

[ -n "$MBSA_DIR" ] && cd $MBSA_DIR

# setup LD_LIBRARY_PATH
if [ -z "$PROCESSOR" ]; then PROCESSOR=i386; fi
export LD_LIBRARY_PATH="../lib/runtimes/linux/$PROCESSOR:../lib/runtimes/linux/$PROCESSOR/plugins:$LD_LIBRARY_PATH"

# export MBSA_LOG_DISABLED=1
export LOG_ENABLED="true"
[ "$MBSA_LOG_DISABLED" = "1" ] && export LOG_ENABLED="false" 

echo "Stopping mBSA [`pwd`/../lib/runtimes/linux/$PROCESSOR/mbsae.core $@]..."

# uncomment for synchronous/asynchronous stop command
STOPCMD=stopsync
#STOPCMD=stop

# uncomment and modify the following line if mbs needs more than 60s for stopping
#export MBSA_STOP_TIMEOUT=60

../lib/runtimes/linux/$PROCESSOR/mbsae.core mbsa.cmd=$STOPCMD mbsa.log.file=./logs/mbsa_stop.log core.log.enable=$LOG_ENABLED $*
rc=$?
echo "mBSA exit code: $rc"
exit $rc

##########
# code 0   - mbsa stopped successfuly
# code 1   - mbsa stop failed (e.g. configuration issues)
# code 2   - mbsa already stopped (synch was unavailable upon script startup)
# code 3   - mbsa synch stop timeouted (consider increasing MBSA_STOP_TIMEOUT env. variable)
# code 100 - mbsa is stopping (retry until exit code=2 or exit code=1)
