#!/bin/bash
# $Id: stage2,v 1.9 2009-02-07 08:04:14 tim Exp $

while true; do
    cat <<EOF >/etc/network/interfaces
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

# The loopback interface
auto lo
iface lo inet loopback

# The first network card - this entry was created during the Debian installation
auto eth0

EOF

    echo "Do you want to configure a static IP address (y/n)?"
    read -t 10 yn || yn=n
    if [ "$yn" = "n" ]; then
	echo "Setting up dhcp"
	echo "iface eth0 inet dhcp" >>/etc/network/interfaces
	break;
    fi
    if [ "$yn" = "y" ]; then
	echo "Enter IP address"
	read address
	echo "Enter netmask"
	read netmask
	echo "Enter gateway"
	read gateway
	echo
	echo address=$address
	echo netmask=$netmask
	echo gateway=$gateway
	echo
	echo "OK (y/n)?"
	read yn
	if [ "$yn" = "y" ]; then
	    echo "iface eth0 inet static" >>/etc/network/interfaces
	    echo "address $address" >>/etc/network/interfaces
	    echo "netmask $netmask" >>/etc/network/interfaces
	    echo "gateway $gateway" >>/etc/network/interfaces
	    break;
	fi
    fi
done

echo Checking for raid devices: please wait

mdadm --examine --scan /dev/hd* /dev/sd* | sed -e 's/^[[:space:]]*devices=/DEVICE /' -e 's/,/ /' >/etc/mdadm/mdadm.conf

exit 0
