#
# tape installation stage 2 (setup.t2 and baseexec)
#
# Modification history:
#	02-13-87 by ACW - made each set of device files explicitly
#	03-23-87 by ACW - made floppy device files for number of drives in 
#			  system
#	05-15-87 by ACW - added tests to determine whether the critical steps
#			  in this routine have executed correctly. The script
#			  will terminate in most cases if an error occurs.
#	11-27-87 by ACW - combined setup.t2 and baseexec into a single script,
#			  included initialisation of network and creation of 
#			  network devices.
#	12-09-87 by ACW - removed all invocations of dev.mk with the exception
#			  of fd2 (if required). All basic system devices are
#			  listed in 'devfiles', and cpio does all the work of
#			  creating and linking them
#

#
# Find out how many floppy drives are installed in the current and system, and
# make special device files accordingly. This should prevent an uninitiated
# user from reading or writing a non-existent floppy.
#
echo "\n"
while true
do
  echo "Please enter the number of floppy drives "
  echo "in the current system [1 or 2]:\07 \c"
  read ANS
  case "$ANS" in
    "1"|"2") break 
	     ;;
     *) echo "Invalid response"
	;;
  esac
done
echo
if [ "$ANS" = "2" ]
then 
    cd /dev
    if make -i -f dev.mk fd2
    then
    	:
    else
    	echo "An error has occurred while making \"fd2\" device files."
        echo "Please retry this setup."
	exit 1
    fi
fi

cd /
if mount /dev/dsk/0s3 /usr
then
    :
else
    echo "An error has occurred while attempting to mount the third partition"
    echo "of the boot winchester as /usr."
    echo "Exiting..."
    exit 1
fi
#
# The following call to stty has been added to facilitate entering the date.
# That is, if a mistake is made whilst entering the date, the backspace key
# will do what you expect.
#
stty erase "^H" 
trap "" 2
TZ=GMT0GDT ; export TZ

while true
do
    echo "Is the timezone" $TZ "correct? (y or n) \c"
    read reply
    case "$reply" in
	"y") break 
	     ;;
	"n") echo "Enter the correct timezone"
	     echo "Where SSS (WWW) denote the summer (winter) timezones. (3 letters each)"
	     echo "nn is the number of hours difference between your timezone and GMT." 
	     echo "Positive for west of GMT, negative for east of GMT."
	     echo "(WWWnnSSS): \c"
	     read TZ
	     echo 'TZ='$TZ '; export TZ' > /etc/TIMEZONE
	     export TZ
	     ;;
	*) echo "Invalid response"
	   ;;
    esac
done

date `/etc/time` >/dev/null

while true
do
    echo "Is the date `date` correct? (y or n) \c"
    read reply
    case "$reply" in
	"y") break 
	     ;;
	"n") echo "Enter the correct date: (MMddhhmmyy) \c"
	     read reply
	     date "$reply" >/dev/null
	     date +%m%d%H%M%y >/etc/odate
	     date +%m%d%H%M%y >/dev/time
	     ;;
	*) echo "Invalid response" 
	   ;;
    esac
done

set -x
cd / ; mklost+found ; chmod 775 /
cd /usr ; mklost+found
cd /
set +x

#
# This script contained statements to build "sxt" devices if they did not 
# already exist. This has been removed as the file "dev.mk", which is invoked
# earlier, does the same job.
#
#
# Initialise the principal network files if this is a network system
#
if [ -f /net/CubixInitE ]
then
    if grep ntty /etc/inittab.m > /dev/null
    then
	:
    else
	echo "20:23:off:/etc/getty ntty0 9600" >> /etc/inittab.m
	echo "21:23:off:/etc/getty ntty1 9600" >> /etc/inittab.m
	echo "22:23:off:/etc/getty ntty2 9600" >> /etc/inittab.m
	echo "23:23:off:/etc/getty ntty3 9600" >> /etc/inittab.m
	echo "24:23:off:/etc/getty ntty4 9600" >> /etc/inittab.m
	echo "25:23:off:/etc/getty ntty5 9600" >> /etc/inittab.m
	echo "26:23:off:/etc/getty ntty6 9600" >> /etc/inittab.m
	echo "27:23:off:/etc/getty ntty7 9600" >> /etc/inittab.m
	echo "28:23:off:/etc/getty ntty8 9600" >> /etc/inittab.m
	echo "29:23:off:/etc/getty ntty9 9600" >> /etc/inittab.m
	echo "30:23:off:/etc/getty nttya 9600" >> /etc/inittab.m
	echo "31:23:off:/etc/getty nttyb 9600" >> /etc/inittab.m
	echo "32:23:off:/etc/getty nttyc 9600" >> /etc/inittab.m
	echo "33:23:off:/etc/getty nttyd 9600" >> /etc/inittab.m
	echo "34:23:off:/etc/getty nttye 9600" >> /etc/inittab.m
	echo "35:23:off:/etc/getty nttyf 9600" >> /etc/inittab.m
    fi

    if sh /net/CubixInitE
    then
	:
    else
	echo "An error has occurred while initialising the network files."
	echo "Please try this script again."
	exit 1
    fi
fi

>/etc/install.date
chmod 444 /etc/install.date
sync; sync; sync
umount /dev/dsk/0s3
trap 2
mv /etc/inittab /etc/inittab.s
if cp /etc/inittab.m /etc/inittab
then
    :
else
    echo "An error has occurred during the installation of the multi-user"
    echo "inittab. You will need to install an appropriate inittab before"
    echo "typing 'init 2'."
fi
if echo 100 > /etc/.nextid
then
    :
else
    echo "An error has occurred while setting up the index value for the"
    echo "utility Addusr. Before using this utility you should ensure that"
    echo "the file /etc/.nextid contains the value 100."
fi
echo "The installation should now be complete. "
echo "If everything is OK type 'init 2', and the"
echo "system will go multi-user"
echo "login as: root"
echo "password: root"
echo "If you had problems you may rerun this script by typing /bin/setup_."
mv -f /bin/setup.3 /bin/setup
sync;sync;sync
