#!/bin/sh

defaultconfig=$(dirname $0)/hosts

if [ -z "$2" -a ! -f $defaultconfig ] ; then
	echo "Usage: $(basename $0) <hops> [<config>]"
	exit 1
fi
if [ -z "$1" ] ; then
	echo "Usage: $(basename $0) <hops> [<config>]"
	exit 1
fi

if [ -f "$2" ] ; then
	config=$1
else
	config=$defaultconfig
fi

hosts=$(grep -v -e prefix -e admin -e connection $config | perl -ne 's/=.*//; print')
connection=$(grep connection $config | sed -e 's/.*=//' -e 's/-/ /g')
host=$(echo $connection | cut -d ' ' -f $(($1+1)))

echo -n "Registering service at wllap11... "
ssh msmeasure@wllap11 "~/applications/openslp/bin/slptool register service:test.x://192.168.0.11" && echo "Done."
echo "Looking up service from $host..."
ssh msmeasure@$host "~/applications/openslp/bin/slptool unicastfindsrvs 127.0.0.1 service:test.x"
