#!/bin/bash

NETDEV=eth0
GROOVIX_ID=`ifconfig $NETDEV 2>/dev/null | grep HWaddr | sed 's/.*HWaddr //' | sed 's/://g' | sed 's/^/GV/' | perl -pi -e 's/\s+//g'  | tr '[:lower:]' '[:upper:]' `
if [ -z "$GROOVIX_ID" ]; then
	OTHER_NETDEVS=`ifconfig -s | cut -f 1 -d" " | egrep -v "^(lo|Iface|eth0)$"`
	for NETDEV in $OTHER_NETDEVS ; do
		GROOVIX_ID=`ifconfig $NETDEV 2>/dev/null | grep HWaddr | sed 's/.*HWaddr //' | sed 's/://g' | sed 's/^/GV/' | perl -pi -e 's/\s+//g' | tr '[:lower:]' '[:upper:]' `
		if [ -n "$GROOVIX_ID" ]; then
			echo "found id on $NETDEV" 1>&2
			echo $GROOVIX_ID;
			exit 0;
		fi
	done
else
	echo $GROOVIX_ID;
	exit 0
fi

echo "unknown"
exit 1
