#!/bin/bash

IP=$1
NETMASK=$2
GATEWAY=$3

if [ -z "$IP" ] || [ -z "$NETMASK" ]
then
    cat << EOF
USAGE:
    $0 <ip address> <netmask> optional: <gateway>
EOF
    exit 1;
fi

if [ -z "$GATEWAY" ]
then
    GATEWAY_LINE=""
else
    GATEWAY_LINE="gateway $GATEWAY"
fi

cat << EOF > /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address $IP
    netmask $NETMASK
    $GATEWAY_LINE

auto eth1 eth1:0
iface eth1 inet static
    address 172.16.6.1
    netmask 255.255.254.0
iface eth1:0 inet static
    address 172.16.0.2
    netmask 255.255.254.0
EOF
