#! /bin/sh
#----------------------------------------------------------------------------
# etc/setup - eisfair installation
#
# Creation:	15.10.2001  fm
# Last Update:  19.11.2001  fm
#
# Copyright (c) 2001 Frank Meyer <frank@eisfair.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#----------------------------------------------------------------------------

mode=$1					# e.g. start
dirname=`dirname $0`

case $dirname
in
    .)	dirname=`pwd`;;			# current directory
    /*) ;;				# absolute path
    *)	dirname=`pwd`/$dirname;;	# relative path
esac

if [ "$mode" != "start" ]
then
    mode=test
fi

if [ $mode != test ]
then
    . /etc/rc.cfg
fi

ask ()
{
    while [ 1 ]
    do
	echo -e "$1 (y/n)? \c"
	read a

	case "$a"
	in
	    y | yes)	a=y; break;;
	    n | no)	a=n; break;;
	    *)
		colecho "Please answer y(es) or n(o)!" br x br
		;;
	esac
    done
}

#----------------------------------------------------------------------------
# welcome
#----------------------------------------------------------------------------

cd /

echo
colecho "Welcome to EIS/FAIR installation" br x br
echo

#----------------------------------------------------------------------------
# check network interfaced (ethernet card)
#----------------------------------------------------------------------------

colecho "Checking network interface ..." gn
echo

eth_name=$IP_ETH_1_NAME

if [ "$eth_name" = "" ]
then
    eth_name=eth0
fi

ifconfig $eth_name >/tmp/$eth_name

if [ $? != 0 ]
then
	colecho "Did not found your network interface. Exit!" br x br

	for x in `lspci -n -m | grep "lass 02"`
	do
		case "$x" in
			[0-9][0-9]:?*) # device number
				lspci -s $x -n
				lspci -s $x -vv
				;;
			*) # none
				;;
		esac
	done

	exit 1
fi

#----------------------------------------------------------------------------
# get MAC Adress and try to get Setup-Archive
#----------------------------------------------------------------------------

if [ "$LOCAL_SETUP" != "" ]
then
	mac=`grep "HWaddr" </tmp/$eth_name | cut -d ' ' -f 11 | tr ':' '-'`

	wget -T 60 $LOCAL_SETUP/$mac/local-setup.tar.gz

	if [ $? != 0 ]
	then
		wget -T 60 $LOCAL_SETUP/local-setup.tar.gz
	fi
fi

if [ -r local-setup.tar.gz ]
then
	colecho "Using Remote Setup..." gn
	gunzip -d <local-setup.tar.gz | tar xvf -
else
	colecho "Using Local Setup..." gn
fi

#----------------------------------------------------------------------------
# 
#----------------------------------------------------------------------------

chmod a+x /etc/local-setup
/usr/local/bin/dtou /etc/local-setup
. /etc/local-setup
