#!/bin/sh
# $Id: connect.sh,v 1.8 1998/02/10 20:00:56 nathanw Exp nathanw $
# Script to get the network up and running from the ramdisk install.

getresp() {
	read resp
	if [ "X$resp" = "X" ]; then
		resp=$1
	fi
}


# Run ifconfig -a and get rid of everything but the name of a real interface
# device. 
intfs=`ifconfig -l | sed -e 's/lo.//g;s/sl.//g;s/ppp.//g;s/strip.//g;s/tun.//g'`


if [ "intfs" = "" ]; then
	echo "No network interfaces found.  If you have a network connection,"
	echo "it wasn't recognized by the kernel.  If you don't have a network"
	echo "connection, you should be using a different installation disk."
	echo "Type 'halt' now to halt your machine."
	exit 1
fi

echo ""
ifaddr=
while [ "$ifaddr" = "" ]; do
	echo -n "What is this machine's IP address? "
	read ifaddr
done
ifaddrset=yes

params=`/etc/athena/netparams -e "$ifaddr"`
if [ $? -eq 1 ]; then
	paramsguessed=no
	echo "Not on MITnet; unable to guess network parameters."
else
	on_mitnet=yes
	set -- $params
	ifnetmask=$1
	ifbroadcast=$3
	ifgateway=$4
	paramsguessed=yes
fi


while [ ! $done ]; do

	if [ $ifaddrset != yes ]; then
		while [ "$ifaddr" = "" ]; do
			echo -n "What is this machine's IP address [$ifaddr]? "
			read ifaddr
		done
	fi
	
	params=`/etc/athena/netparams -e "ifaddr"`
	if [ $? -eq 1]; then
		on_mitnet=yes
	else
		on_mitnet=no
	fi

	set -- $params
	ifnetmask=$1
	ifbroadcast=$3
	ifgateway=$4

	# Perform IFS magic to seperate IP address into four pieces.
	OLDIFS="$IFS"
	IFS=.
	set -- $ifaddr
	ifA=$1 ifB=$2 ifC=$3 ifD=$4
	IFS="$OLDIFS"

	echo -n "What is your netmask? [0xffffff00]"
	getresp 0xffffff00; ifnetmask="$resp"
	if [ "$ifnetmask" = "0xffff0000" ]; then
		proto_bcast="${ifA}.${ifB}.255.255"
		proto_gateway="${ifA}.${ifB}.0.1"
	else
		proto_bcast="${ifA}.${ifB}.{$ifC}.255"
		proto_gateway="${ifA}.${ifB}.${ifC}.1"
	fi
