#!/bin/bash

# setup CI environment locally

set -e
usage() {
    echo "Usage: "
    echo "  -h  Dispaly this help message"
    echo "  -s  [ nav | perc ] options (required)"
    exit 1
}

while getopts ":hs:" opt; do
    case ${opt} in
        h )
            usage
            ;;
        s )
            SERVICE=$OPTARG
            ;;
        \? )
            echo "Invalid option: $OPTARG" 1>&2
            usage
            ;;
        : )
            echo "Invalid option: $OPTARG requires an argument" 1>&2
            usage
            ;;
    esac
done

mkdir -p  /home/scotty/colcon_ws/src/third_party
case ${SERVICE} in
    nav )
        THIRD_PARTY_DIR=/home/scotty/nav-third-party.yml
        ln -s /home/scotty/prj/pkgs/nav /home/scotty/colcon_ws/src/nav
        ;;
    perc )
        THIRD_PARTY_DIR=/home/scotty/perc-third-party.yml
        ln -s /home/scotty/prj/pkgs/perc /home/scotty/colcon_ws/src/perc

        ;;
    * )
        echo "Options: [ nav | perc ]"
        usage
        ;;
esac

source /opt/ros/$ROS_DISTRO/setup.bash
ln -s /home/scotty/prj/pkgs/common /home/scotty/colcon_ws/src/common
cd /home/scotty/colcon_ws
/home/scotty/prj/ci/clone-third-party.py --input $THIRD_PARTY_DIR --path src/third_party
rosdep install -y --ignore-src --rosdistro $ROS_DISTRO --from-paths src --skip-keys="GTSAM Eigen PCL OpenCV"
