#!/bin/bash

# Stop immediately if a dependency cannot be installed.
set -e

FOXYFILE="/opt/ros/foxy/local_setup.bash"

if ! [ -f $FOXYFILE ]; then
	echo "you must install voxl-ros2-foxy first before you can use voxl-mpa-to-ros2"
	exit 1
fi

echo "Installing some apt dependencies"
apt install -y python3-pip python3-numpy libtinyxml2-6 nlohmann-json-dev

echo "making sure pip is installed and upgraded"
python3 -m pip install --timeout 60 --retries 5 --upgrade pip

echo "pip installing some dependencies"
# Foxy requires the EmPy 3 API; constrain it before resolving colcon dependencies.
python3 -m pip install --timeout 60 --retries 5 \
    colcon-common-extensions lark netifaces "empy==3.3.4"

echo "enabling voxl-microdds-agent"
systemctl enable --now voxl-microdds-agent

# run our bash profile script to we can get going right away.
# this will get run again next time the user opens a shell
echo "sourcing our bash profile"
source /home/root/.profile.d/source_foxy_setup.sh

echo ""
echo "done configuring voxl-mpa-to-ros2"

echo 'export ROS_HOME=/opt/ros/foxy' >> ~/.bashrc 
echo 'source /opt/ros/foxy/local_setup.bash' >> ~/.bashrc 
echo 'source /opt/ros/foxy/mpa_to_ros2/install/setup.bash' >> ~/.bashrc