#!/bin/sh

set_ether_mac() {

	RB_CONFIG="$(grep "RedBoot config" /proc/mtd | cut -d: -f1)"

	for npe in eth0 eth1 eth2
	do
		if [ "$(ifconfig $npe 2>/dev/null | grep -c 00:00:00:00:00:00)" == "1" ]; then
			ifconfig $npe hw ether $(fconfig -s -r -d /dev/$RB_CONFIG -n npe_"$npe"_esa)
		fi
	done

	# Some developers should be shot on sight at Zcom/Netgear
	# -- Fixup for the WG302v1, need someone with a WAG302v1 to fix that, too

	if [ "$(ifconfig eth0 2>/dev/null | grep -c 00:00:00:00:00:00)" == "1" ]; then
			ifconfig eth0 hw ether $(fconfig -s -r -d /dev/$RB_CONFIG -n zcom_npe_esa)
	fi
}

boot_hook_add preinit_main set_ether_mac

