#!/usr/bin/env bash

set -Eeuo pipefail

SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
ARCH=""
BINARY="dataplane"
CONFIG=""
TYPE=""

usage() {
  cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [OPTIONS]

YANET wrapper.

Options:
-h        Print this help and exit
-a        Instruction set architecture host (corei7, broadwell, knl)
-b        Set binary (dataplane, controlplane)
-c        Config file
-t        Type of yanet binary (release, l3balancer or firewall)
EOF
  exit
}

while getopts "h:a:b:c:t:" opt ; do
  case $opt in
    h) usage ;;
    a) ARCH=$OPTARG ;;
    b) BINARY=$OPTARG ;;
    c) CONFIG=$OPTARG ;;
    t) TYPE=$OPTARG ;;
    *) usage ;;
  esac
done

if [ "$BINARY" = "dataplane" ]; then
  /usr/bin/yanet-$BINARY-$ARCH-$TYPE -c $CONFIG
elif [ "$BINARY" = "controlplane" ]; then
  /usr/bin/yanet-$BINARY-$ARCH -c $CONFIG
else
  false
fi
