#!/bin/sh

PWD="$(pwd)"
WHEREAMI="$(dirname "$0")"
WHEREAMI="$(cd "$WHEREAMI" && pwd)"

OS="`uname`"
ARCH=$(uname -m)

case $ARCH in 
  x86_64)
    ARCH="x64"
    ;;
  aarch64)
    ARCH="arm64"
    ;;
  *)
   echo "Unsupported Architecture: $ARCH"
   exit 1
   ;;
esac

case $OS in
  'Linux')
    if [ -f "$WHEREAMI"/linux/manager-linux-$ARCH ]; then
      exec "$WHEREAMI"/linux/manager-linux-$ARCH "$@"
    else
      exec "$WHEREAMI"/linux/manager-linux "$@"
    fi
    ;;
  'FreeBSD')
    echo "FreeBSD is not supported"
    ;;
  'WindowsNT')
    echo "Windows is not supported"
    ;;
  'Darwin')
    exec "$WHEREAMI"/macos/manager-macos "$@"
    ;;
  *)
    echo "Your OS: $OS is not supported"
    ;;
esac
