#!/bin/bash
AVAILABLE=" plane copter rover sub"
VEHICLE="$1"

if [ -z "${VEHICLE}" ]; then
  echo "Usage: ardupilot-enable <vehicle>"
  echo "Available vehicles: ${AVAILABLE}"
  exit 1
fi

if ! echo "${AVAILABLE}" | grep -qw "${VEHICLE}"; then
  echo "Error: '${VEHICLE}' is not available. Choose from:${AVAILABLE}"
  exit 1
fi

for V in ${AVAILABLE}; do
  if [ "${V}" != "${VEHICLE}" ]; then
    sudo systemctl disable --now "ardu${V}" 2>/dev/null || true
  fi
done

sudo systemctl enable --now "ardu${VEHICLE}"
echo "ArduPilot ${VEHICLE} enabled and started."
