#! /bin/sh
# $Header: INSTALL,v 1.9 87/12/14 10:24:05 root Exp $
#
# Install script for System V.
#

#
# Set up some defaults
#
InstallTime="10 minutes"
FreeBlocks=15800
KernelFB=10500
CreateDir=false
TapeDevice=${Tape-/dev/nrmt0}
rfsnet=/dev/rfsnet
rfs_maj=30
rfs_min=38
sxt_dir=/dev/sxt
sxt_maj=31
spx=/dev/spx
spx_maj=30
spx_min=29

if [ "$Install" = "" ] ; then
	InstallDir=`pwd`
fi

#
# Do sanity checking asking the user for information.
#
# Get the correct installation directory.
#
if [ $# -gt 1 ] ; then
	echo "$0 takes only one argument.
Usage: $0 install_directory"
	exit 1
fi
if [ $# -eq 1 ] ; then
	if [ ! -d $1 ] ; then
		echo "$i does not exist."
		echo -n "Would you like me to create it [y/n](y)? "
		read ans
		case $ans in
			y*|Y*|"")
				CreateDir=true
				InstallDir=$1
				;;
			*)
				echo "
Please restart this script whenever you're ready."
				exit 1
				;;
		esac
	else
		InstallDir=$1
		CreateDir=false
	fi
else
	echo "The installation directory will be
	$InstallDir"
	echo -n "Is this ok [y/n](y)? "
	read ans
	case $ans in
		y*|Y*|"")
			CreateDir=false
			;;
		*)
			echo "
Please restart this script whenever you're ready."
			exit 1
			;;
	esac
fi
#
# Make sure that we have the correct tape
#
echo "The following is the tape device selected.
	$TapeDevice"
echo -n "Is this ok [y/n/q](y)? "
read ans
case $ans in
	y*|Y*|"")
		;;

	n*|N*)
		while
			echo "Please enter the path to your tape device.
It must be a non-rewinding device."
			echo -n "= "
			read TapeDevice
		do
			if [ -f $TapeDevice ] ; then
				break
			fi
			echo "$TapeDevice does not exist."
			echo "Please enter a valid path name."
		done
		;;

	*)
		echo "
Please restart this script whenever you're ready."
		exit 1
		;;
esac

df
echo "You'll need approximately $FreeBlocks blocks available on the file
system that $InstallDir resides."
echo -n "Do you have enough room [y/n](y)? "
read ans
case $ans in
	y*|Y*|"")
		;;
	*)
		echo "
Please restart this script whenever you're ready."
		exit 1
		;;
esac

echo -n "Would you like to install the kernel objects[y/n](n)? "
read ans
case $ans in 
	y*|Y*)
		df /usr
		echo -n "
Because of the building procedure the kernel objects must be installed 
in /usr/sys.  You will need at least $KernelFB free blocks on /usr.
Do you have enough room on /usr [y/n/q](n)? "
		read ans1
		case $ans1 in
			y*|Y*)
				InstallKernelObjs=true
				;;
			q*|Q*)
				echo "
Please restart this script whenever you're ready."
				exit 1
				;;
			*)
				InstallKernelObjs=false
				;;
		esac
		;;
	*)
		InstallKernelObjs=false
		echo -n "
The system header files are part of the kernel binaries which you have
decided not to install.  I can install just system header files if
you would like me to? [y/n/q](y) "
		read ans
		case $ans in
		n*|N*)
			InstallSystemHeaders=false
			;;
		q*|Q*)
		       	echo "
Please restart this script whenever you're ready."
			exit 1
			;;
		*)
			InstallSystemHeaders=true
			;;
		esac		
		;;
esac
echo "
Get a cup of coffee or a coke.  This installation will take 
about $InstallTime to complete."

#
# Move the tape over the first file which is the installation script.
#
mt -f $TapeDevice fsf 1


if [ "$CreateDir" = "true" ] ; then
	mkdir $InstallDir
	if [ $? -ne 0 ] ; then
		echo "mkdir of $InstallDir failed!"
		exit 1
	fi
fi

cd $InstallDir
tar xpf $TapeDevice

if [ ! -f etc/mkdual ]  ; then
	echo "Installation failed!"
	exit 1
fi

echo "Extraction of System V binaries complete.  Now creating links."
etc/mkdual $InstallDir

if [ "$InstallKernelObjs" = "true" ] ; then
     echo -n "Installing kernel binaries in /usr/sys ..."
     ( cd / ; tar xpf $TapeDevice)
     echo " done"
elif [ "$InstallSystemHeaders" = "true" ] ; then
     echo -n "Installing system header files ..."
     ( cd / ; tar xpf $TapeDevice usr/sys/sysv/sys )
     echo " done"
fi

#
# Copy rc.sysv into the BSD etc directory.  This file will setup the 
# symbolic links to passwd, group and mtab which might get broken if the
# user edits the files under System V.
# If the user has setup RFS, rc.sysv will start the necessary daemons to 
# get it going.
#
if [ -f etc/rc.sysv ] ; then
	cp etc/rc.sysv /.etc.BSD
fi

#
# Only the domestic version has a libcrypt.dom.  It contain des_dcrypt.o
#
if [ -f usr/lib/libcrypt.dom ] ; then
	echo "Installing correct version of libcrypt.a"
	mv usr/lib/libcrypt.dom usr/lib/libcrypt.a
fi

#
# Setup the rfsnet device.
#
if [ -f $rfsnet ] ; then
	rm $rfsnet
fi
mknod $rfsnet c $rfs_maj $rfs_min > /dev/null 2>&1
if [ $? -ne 0 ] ; then
	echo "
I'm going to need your help.  I tried to create the RFS networking device
but the command failed.  You'll need to figure out what went wrong.  The 
device name is
	$rfsnet
and it should be a character device with the major number being $rfs_maj and the
minor number $rfs_min."
fi

#
# Setup the spx device.
#
if [ -f $spx ] ; then
	rm $spx
fi
mknod $spx c $spx_maj $spx_min > /dev/null 2>&1
if [ $? -ne 0 ] ; then
	echo "
I'm going to need your help.  I tried to create the RFS networking device
but the command failed.  You'll need to figure out what went wrong.  The 
device name is
	$spx
and it should be a character device with the major number being $spx_maj and the
minor number $spx_min."
fi

#
# Setup the sxt devices
#
if [ -d $sxt_dir ] ; then
	rm -r $sxt_dir		# remove old devices
fi
mkdir $sxt_dir
for shl_device in 0 1 2 3 4 5 6 7 8 ; do
	mknod $sxt_dir/00$shl_device c $sxt_maj $shl_device
done

#
# Rewind tape.
#
echo -n "Rewinding tape ... "
mt -f $TapeDevice rew > /dev/null 2>&1
mt -f $TapeDevice status > /dev/null 2>&1
echo "Done."

Vmunix=`(cd $InstallDir ; echo vmunix.*)`
if [ "$Vmunix" != "" ] ; then
	echo "
Before you can run these System V utilities you must do the following.
Save the old /vmunix someplace if you want.  Some people find it
reassuring to have their old kernel around when they first boot a new
kernel.  Then copy one of these file
	$Vmunix
from
	$InstallDir 
to /.  
Now reboot the system after everyone has logged off the system.
"
fi
echo "
The installation is now complete."
exit 0
