# --------------------------------------------------------------
# Update the .bashrc file so that newly opened terminals will be
# configured correctly to work with a turtlebot.
# --------------------------------------------------------------
if grep --quiet foxy ~/.bashrc; then
    printf ".bashrc already configured.\n"
else
    printf "Configuring .bashrc\n"
    printf "\n" >> ~/.bashrc
    echo "source /opt/ros/foxy/setup.bash" >> ~/.bashrc
    echo "export ROS_DOMAIN_ID=30" >> ~/.bashrc
    echo "export TURTLEBOT3_MODEL=\"waffle_pi\"" >> ~/.bashrc
    echo "export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:\"/opt/ros/foxy/share/turtlebot3_gazebo/models/\"" >> ~/.bashrc
    echo "export RCUTILS_LOGGING_BUFFERED_STREAM=1" >> ~/.bashrc
    printf "\n" >> ~/.bashrc

    echo "if [ -e $HOME/dev_ws/install/setup.bash ]" >> ~/.bashrc
    echo "then" >> ~/.bashrc
    echo "  source $HOME/dev_ws/install/setup.bash" >> ~/.bashrc
    echo "fi" >> ~/.bashrc
fi

# --------------------------------------------------------------
# Source .bashrc so that *this* shell will be configured.
# --------------------------------------------------------------

source ~/.bashrc

# --------------------------------------------------------------
# Create and configure a ros2 workspace, if necessary.
# --------------------------------------------------------------

WORKSPACE_SRC=$HOME"/dev_ws/src/"

if [ ! -d $WORKSPACE_SRC ]; then
    printf "\nCreating ros2 workspace.\n"
    echo $WORKSPACE_SRC
    mkdir -p $WORKSPACE_SRC
else
    printf "\n ROS2 workspace already created.\n"
fi
