#!/bin/sh
#
#

echo
echo "Configuring system for Ethernet based Internet connection."
echo

# Allow for local network reconfig
config_local

echo
YNMSG="Does your Internet connection get its IP via DHCP? [y/n]: "
check_yn
if [ "$YN" = "Y" ]; then
	INETTYPE=ETHERNET_DHCP
	echo
	echo "Some areas require you to specify a hostname when obtaining a DHCP address."
	echo "This hostname would have been given to you when you originally had"
	echo "your Internet access installed.  If you have been supplied with a hostname "
	echo "for your computer, enter it here. If not, simply press enter."
	echo
	echo -n "Enter your DHCP hostname: "
	read DHCPHOSTNAME
else
	INETTYPE=ETHERNET_STATIC
	echo
	echo "Please enter the information for your static IP configuration"
	echo -n "Internet IP Address: "
	read IPADDR
	echo -n "Internet Subnet Mask [255.255.255.0]: "	
	read NETMASK
	# If the user did not specify a subnet mask, default to a Class C
	[ -z "$NETMASK" ] && NETMASK=255.255.255.0
	echo -n "Internet Broadcast [Enter = Default]: "
	read BROADCAST
	echo -n "Internet Gateway Address: "
	read GATEWAY
	echo -n "Domain Name: "
	read DOMAINNAME
	echo "DNS Server 1: "
	read DNS1
	echo "DNS Server 2 (optional): "
	read DNS2
fi

# Clear the additional packages file
echo > floppy/packages

echo
YNMSG="Install the Big Pond login software? [y/n]: "
check_yn
if [ "$YN" = "Y" ]; then
	echo "bpalogin" >> floppy/packages
	echo
	echo -n "Enter Big Pond username: "
	read BPA_LOGIN
	echo
	echo -n "Enter Big Pond password: "
	read BPA_PASSWORD
fi

config_dhcp

config_dmz

# Reset the modules definition file
> pkgsrc/modules/etc/modules
# Reset the modules directory
rm -f pkgsrc/modules/lib/modules/*
for REQMODS in `cat data/modules`; do
	add_module $REQMODS
done

# Get the network card configuration
scripts/getcards.pl

config_dmz_card

config_language

# Install any misc packages
. ./scripts/mkflp-misc
# Generate the ssh host keys
. ./scripts/cfg-sshd

# Create the Coyote configuration file
save_local_config
save_dmz_config
save_dhcp_config
echo "INETTYPE=$INETTYPE" >>  $CONFIG_FILE
if [ "$INETTYPE" = "ETHERNET_STATIC" ]; then
	echo "IPADDR=$IPADDR" >>  $CONFIG_FILE
	echo "NETMASK=$NETMASK" >>  $CONFIG_FILE
	if ! [ -z "$BROADCAST" ]; then 
		echo "BROADCAST=$BROADCAST" >> $CONFIG_FILE
	fi
	echo "GATEWAY=$GATEWAY" >>  $CONFIG_FILE
	echo "DNS1=$DNS1" >>  $CONFIG_FILE
	echo "DNS2=$DNS2" >>  $CONFIG_FILE
	echo "DOMAINNAME=$DOMAINNAME" >>  $CONFIG_FILE
fi

# Big Pond login software
if ! [ -z "$BPA_LOGIN" ]; then
    echo "BPA_LOGIN=$BPA_LOGIN" >> $CONFIG_FILE
    echo "BPA_PASSWORD=$BPA_PASSWORD" >> $CONFIG_FILE
fi

if ! [ -z "$DHCPHOSTNAME" ]; then
	echo "DHCPHOSTNAME=$DHCPHOSTNAME" >> $CONFIG_FILE
fi
if ! [ -z "$LOGGING_HOST" ]; then
	echo "LOGGING_HOST=$LOGGING_HOST" >> $CONFIG_FILE
fi

buildall
write_floppy

echo "Done."
