# Use these string replacements for deploying TIAGO Gazebo packages originally designed 
# for Ubuntu 18/ROS Melodic in a Ubuntu 20/ROS Noetic environment

echo "--- TIAGo Gazebo Noetic Upgrade ---"
echo "Run this script in the root folder of your TIAGo Gazebo workspace."
echo "Slightly adjusting some values in your TIAGo Gazeboo environment folder..."

# At this moment, I have no idea where this package originated, and its only some internal test dependency...
# Thus, we will just disable it everywhere.
NEW_NAME="<\!--test_depend>urdf_test<\/test_depend-->"
OLD_NAME="<test_depend>urdf_test<\/test_depend>"
grep -rl $OLD_NAME src | xargs -r sed -i 's/'$OLD_NAME'/'$NEW_NAME'/g' 
#echo "$OLD_NAME --> $NEW_NAME"

# See http://wiki.ros.org/noetic/Migration for the next two
OLD_NAME="<build_depend>orocos_kdl<\/build_depend>"
NEW_NAME="<build_depend>liborocos-kdl<\/build_depend>\n<build_depend>liborocos-kdl-dev<\/build_depend>"
grep -rl $OLD_NAME src | xargs -r sed -i 's/'$OLD_NAME'/'$NEW_NAME'/g'
#echo "$OLD_NAME --> $NEW_NAME"

OLD_NAME="<run_depend>orocos_kdl<\/run_depend>"
NEW_NAME="<run_depend>liborocos-kdl<\/run_depend>\n<run_depend>liborocos-kdl-dev<\/run_depend>"
grep -rl $OLD_NAME src | xargs -r sed -i 's/'$OLD_NAME'/'$NEW_NAME'/g'
#echo "$OLD_NAME --> $NEW_NAME"

# I think this executable's name has had changed way before noetic... Doesn't matter, just extend it.
OLD_NAME="type=\"state_publisher"
NEW_NAME="type=\"robot_state_publisher"
grep -rl $OLD_NAME src | xargs -r sed -i 's/'$OLD_NAME'/'$NEW_NAME'/g'
#echo "$OLD_NAME --> $NEW_NAME"

echo "Finished string replacements!"
echo "---"
