#!/bin/bash
# Pull latest saltylab-firmware and rebuild ROS2 workspace
set -e
cd ~/saltylab-firmware
git fetch origin
LOCAL=$(git rev-parse main)
REMOTE=$(git rev-parse origin/main)
if [ "$LOCAL" = "$REMOTE" ]; then
    echo "Already up to date ($LOCAL)"
    exit 0
fi
echo "Pulling $(git rev-list --count main..origin/main) new commits..."
git checkout main
git pull origin main
cd jetson/ros2_ws
source /opt/ros/humble/setup.bash
colcon build --symlink-install --parallel-workers 4
echo "Build complete at $(date)"
