#!/usr/bin/env bash

#
# Copyright (C) Monterey Bay Aquarium Research Institute (MBARI)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#

errcho() { printf "%s\n" "$*" >&2; }
CMD_X_OPTION=""

if [ $# -ge 1 ]; then
  VEHICLE=$1
  if [ $# -ge 2 ]; then
      CMD_X_OPTION="-x '$2'"
  fi
else
  echo ""
  echo "A known vehicle name is required to run the LRAUV application:"
  echo ""
  echo "      usage example1: `basename $0` tethys"
  echo "      usage example2: `basename $0` tethys 'run Science/profile_station.xml'"
  echo ""
  exit
fi

if [ -d "lrauv/$VEHICLE" ]; then
	cd lrauv/$VEHICLE;
	CMD="./bin/LRAUV -c sim/gz/$VEHICLE $CMD_X_OPTION"
  echo $CMD;
  eval $CMD;
else
  echo ""
  errcho "ERROR: Failed to start LRAUV application instance for $VEHICLE. Location ./lrauv/$VEHICLE was not found."
  errcho "Aborting." && exit
fi
