#!/bin/sh
# @(#)install.cpp	1.35 revision of 97/04/23  14:37:46
# This is an unpublished work copyright (c) 1989 HELIOS Software GmbH
# 30159 Hannover, Germany
set +vx

ESDIR=`pwd`
export ESDIR

# @(#)HeliosVersion 2.5.0a2 Copyright 1989-1998 HELIOS Software Garbsen

# @(#)setup.cpp	1.28 revision of 98/02/09  19:27:44
PATH=$ESDIR:$ESDIR/etc:$PATH
export PATH
grop="macusers"
user="macuser"
hostupper=`hostname|sed 's/\..*//'|tr '[a-z]' '[A-Z]'` 2>/dev/null
if test -z "$hostupper"
then
	hostupper=`uname -n|sed 's/\..*//'|tr '[a-z]' '[A-Z]'`
fi
hostid=`machid`
# test how we can suppress the new line on echo
if test "X`echo -n`" = "X-n"
then
	en=''
else
	en='-n'
fi
if test "X`echo '\c'`" = "X\c"
then
	ec=''
else
	ec='\c'
fi










fstyp="-k -l"
Slevel=3000
Klevel=3000
rcdir=/etc










# @(#)line.cpp	1.9 revision of 93/04/20  22:29:16
# Berkeley has a stoneage bourne shell, so this mess is really necessary.
# this is also the reason not to use cat <<-eof to keep the code nicely
# indented.
status=0
line=""
gets=". /tmp/gets$$"
trap "rm -f /tmp/gets$$; exit \$status" 0 1 2 3 15
cat >/tmp/gets$$ <<\eof
line="!"
while test x"$line" = x"!"
do
	echo $en "* $p ? [$d] "$ec
	read line
	if test x"$line" = x"!"
	then
		$SHELL
	fi
done
if test -z "$line"
then
	line="$d"
fi
eof


kconfig="n"
done="n"
maystart="n"

if $ESDIR/etc/suser
then
	:
else
	echo "Installing EtherShare can only be done as user root!"
	exit 1
fi



default="1"

while test "$done" != "y"
do
cat <<eof

	EtherShare Installation Menu
	----------------------------
	
	The machine ID of this computer is "$hostid"

	1)	Install programs and configuration files
	2)	Install and configure AppleTalk kernel modules
	3)	Enter activation key to license HELIOS programs
	4)	Create a demo user
	5)	Configure AppleTalk network numbers
	6)	Display README file
	7)	Quit

eof
	p="Your choice" d=$default $gets
	case "$line" in
	1|p|P)	$ESDIR/etc/prginstall
		if test $? -eq 0
		then
			default="2"
		fi
		;;
	2|k|K)	$ESDIR/etc/kconfig
		case $? in
		0)
			default="3"
			kconfig="y"
			;;
		2)
			default="3"
			maystart="y"
			;;
		*)
			;;
		esac
		;;
	3|a|A)

		$ESDIR/etc/activate
		if test $? -eq 0
		then
			default="4"
		fi
		;;
	4|u|U)	$ESDIR/etc/usrinstall
		if test $? -eq 0
		then
			default="5"
		fi
		;;
	5|c|C)	nif=`$ESDIR/etc/lsif|wc -l`


		if test $nif -gt 1
		then
			$ESDIR/netconf
		else
cat <<eof

This system has only one network interface installed, thus there is no
need to configure any network numbers.
eof
		fi

		default="6"
		;;
	6|r|R)
		more $ESDIR/README
		default="7"
		;;
	7|q|Q)	done="y"
		;;
	*)
		echo "Please enter a number between 1 and 7"
		;;
	esac
done

cat <<eof

The EtherShare configuration is now finished. If you want to add printers,
users, groups or volumes, read the book first and use vi, or use our
EtherShare Admin application from one of the Macs. The latter is much
easier, even if you are experienced with vi (the famous UNIX editor).

eof

$ESDIR/lcheck -f $ESDIR/conf/ethershare.license EtherShare >/dev/null 2>&1
if test $? -ne 0
then
	maystart="n"
cat <<eof

There is no valid license in the EtherShare license data base. The
EtherShare server will not start until a valid license has been entered
using menu option 3.

eof
fi

if test "$maystart" = "y"
then
cat <<eof

Starting the EtherShare server.

eof
	$ESDIR/start-atalk
fi

if test "$kconfig" = "y"
then

cat <<eof

To make the EtherShare kernel modifications effective it is necessary
to reboot the system.

eof

	p="Do you want to reboot now" d="y" $gets

	if test "$line" = "y"
	then

		p="Minutes till shutdown" d="0" $gets

		if test "$line" -eq 0
		then
			line="now"
		else
			line="+$line"
		fi
		cd /
		shutdown -r $line


	fi
fi
