Skip to content

Instantly share code, notes, and snippets.

@marc-hanheide
Created January 15, 2015 14:58
Show Gist options
  • Select an option

  • Save marc-hanheide/1ac6d9dfd6e89d4f6126 to your computer and use it in GitHub Desktop.

Select an option

Save marc-hanheide/1ac6d9dfd6e89d4f6126 to your computer and use it in GitHub Desktop.

Revisions

  1. marc-hanheide renamed this gist Jan 15, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. marc-hanheide created this gist Jan 15, 2015.
    26 changes: 26 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #!bin/bash

    # This script configures the ROS environment variables according to the route
    # to the ROS_MASTER. ROS_MASTER can either be defined as an evironment variable
    # itself or given as first argument to this script. The ROS_IP and ROS_HOSTNAME
    # are set according to the IP that is sitting on the route to this master.
    # The ROS_MASTER_URI is also set, using port 11311. ROS_MASTER needs to be defined
    # as a numeric IP address, not a hostname.

    if [ "$1" ]; then
    ROS_MASTER="$1"
    fi

    if [ -z "$ROS_MASTER" ]; then
    ROS_MASTER=127.0.0.1
    fi

    echo "ROS_MASTER: $ROS_MASTER"

    export ROS_IP=`ip route get $ROS_MASTER | grep "src" | sed 's/.*src \([0-9\.]*\).*/\1/'`
    export ROS_HOSTNAME=$ROS_IP
    export ROS_MASTER_URI="http://$ROS_MASTER:11311/"

    echo "ROS_IP: $ROS_IP"
    echo "ROS_HOSTNAME: $ROS_HOSTNAME"
    echo "ROS_MASTER_URI: $ROS_MASTER_URI"