#!/bin/sh

set +e

dirname=`dirname $0`
retval=0

case $dirname in
	/*)
		cd $dirname/.. > /dev/null
		path=`pwd`
		cd - > /dev/null
	;;
	*)
		cd `pwd`/$dirname/.. > /dev/null
		path=`pwd`
		cd - > /dev/null
	;;
esac

export PYTHONPATH=$path/lib

cd $path/conf
names=`ls *.conf`
cd -

export exabgp_tcp_bind=''
export exabgp_debug_selfcheck=true

for conf in $names
do
	printf "%-50s " $conf
	result=`$path/../sbin/exabgp $path/conf/$conf 2>&1`
	retcode=$?
	problem=`echo $result | grep 'Problem with the configuration file' || true`

	if [ $retcode -eq 0 ] && [ "$problem" = "" ]
	then
		printf "ok\n"
	else
		printf "failed\n"
		printf "\n"
		printf "env exabgp.tcp.bind='' exabgp.debug.selfcheck=true $path/../sbin/exabgp $path/conf/$conf 2>&1"
		printf "\n\n"
		printf "$result"
		printf "\n\n"
		retval=1
	fi
done

exit $retval
