#!/bin/sh
# NOTE : This command must be sh
# bash is not available in the container
# So this script must stick to just sh syntax

if [ "$#" -ne 2 ]
then
  echo
  echo "****************************************"
  echo "Usage :: $0  --profile <profile-name>"
  echo "****************************************"
  exit 1
fi

while [ "$#" -gt 0 ]
do

  case $1 in
  --profile)
            profile="$2"
            echo
            echo "--------------------------------------------------------------------------------"
            echo "Setting profile to = ${profile}"
            echo "--------------------------------------------------------------------------------"
            echo
            shift
            ;;

  *)
            echo
            echo "****************************************"
            echo "Unknown parameter passed: $1"
            echo "****************************************"
            exit 1
            ;;
  esac

  shift

done

case $profile in
    local-mem) spring_profile=$profile;;
    local-docker) spring_profile=$profile;;
    marvel-dev) spring_profile=$profile;;
    marvel-test) spring_profile=$profile;;
    *)
        echo
        echo "****************************************"
        echo "Unknown profile : $profile"
        echo "****************************************"
        exit 1
        ;;
esac


echo
echo "--------------------------------------------------------------------------------"
echo "Running Marvel 2 REST API with spring profile = ${spring_profile}"
echo "--------------------------------------------------------------------------------"
echo

/usr/bin/java -jar -Dserver.port=80 /opt/zoox/marvel.jar --spring.profiles.active=${spring_profile}


