#!/bin/sh
#******************************************************************
#ident /etc/netenv/netenv_setup Time-stamp: <03/03/31 08:47:21 bav>
#******************************************************************
#                            Gerd Bavendiek  bav@epost.de  03-03-11
#
# If there is a variable NETENV_SCRIPT pointing to this executable
# file, netenv will source this script during boot.
#
# This is an Debian-only example. It creates an
# /etc/network/interfaces in a hopefully safe manner.
# This way non PCMCIA-NIC-users can use netenv on Debian without
# further configuration steps.
#------------------------------------------------------------------
print_action() 
{
   echo -e netenv: $* " ... \c"  
}
print_status() 
{
   if [ $? -eq 0 ]; then
      echo done
   else
      echo failed
   fi
}

if ! grep Debian /etc/issue >/dev/null 2>&1; then
   print_action Doing nothing, as this is obviously no Debian
   echo
   exit 0
fi

# Save /etc/network/interfaces if it has not been created by netenv
if grep netenv /etc/network/interfaces >/dev/null 2>&1; then
   cp -p /etc/network/interfaces /etc/network/interfaces.pre-netenv
   print_action /etc/network/interfaces was backuped as /etc/network/interfaces.pre-netenv
fi

print_action creating new /etc/network/interfaces
(
   echo "# /etc/network/interfaces autogenerated by netenv "`date`
   echo "# old /etc/network/interfaces backup as /etc/network/interfaces.pre-netenv"
   echo auto lo
   echo iface lo inet loopback
   echo auto eth0
   if [ "$BOOTPROTO" = "dhcp" ]; then
      echo iface eth0 inet dhcp
   else
      echo iface eth0 inet static
      echo address $IPADDR
      echo netmask $NETMASK
      echo network $NETWORK
      echo broadcast $BROADCAST
      echo gateway $GATEWAY
   fi
) > /etc/network/interfaces
print_status done

