#!/bin/bash

# This script provides a central location for getting IP addresses. It uses
# output/ip_base.txt as the first 3 parts and then adds on whatever is
# correct for its first argument (fitpc or robot).
# It will create output/ip_base.txt with a default value if it does not already
# exist.

FILE=`dirname $0`/../../output/ip_base.txt

if [[ ! -e ${FILE} ]]; then
	mkdir -p `dirname ${FILE}`
	echo '10.9.71' > ${FILE}
fi

BASE=`cat ${FILE}`

case $1 in
	fitpc)
		# This is the IP address that we use for our fitpc.
		echo ${BASE}.179 ;;
	robot)
		# This is the IP address that the cRIO has to be on.
		echo ${BASE}.2 ;;
	*)
		echo "Unknown IP address $1. Returning ${BASE}.0 instead." 1>&2
		echo ${BASE}.0
esac
