From 86364e8e6390ad41848167d8553d95e9504bb0c5 Mon Sep 17 00:00:00 2001 From: Hilary Luo Date: Sun, 14 Apr 2024 22:55:36 -0400 Subject: [PATCH] Remove IP Routing from script to set up discovery server on the user computer, no longer needed due to the republisher, includes file/service cleanup --- turtlebot4_discovery/configure_discovery.sh | 59 +++++++++++++++------ turtlebot4_discovery/ip_route.service | 12 ----- turtlebot4_discovery/ip_route.sh | 2 - 3 files changed, 44 insertions(+), 29 deletions(-) delete mode 100644 turtlebot4_discovery/ip_route.service delete mode 100755 turtlebot4_discovery/ip_route.sh diff --git a/turtlebot4_discovery/configure_discovery.sh b/turtlebot4_discovery/configure_discovery.sh index 3685ae6..c306df4 100755 --- a/turtlebot4_discovery/configure_discovery.sh +++ b/turtlebot4_discovery/configure_discovery.sh @@ -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} @@ -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 @@ -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" diff --git a/turtlebot4_discovery/ip_route.service b/turtlebot4_discovery/ip_route.service deleted file mode 100644 index bc1f99e..0000000 --- a/turtlebot4_discovery/ip_route.service +++ /dev/null @@ -1,12 +0,0 @@ -Description=IP route service -After=network.target -StartLimitIntervalSec=0 - -[Service] -Type=simple -Restart=on-failure -RestartSec=5 -ExecStart=/bin/bash /usr/local/sbin/ip_route.sh - -[Install] -WantedBy=multi-user.target diff --git a/turtlebot4_discovery/ip_route.sh b/turtlebot4_discovery/ip_route.sh deleted file mode 100755 index c26bbad..0000000 --- a/turtlebot4_discovery/ip_route.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -ip route add 192.168.186.0/24 via 10.42.0.1 \ No newline at end of file