#!/bin/bash
# this file is generated by turtlebot_bringup/upstart/install.bash

log_file=/tmp/turtlebot-upstart.log
DATE=`date`

if [ -s /etc/ros/setup.bash ]; then
    echo "$DATE: turtlebot-start using setup file /etc/ros/setup.bash" >> $log_file
    source /etc/ros/setup.bash
else
    echo "$DATE: turtlebot-start using setup file /opt/ros/electric/setup.bash" >> $log_file
    source /opt/ros/electric/setup.bash
fi

interface=wlan0
echo "$DATE: turtlebot-start on interface $interface" >> $log_file

export ROS_IP=`ifconfig $interface | grep -o 'inet addr:[^ ]*' | cut -d: -f2`

echo "$DATE: turtlebot-start setting ROS_IP=$ROS_IP" >> $log_file

if [ "$ROS_IP" = "" ]; then
    echo "$DATE: turtlebot-start can't run with empty ROS_IP." >> $log_file
    exit 1
fi

if [ -s /etc/ros/electric/turtlebot.launch ]; then
    setuidgid turtlebot roslaunch /etc/ros/electric/turtlebot.launch
else
    setuidgid turtlebot roslaunch turtlebot_bringup minimal.launch
fi
