Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsk_tools/env-hooks/99.jsk_tools.sh] use ip for rossetip instead of ifconfig #1436

Merged
merged 2 commits into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions jsk_tools/env-hooks/99.jsk_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ rossetmaster() {
fi
echo -e "\e[1;31mset ROS_MASTER_URI to $ROS_MASTER_URI\e[m"
}

rossetrobot() {
echo -e "\e[1;31m *** rossetrobot is obsoleted, use rossetmaster ***\e[m"
rossetmaster $@
Expand All @@ -78,37 +79,29 @@ rossetlocal() {
}

rossetip_dev() {
local device=${1-"(eth0|eth1|eth2|eth3|eth4|wlan0|wlan1|wlan2|wlan3|wlan4|en0|en1|en2|en3|lo0)"}
if [ "$(uname -s)" = "Darwin" ]; then
export ROS_IP=`PATH=$PATH:/sbin LANGUAGE=en LANG=C ifconfig | egrep -A1 "${device}"| grep inet\ | grep -v 127.0.0.1 | sed 's/.*inet \([0-9\.]*\).*/\1/' | head -1`
else
export ROS_IP=`PATH=$PATH:/sbin LANGUAGE=en LANG=C ifconfig | egrep -A1 "${device}"| grep inet\ | grep -v 127.0.0.1 | sed 's/.*inet addr:\([0-9\.]*\).*/\1/' | head -1`
fi
local device=${1-'(eth|wlan|en|lo)[0-9]*'}
export ROS_IP=`LANG=C ip -o -4 a | grep -E "^[0-9]+: $device" | tail -n1 | sed -e 's@^.*inet *\([0-9\.]*\).*$@\1@g'`
export ROS_HOSTNAME=$ROS_IP
}

rossetip_addr() {
local target_host=${1-"133.11.216.211"}
##target_hostip=$(host ${target_host} | sed -n -e 's/.*address \(.*\)/\1/gp')
# Check if target_host looks like ip address or not
if [ "$(echo $target_host | sed -e 's/[0-9\.]//g')" != "" ]; then
target_hostip=$(timeout 0.001 getent hosts ${target_host} | cut -f 1 -d ' ')
fi
local mask_target_ip=$(echo ${target_hostip} | cut -d. -f1-3)
for ip in $(hostname -I); do
if echo $ip | egrep "^172.17.42.|^127.0." >/dev/null; then
# skip docker/local host
continue
elif echo $ip | grep "$mask_target_ip" >/dev/null; then
export ROS_IP=$ip
break
target_host_ip=$(timeout 0.01 getent hosts ${target_host} | cut -f 1 -d ' ')
if [ "$target_host_ip" = "" ]; then
echo -e "\e[1;31mCould not resolve ip from address. Subnet may be different\e[m"
rossetip_dev
return 0
fi
done
export ROS_HOSTNAME=$ROS_IP
target_host=$target_host_ip
fi
export ROS_IP=$(ip -o -4 route get $target_host | awk "/$target_host/ "'{print $5}')
export ROS_HOSTNAME=$ROS_IP
}

rossetip() {
local device=${1-"(eth0|eth1|eth2|eth3|eth4|wlan0|wlan1|wlan2|wlan3|wlan4|en0|en1|en2|en3|lo0)"}
local device=${1-'(eth|wlan|en|lo)[0-9]*'}
if [[ $device =~ [0-9]+.[0-9]+.[0-9]+.[0-9]+ ]]; then
export ROS_IP="$device"
else
Expand Down Expand Up @@ -148,6 +141,7 @@ rosn() {
fi
fi
}

rost() {
if [ "$1" = "" ]; then
select=$(rostopic list | percol | xargs -n 1 rostopic info | percol)
Expand Down
1 change: 1 addition & 0 deletions jsk_tools/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<run_depend>rqt_reconfigure</run_depend>
<run_depend>axis_camera</run_depend>
<run_depend>pr2_computer_monitor</run_depend>
<run_depend>iproute2</run_depend>
<run_depend>jsk_network_tools</run_depend>
<run_depend>jsk_topic_tools</run_depend>
<run_depend>rosbag</run_depend>
Expand Down