#!/usr/bin/perl
# Get list of network devices
open(BAR,"/proc/net/dev") || die "Can't find /proc/net/dev";
while (<BAR>)
{
	if (/(.*):/) {
		$kdev = $1;
		$kdev =~ s/ //g;
		$bdev = `/sbin/biosdevname --policy vmware -i $kdev`;
		chomp($bdev);
		if ($bdev ne "") {
			$kbmap{$kdev} = $bdev;
			if ($kdev ne $bdev) {
				$remap++;
			}
		}
	}
}
close(BAR);
if ($remap == 0) {
	printf("All devices numbered correctly\n");
	exit(0);
}

# Read old contents of esx.conf, replace old with new name
open(BAR,"/etc/esx.conf") || die "Can't find /etc/esx.conf"; 
while($line = <BAR>)
{
	for (keys %kbmap) {
		$line =~ s/$_/$kbmap{$_}/g;
	}
	push(@outline,$line);
}
close(BAR);

# Rewrite esx.conf
open(BAR, ">/etc/esx.conf");
print (BAR @outline);
close(BAR);
