Skip to content

Commit

Permalink
Remove IP Routing from script to set up discovery server on the user …
Browse files Browse the repository at this point in the history
…computer, no longer needed due to the republisher, includes file/service cleanup
  • Loading branch information
hilary-luo committed Apr 16, 2024
1 parent 553c9e8 commit 86364e8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
59 changes: 44 additions & 15 deletions turtlebot4_discovery/configure_discovery.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
#!/bin/bash

read -p "RPi4 IP address: " ip
prompt_YESno() {
# as the user a Y/n question
# $1 is the variable into which the answer is saved as either "n" or "y"
# $2 is the question to ask

local __resultvar=$1
local __prompt=$2

echo -e "\e[39m$__prompt\e[0m"
echo "Y/n: "

if [[ $AUTO_YES == 1 ]];
then
echo "Automatically answering Yes"
eval $__resultvar="y"
else
read answer
if [[ $answer =~ ^[n,N].* ]];
then
eval $__resultvar="n"
else
eval $__resultvar="y"
fi
fi
}

read -p "Discovery Server IP [$ip]: " discovery_ip
discovery_ip=${discovery_ip:-$ip}
Expand All @@ -22,29 +46,18 @@ done
discovery_str="${discovery_str}${discovery_ip}:${discovery_port}"

echo "Configuring:"
echo " ip route add 192.168.186.0/24 via $ip";
echo " ROS_DISCOVERY_SERVER=$discovery_str"
echo " ROS_DOMAIN_ID=$domain_id"

# Delete existing route if applicable
if [ -f "/usr/local/sbin/ip_route.sh" ]; then
ip_add=$(grep -o 'ip [^"]*' /usr/local/sbin/ip_route.sh)
ip_del=$(echo $ip_add | sed "s/add/del/g")
echo $(sudo $ip_del)
fi

# Make directory to hold configs
sudo mkdir -p /etc/turtlebot4_discovery/

# Clone turtlebot4_setup and install files
git clone -b humble https://github.com/turtlebot/turtlebot4_setup.git /tmp/turtlebot4_setup/ &> /dev/null
sudo mv /tmp/turtlebot4_setup/turtlebot4_discovery/ip_route.sh /usr/local/sbin/
sudo mv /tmp/turtlebot4_setup/turtlebot4_discovery/ip_route.service /etc/systemd/system/
sudo mv /tmp/turtlebot4_setup/turtlebot4_discovery/setup.bash /etc/turtlebot4_discovery/
rm /tmp/turtlebot4_setup/ -rf

# Modify IP address
sudo sed -i "s/10.42.0.1/$ip/g" /usr/local/sbin/ip_route.sh
sudo sed -i "s/10.42.0.1:11811/$discovery_str/g" /etc/turtlebot4_discovery/setup.bash
sudo sed -i "s/ROS_DOMAIN_ID=0/ROS_DOMAIN_ID=$domain_id/g" /etc/turtlebot4_discovery/setup.bash

Expand All @@ -54,8 +67,24 @@ then
echo 'source /etc/turtlebot4_discovery/setup.bash' >> ~/.bashrc
fi

# Enable and start IP route service
sudo systemctl enable ip_route.service
sudo systemctl restart ip_route.service
if [ -f "/usr/local/sbin/ip_route.sh" ]||[ -f "/etc/systemd/system/ip_route.service" ];
then
prompt_YESno cleanup "\Would you like to clean up the outdated IP route? This is no longer required as of turtlebot4_robot version 1.0.3.\e[0m"
if [[ $cleanup == "y" ]];
then
# Delete existing route if applicable
if [ -f "/usr/local/sbin/ip_route.sh" ];
then
sudo rm /usr/local/sbin/ip_route.sh
fi
if [ -f "/etc/systemd/system/ip_route.service" ];
then
# Enable and start IP route service
sudo systemctl stop ip_route.service
sudo systemctl disable ip_route.service
sudo rm /etc/systemd/system/ip_route.service
fi
fi
fi

echo "Source your ~/.bashrc file to apply changes"
12 changes: 0 additions & 12 deletions turtlebot4_discovery/ip_route.service

This file was deleted.

2 changes: 0 additions & 2 deletions turtlebot4_discovery/ip_route.sh

This file was deleted.

0 comments on commit 86364e8

Please sign in to comment.