Skip to content

Instantly share code, notes, and snippets.

@mstaflex
Created February 25, 2014 14:22
Show Gist options
  • Save mstaflex/9209710 to your computer and use it in GitHub Desktop.
Save mstaflex/9209710 to your computer and use it in GitHub Desktop.
Script that distributes all the ROS files from the central control station to the TWISTbots
#!/bin/bash
stations="tbot_unit01 tbot_unit02 tbot_unit03 tbot_unit04 tbot_unit05"
excluds="distribute build msg_gen srv_gen log packs"
# Author Jasper Buesch
####################################################################################
############# DO NOT CHANGE BELOW THIS #############################################
####################################################################################
if [ "$1" == "-h" ]; then
echo ""
echo "This is a command line tool to distribute ROS (~/ros) code onto the tbot_units"
echo "Usage:"
echo " distribute [ all | <list of bot names> ]"
echo
exit
fi
if [ "$#" -ne 0 ]; then
if [ "$1" == "all" ]; then
stations=$stations
else
stations=$@
fi
fi
echo $stations
return=""
station=""
active_stations=""
running="False"
exclude_param=""
for i in $excluds
do
exclude_param="$exclude_param --exclude=$i"
done
echo ""
echo "Pinging for active stations..."
echo ""
check_if_station_is_there ()
{
result="$(ping -w 1 -c 1 $station | grep '1 received' | awk -F ' ' '{print $1}')"
if [ "$result" == "" ]; then
echo "$station not present"
return
elif [ $result -ne 1 ]; then
return
else
return='True'
fi
}
for i in $stations
do
station=$i
return='False'
check_if_station_is_there
if [ $return == 'True' ]; then
running="True"
echo "$station PRESENT!"
$(rsync -a -z $exclude_param /home/tbot/cps_ros/ $i:/home/tbot/ros/ ) &
fi
done
printf "\nSynching clients."
while [ "$running" != "" ]; do
sleep 1
printf "."
running="$(ps aux | grep rsync | grep ssh | awk -F ' ' '{print $12}')"
done
printf "\n"
echo "Synching to all clients finished!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment