#!/bin/sh

if [ "$1" = "-b" ]; then
  {{ EXEM_HOME }}/manager/script/binary_start.sh

else
  if [ "$OS_NAME" = "SunOS" ]; then
    ID=`/usr/xpg4/bin/id -u`
  else
    ID=`id -u`
  fi

  if [ "$ID" -eq 0 ]; then
    {{ EXEM_HOME }}/manager/script/service_start.sh
    if [ "$?" != 0 ]; then
      {{ EXEM_HOME }}/manager/script/binary_start.sh
    fi
  else
    echo "No root privileges. Starting without registering service."

    {{ EXEM_HOME }}/manager/script/binary_start.sh
  fi
fi

if [ "$?" = 0 ]; then
  echo "xmSuccess(0): exem-manager-agent is started"
else
  echo "xmError(1): Failed to start exem-manager-agent"
fi