#!/usr/bin/bash

# Debian Edu Buster gateway machine /etc/network/interfaces generator
# Assume 2 NICs.

NICS=$(find /sys/class/net ! -name net -a ! -name lo -exec basename \{\} \; | cat)

function check_nics
{
    if ( [ "$1" != "" ] && [ "$2" != "" ] ); then return
    else echo "ERROR: Need exactly 2 NICs; found $1 $2" && exit -1
    fi
}

check_nics $NICS

function base_and_lo
{
    echo "source /etc/network/interfaces.d/*"
    echo "auto lo"
    echo "iface lo inet loopback"
}

function wan_and_lan
{
    echo "allow-hotplug $1"
    echo "iface $1 inet dhcp"

    echo "allow-hotplug $2"
    echo "iface $2 inet static"
    echo "    address 10.0.0.1"
    echo "    netmask 255.0.0.1"
}

base_and_lo
wan_and_lan $NICS

