#!/bin/bash
set -e

if [ -e /dev/ttyAMA0 ]
then
	EIB_URL="tpuarts:/dev/ttyAMA0"
	# ttyAMA0 interferes with others. Check if everything is deactivated
	if [ -f /etc/inittab ]
	then
		if grep ttyAMA0 /etc/inittab
		then
			echo "ttyAMA0 not deactivated. Run dpkg eibd --reconfigure."
			exit 10
		fi
	fi
elif [ -e /dev/ttyACM0 ]
then
	EIB_URL="tpuarts:/dev/ttyACM0"
else
	EIB_URL="ipt:127.0.0.1"
fi

echo "running under $IND_ADDR"
echo "connect with $EIB_URL"
/usr/bin/eibd -i -DTS -e $IND_ADDR $ADD_PARAM $EIB_URL &

