#!/bin/sh
#
# newhost
#
# Installation script for iX-Terminal (iX 8/95)
#
# Copyright (C) 1995 Verlag Heinz Heise 
# and Harald Milz (hm@ix.de)
#
# If you need support, contact 
# Harald Milz
# iX Multiuser Multitasking Magazine
# Helstorfer Str. 7
# D-30625 Hannover
# phone +49 511/53 52-377
# fax   +49 511/53 52-361
# email hm@ix.de
#

DIR=`dirname $0`
cd $DIR
LIBDIR=`pwd`
DIR=

# get initial setting as network etc. 
cat << EOF

This script generates a file tree for a new "iX-Terminal". It will ask you
following items: 
- hostname, domain name and several IP addresses in internet dotted notation
  (xxx.xxx.xxx.xxx) 
- type of graphics adapter
- type of mouse
- keyboard type
so you might want to keep your documentation handy... 

EOF


DONE=N
while [ "$DONE" = "N" ] ; do
	HOSTNAME=`hostname`
	echo "hostname, e.g. $HOSTNAME: \c"
	read HOSTNAME REST
	DOMAINNAME=`domainname`
	echo "domain name, e.g. $DOMAINNAME: \c"
	read DOMAINNAME REST
	echo "IP address of the new terminal, e.g. 192.168.10.10: \c"
	read IPADDR REST
	echo "local net address, e.g. 192.168.10.32: \c"
	read LOCALNET REST
	echo "local netmask, e.g. 255.255.255.224: \c"
	read NETMASK REST
	echo "local broadcast address, e.g. 192.168.10.255: \c"
	read BROADCAST REST
	echo "your default gateway, e.g. 192.160.10.1: \c"
	read ROUTER REST
	echo "your nameserver, e.g. 192.168.10.34: \c"
	read NAMESERVER REST
	echo "name of the syslog logging host: \c"
	read LOGHOST REST
	echo "name of the XDMCP host: \c"
	read XDMCPHOST REST


# determine graphics adapter
	cat << EOF

Now we must determine your graphics adapter. 

Please enter	if you have a

8514		8514-compatible adapter	
AGX		AGX-based board, e.g. a Hercules Graphite HG-210		
Mach8		ATI Mach8
Mach32		ATI Mach32
Mach64		ATI Mach64
P9000		Weitek P9000-based board
S3		S3-based board
SVGA		any SVGA board, e.g. ET4000
W32		ET4000 W32 board

EOF
	CORRECT=N
	while [ "$CORRECT" = "N" ] ; do 
		echo "type of graphics adapter: \c"
		read ADAPTER REST
		SERVER="XF86_$ADAPTER"
		if [ -f TEMPLATE/usr/X11R6/bin/$SERVER ] ; then
			CORRECT=Y
		else
			echo "server for $ADAPTER is unknown, please re-enter!"
		fi
	done
	

# now determine the mouse type
	cat << EOF

It's time to determine your mouse device. You have the choice of the following:

logibm          Logitech bus mouse
psaux           PS/2 bus mouse
inportbm        Microsoft bus mouse
atibm           ATI XL bus mouse
ttyS0		serial mouse connected to the first serial port
ttyS1		serial mouse connected to the second serial port

EOF
	CORRECT=N
	while [ "$CORRECT" = "N" ] ; do
		echo "type of mouse: \c"
		read MOUSE REST
		if grep "^$MOUSE" TEMPLATE/mouse-types > /dev/null ; then
			CORRECT=Y
		else
			echo "mouse type $MOUSE is unknown, please re-enter!"
		fi
	done


# determine keyboard mapping
	cat << EOF

We are going to set up the right keyboard mapping. Following
Keyboard types are supported: 

EOF
	(
	cd TEMPLATE/usr/lib/kbd/keytables
	ls *.map
	)

	echo "if in doubt, see the docs in TEMPLATE/usr/lib/kbd/keytables"
	echo "for a German keyboard, type gr-lat1.map is recommended."
	CORRECT=N
	while [ "$CORRECT" = "N" ] ; do
		echo "your keyboard type: \c"
		read KEYBOARD REST
		if [ -f TEMPLATE/usr/lib/kbd/keytables/$KEYBOARD ] ; then
			CORRECT=Y
		else
			echo "keyboard type $KEYBOARD not supported, please re-enter!"
		fi
	done


# now have the user check everything
	cat << EOF

These are your present settings:
hostname			$HOSTNAME
domain				$DOMAINNAME
IP address			$IPADDR
your graphics adapter		$ADAPTER
your mouse type			$MOUSE
your local network address	$LOCALNET
your netmask			$NETMASK
your broadcast address		$BROADCAST
your default gateway		$ROUTER
your nameserver			$NAMESERVER
the syslog logging host		$LOGHOST
the XDMCP host			$XDMCPHOST
your keyboard type		$KEYBOARD

EOF
	echo "Everything correct? (Y/N) \c"
	read DONE REST
	if [ "$DONE" = "y" -o "$DONE" = "Y" ] ; then
		DONE=Y
	fi
done

# now set up the directory tree for the new toy

echo "setting up directory tree for $HOSTNAME"
DIRTREE="/tmp/dirtree.$$"
( 
cd TEMPLATE
find . -type d -print > $DIRTREE
)
mkdir $HOSTNAME
(
cd $HOSTNAME
for dir in `cat $DIRTREE`; do
	./mkdirhier $dir
done
)

# copy all of /etc into the corresponding dir.
# hopefully your tar isn't broken. If in doubt, use GNU tar :-)
echo "copying all in /etc"
(cd TEMPLATE; tar cpf - etc) | (cd $HOSTNAME; tar xpf -)

# set up hard links for all the rest... 
echo "hardlinking all the rest"
FILES="/tmp/files.$$"
(
cd TEMPLATE
THIS=`echo * | sed 's#etc ##'`
find $THIS -type f -print > $FILES
)
for file in `cat $FILES` ; do
	ln TEMPLATE/$file $HOSTNAME/$file
done
rm -f $DIRTREE $FILES

# create some handy symlinks
echo "creating some symlinks"
(cd $HOSTNAME/usr/X11R6/bin; ln -s $SERVER X)
(cd $HOSTNAME/bin; ln -s bash sh; ln -s vim vi)
(cd $HOSTNAME/usr/lib/kbd/keytables; ln -s $KEYBOARD local.map)
(cd $HOSTNAME/dev; ln -s $MOUSE mouse; ln -s tty0 console)
(cd $HOSTNAME/sbin; ln -s swapon swapoff)
# symlink some man pages
(
cd $HOSTNAME/usr/man/preformat/cat1
for i in 8514 AGX Mach32 Mach64 Mach8 P9000 S3 W32 ; do
	ln -s XF86_Accel.1x.gz XF86_$i.1x.gz
done
ln -s elvis.1.gz vi.1.gz
)
(
cd $HOSTNAME/usr/man/preformat/cat8 
ln -s agetty.8.gz getty.8.gz
ln -s mount.8.gz umount.8.gz
ln -s rdev.8.gz swapdev.8.gz
ln -s swapon.8.gz swapoff.8.gz
)


# 
touch $HOSTNAME/etc/CONFIG
if expr "$MOUSE" : "ttyS" > /dev/null ; then
	:
else	
	# this serves for creating the busmouse
	# special files later:
	echo BUSMICE > $HOSTNAME/etc/CONFIG
fi		

# generate etc/NETCONF, etc/HOSTNAME, etc/syslog.conf etc.

cd $HOSTNAME/etc
echo "generating NETCONF HOSTNAME syslog.conf resolv.conf hosts"
(
cat << EOF
CONFIGPATH=/etc
HOSTNAME=$HOSTNAME
DOMAINNAME=$DOMAINNAME
FULLNAME=$HOSTNAME.$DOMAINNAME
IPADDR=$IPADDR
LOCALNET=$LOCALNET
NETMASK=$NETMASK
BROADCAST=$BROADCAST
ROUTER=$ROUTER
NAMESERVER=$NAMESERVER

export CONFIGPATH HOSTNAME DOMAINNAME FULLNAME IPADDR LOCALNET
export NETMASK BROADCAST ROUTER NAMESERVER
EOF
) > NETCONF

echo "$HOSTNAME.$DOMAINNAME" > HOSTNAME

(
cat << EOF
# syslog.conf
# send everything to the loghost

*.debug		@$LOGHOST
EOF
) > syslog.conf

echo "domain $DOMAINNAME" > resolv.conf
echo "nameserver $NAMESERVER" >> resolv.conf

echo "127.0.0.0		loopback" > hosts
echo "127.0.0.1		localhost" >> hosts
echo "$IPADDR		$HOSTNAME" >> hosts

# update rc.M (XDMCPHOST)

cd $LIBDIR
rm -f $HOSTNAME/etc/rc.d/rc.M
sed 's#XDMCPHOST#'$XDMCPHOST'#' < TEMPLATE/etc/rc.d/rc.M > $HOSTNAME/etc/rc.d/rc.M
chmod 755 $HOSTNAME/etc/rc.d/rc.M

# now spit out final warning

cat << EOF

Now you should cd to $HOSTNAME/etc and edit
XF86Config		(mandatory)
rc.d/rc.local		(if you like)
inittab 		(if you like)

When booting your new iX-Terminal for the first time, the kernel will ask
for a suitable video mode. Press RETURN and choose one of the modes
shown. To permanently set this video mode upon boot, you can create a new
bootImage with the "rdev" and "mknbi" commands. 

Don't forget to set up the file /etc/bootptab on your BOOTP host. You
should consult the documentation of the respective host, i.e.  "man
bootpd". If BOOTP host and TFTP host are identical, a minimum bootptab
entry might look like:

$HOSTNAME:ht=ethernet:ip=$IPADDR:ha=0000c0123456: \\
       bf=$LIBDIR/$HOSTNAME/bootImage

Have fun!

EOF
