#!/bin/bash

# Check to see if we have an /etc/network/interfaces file. If not, restore the backup located in XXXX

NET_INTERFACE_FILE=/etc/network/interfaces
RESTORE_FILE=/etc/nyquist/backup/interfaces

echo "Checking for network interfaces"

if [ ! -f $NET_INTERFACE_FILE ]; then
    echo "$NET_INTERFACE_FILE not found! Restoring from $RESTORE_FILE"
    if [ ! -f $RESTORE_FILE ]; then
        echo "$RESTORE_FILE not found! Creating default DHCP interface file"
    	stdbuf -o0 echo -e "# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp
# Example to keep MAC address between reboots
" > $NET_INTERFACE_FILE

        #Copy this new interface file to the backup directory
        cp $NET_INTERFACE_FILE $RESTORE_FILE
	
    else
        # Restore if backup file exists
        cp $RESTORE_FILE $NET_INTERFACE_FILE
    fi


else
    echo "$NET_INTERFACE_FILE is available!"
fi 


