#!/bin/bash
echo "Updating 70-persistent-net.rules with eth0..."
sed -i '7,9d' /etc/udev/rules.d/70-persistent-net.rules
sed -i s/eth1/eth0/g /etc/udev/rules.d/70-persistent-net.rules
echo "Updating ifcfg-eth0 with new MAC address..."
newmac=`ip a | tail -n 1 | awk '{print $2}'`
oldmac=`grep HWADDR /etc/sysconfig/networking/devices/ifcfg-eth0 | awk -F "=" '{print $2}'`
sed -i s/$oldmac/$newmac/g /etc/sysconfig/networking/devices/ifcfg-eth0
cp /etc/sysconfig/networking/devices/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0
echo "Rebooting the OS"
sleep 2
reboot