:
# "INSTALL", a shell script which generates another shell script to
#            perform Phase I of the iDIS R2.0 installation -- the
#            extraction of iDIS R2.0 iBASE software from any media.
#            (Phase II is performed afterwards depending upon installation
#            scenario: either by End-User XENIX's SCP, or by request
#            at the end of Phase I installation, or by manual invocation)

# Copyright 1983, 1986 Intel Corporation.

# 04/15/86  gll  Rewritten to conform with requirement for End-User
#                XENIX 3.4, OpenNET Networking, and iDIS R2.0.
# 04/24/86  gll  Made temporary modifications to support a BETA
#                release without a Logical Network Administrator.
#                (to undo, find places marked G001)
# 05/24/86  gll  Revised to remove temporary mods, and make invoke 
#                configure.idis everytime.  Also reworded messages
#                to allow for multi-media installations.
# 07/01/86  gll  Corrected a typo.  Inserted linefeeds in displayed messages
#                here and there.  Also move configure.idis to root
#                first in case of stand-alone system so iBASE directory
#                can be removed at end.
# 08/11/86  gll  Prevent overinstalls of Standalone and Logical Net Masters.
#                Look for pre-loaded systems and skip tar if so.

PhaseI=y
export PhaseI
idisvers="iBASE R2.0, V1.0"
export idisvers

# If requested, list the options available with this command.

if [ "$1" = "-o" -o "$1" = "-O" ]
then echo "
usage: sh INSTALL [-o] [-n] [-f <tar_file_path>] 

  If -o is specified, these options will be listed.  The -o option
   should be the first one listed if used.
  If -n is specified, its ignored since we do not build a kernel.
  If -f is specified, tar input will be from <tar_file_path>.
"
     exit 1
fi

#    This utility is pulled off of the installation media via 
#                 "tar xvf /dev/dvf0  INSTALL"
#    and executed as follows:
#                 "sh INSTALL [-y] [-n] [-f] [-o]"
#
#                  [-y] = ignored, available for compatibility.
#                  [-n] = ignored, available for compatibility.
#                  [-f] = specify input device 
#                  [-o] = list these options
#
#    Its  task is to pull all of  the iDIS R2.0 iBASE files and libraries
#    off  of the media  set.

# Below, several path variables are set up to facilitate this installation.
#
# Any of the desired paths may be altered simply by changing the appropriate
# variable below.  For example, the iDIS menu system could be relocated
# simply by changing the 'iDIS' variable below.

rootpath="/"
tmppath=${rootpath}tmp
etcpath=${rootpath}etc
usrpath=${rootpath}usr
syspath=${rootpath}sys
devpath=${rootpath}dev

iDIS=${usrpath}/iDIS
iDISBOOT=${rootpath}iDISboot
ibasepath=${iDIS}/iBASE

devnullpath=/dev/null

export rootpath tmppath etcpath syspath usrpath devpath iDIS ibasepath
export devnullpath iDISBOOT

#
#    The iDIS media was built assuming the standard
#    structure relative to rootpath as shown below.  
#
#    The default values set assume the following base structure:
#
#		             / ($rootpath)
#                            |
#                            +-----+
#		             |     |
#                           usr   sys
#                            |
#               +-----+------+-------+
#               |     |      |       |
#              etc   dev   iDIS   update
#                            |
#                          iBASE
#                            |
#            +----------+----+--+-----+------+
#            |          |       |     |      |
#         iDISboot   iDISbin   etc   iDIS   usr
#
#
# WARNINGS:
#
#    When  this script  tars in  the iDIS R2.0 media,  the above
#    structure relative to rootpath will be created if they are required.  
#
#    When Phase I of the iDIS installation is complete, iDIS is NOT
#    ready to use.  Phase II of iDIS installation, the configuration
#    step performed later, will enable the iDIS software.
#

# Make sure /usr is mounted.

$etcpath/mount $devpath/usr $usrpath 2>$devnullpath
sync

#    The following  determines the update  path, we will  attempt to find
#    the zaplog first in /usr/update/zaplog.    If  not  there,  we  will
#    attempt to find it  in /update/zaplog.   updatepath  will be  set up
#    according to  where we found the zaplog.   If no zaplog is found, we
#    will build a zaplog in /usr/update.  

#    IF updatepath IS /update/zaplog, we will ask if this is a -17, 
#    and if the response is yes, we will abort installation of iDIS.

if [ -f $usrpath/update/zaplog ]
then updatepath=$usrpath/update
else if [ -f ${rootpath}update/zaplog ]
     then updatepath=${rootpath}update
          echo -n "
Is this system a model 286/310-17 ( yes | no ) ? "
          read resp
          echo "$resp" >> $updatepath/zaplog
          case $resp in yes | y | YES | Y ) echo "
The $idisvers software cannot be sucessfully installed on the
Intel 286/310-17.  Please contact your Intel representative 
for further information.

*** Installation of $idisvers software stopped. ***"
                                            exit 1
                                            ;;
          esac
     else mkdir ${usrpath}/update 2>$devnullpath
          updatepath=${usrpath}/update
     fi
fi

export updatepath

echo "
A log of all screen output you will see during the installation of
$idisvers is being made in $updatepath/zaplog.
"

if [ "${timeOK-n}" = "n" ]
then echo "
In order to ensure proper installation, please verify time.
"
# Make sure date/time is correct.

     asktime
     timeOK=y export timeOK
fi

#   Now that we have a path to the zaplog, we want to log all output
#   in zaplog.  In order to do this, we cat from here to end into the
#   file $tmppath/instlidis.tmp and execute it via:
#
#   sh $tmppath/instlidis.tmp $* 2>&1 | tee -a $updatepath/zaplog

cat <<\INSTALLEND >$tmppath/instlidis.tmp
:
# "instlidis.tmp", a shell script to extract iDIS R2.0 iBASE software
#                  from the installation media and perform installation
#                  procedures.

# Copyright 1983, 1986 Intel Corporation.

echo "
==============================================================================
Starting installation of $idisvers
`date`
=============================================================================="

tarpath="$devpath/dvf0"
PhaseII=y

while [ $# != 0 ]
do
   case $1 in -y* | -Y*) # There is no optional interaction in Phase I
                         # of iDIS installation, so -y is ignored.
	                 ;;

      -d | -D | -f | -F) # Get source from another device or node.
                         # (perhaps //bertha/dev/dvf0)
                         shift
                         tarpath=$1	
                         if [ "O$tarpath" = "O" ]
                         then echo "
The -f option requires <tar_file_path>."
                              exit 1
                         fi
                         echo "
$idisvers will be taken from $1"
                         ;;

                -n | -N) # There is no kernal build during iDIS
                         # installation, so -n is ignored.
                         ;;

                      *) echo "
Option ($1) is unknown or in wrong position.

usage: sh INSTALL [-o] [-n] [-f <tar_file_path>] 

  If -o is specified, these options will be listed.  The -o option
   should be the first one listed, if used.
  If -n is specified, interactive iDIS configuration will not be started.
  If -f is specified, tar input will be from <tar_file_path>.
"
                         exit 1
                         ;;
    esac
    shift
done

#	Make sure XENIX 3.4 has been installed.

if grep "XENIX_R3.4" $syspath/conf/xenixconf >$devnullpath
then : continue
else echo -n "
XENIX R3.4 must be installed before installing iDIS R2.0!
(XENIX_R3.4 was not found in $syspath/conf/xenixconf).

If XENIX R3.4 has been installed, you may continue.

If not, please install XENIX R3.4 and then restart this installation.

Do you wish to continue the installation procedure?  

   ('y' or 'yes' to continue) => "
     read ok
     echo "$ok \n" >> $updatepath/zaplog
     case $ok in y* | Y*) echo "
$idisvers installation proceeding." 
                          ;;

                       *) echo "
$idisvers installation stopped."
                          exit 1
                          ;;
     esac
fi

# Make sure iDISgw driver has been installed, else stop.

save=$*
set Start `grep "^iDISgw" /sys/conf/xenixconf`
if [ "$2" = "iDISgw" ]
then if [ "${3-0}" != "1" ]
     then echo "
The iDIS Group Workareas driver, iDISgw, has not been configured into
the xenix kernel.

Enable the iDISgw driver, then try again."
          exit 1
     fi
else echo "
The iDIS Group Workareas driver, iDISgw, has not been installed.

Install iDISgw, then try again."
     exit 1
fi
if [ "$save" != "" ]
then set $save
fi

sync

# Rename ourselves to avoid getting clobbered when we read in
# the remaining files.

mv INSTALL INSTALL- 2>$devnullpath
cp INSTALL- INSTALL 2>$devnullpath

# Determine if this is to be a network node, and if so, find out
# whether its a network master, sub-net master, or sub-ordinate
# node.  The assumption is that if 'ec' is enabled in the
# xenixconf file, then this is an OpenNET node.

#set Start `grep "^OpenNET" /usr/intel/scp/configurations/current`
c=`grep -c "^OpenNET" /usr/intel/scp/configurations/current`

if [ "$c" != "0" ]
  then OpenNET=1
  else OpenNET=0           # Assume stand-alone if OpenNET not found.
fi

# We now know if OpenNET has been installed.  

if [ $OpenNET -eq 1 ]
then resp=
     while [ "$resp" != "valid" ]
     do
        echo -n "
Is this the master node for all of the sub-networks (yes | no)? "
        read resp
        echo $resp >> $updatepath/zaplog
        case $resp in y* | Y*) LNMASTER=y
                               resp=valid
                               ;;
                      n* | N*) LNMASTER=n
                               resp=valid
                               ;;
                      q* | Q*) echo "
$idisvers installation has been stopped."
                               exit 1
                               ;;
        esac
     done

          if [ "$LNMASTER" = "n" ]
          then resp=
               while [ "$resp" != "valid" ]
               do echo -n "
According to your answer, you are incorrectly attempting to install
iDIS from an external media such as diskettes or tape.  The installation
of $idisvers software from such media should only be done on the master
node for the entire network.

$idisvers installation has been stopped.

Press RETURN to continue ..."
                                    read resp
                                    exit 1
            done
         fi
else   # did not find OpenNET s/w.
   echo -n "
The OpenNET software was not found on this system.\n"
   resp=
   while [ "$resp" != "valid" ]
     do
        echo -n "
Do you wish to use this system as a stand-alone system? (y or n): "
        read resp
        echo $resp >> $updatepath/zaplog
        case $resp in y* | Y*) LNMASTER=n
                               resp=valid
                               ;;
                      n* | N*) echo " 
In order to make this a network node, You must first install 
OpenNET R2.0 software before proceeding with iDIS R2.0 software 
installation. $idisvers installation has been stopped."
                               exit 1 
                               ;;
                      q* | Q*) echo "
$idisvers installation has been stopped."
                               exit 1
                               ;;
        esac
     done

fi

node=`cat $etcpath/systemid`
systemid=$node

if [ "$LNMASTER" = "y" ]
then word=node
else word=system
fi

# Check for previous installation of iDIS software.

# Start by assuming no previous installations.

piDIS=n

# Now look for iDIS R1.6

if [ -d ${rootpath}iDISbin ]
then echo "
Previously installed iDIS software found in /iDISbin on $word $node."
     piDIS=y
fi

# Look for overinstall of iDIS R2.0

if [ -d ${usrpath}/iDISbin ]
then echo "
Previously installed iDIS software found in /usr/iDISbin on $word $node."
     piDIS=y
fi

if [ -d ${rootpath}iDISboot -a "$modnod" != "y" ]
then echo "
Previously installed iDIS software found in /iDISboot on $word $node."
     piDIS=y
fi

# See if OpenNET Configuration files are as per instructions.

if [ "$LNMASTER" = "y" ]
then # Check the config files.
     if [ ! -f ${rootpath}net/data ] ; then
	echo "\nThe nameserver database file (${rootpath}net/data) does not exist on node $node."
	echo "You must create the nameserver database entries for node $node in ${rootpath}net/data file"
	echo "according to the installation instructions."
	piDIS=y
     else
        set A `sed -e "/^$systemid/d" ${rootpath}net/data | wc`
        numentry=$2

        if [ $numentry -ne 0 ]
        then echo "
There are nodes improperly listed in the nameserver database on node $node."
             piDIS=y
        fi
     fi

     if [ ! -f ${rootpath}net/cdf ] ; then
	echo "\nThe consumer definition file (${rootpath}net/cdf) does not exist on node $node."
	echo "You must create the consumer entry for node $node in ${rootpath}net/cdf file"
	echo "according to the installation instructions."
	piDIS=y
     else
        set A `wc ${rootpath}net/cdf`
        numentry=$2

        if [ "$execnod" = "y" -o "$usernod" = "y" ]
        then if [ $numentry -ne 0 ]
             then echo "
There are nodes improperly listed in the consumer definition file on node $node."
                  piDIS=y
             fi
        else if [ $numentry -gt 1 ]
             then echo "
There are nodes improperly listed in the consumer definition file on node $node."
                  piDIS=y
             else if [ $numentry -lt 1 ]
                  then echo "
This node's entry to the consumer definition file is missing on node $node."
                       piDIS=y
                  else numentry=`grep -c $node ${rootpath}net/cdf`
                       if [ $numentry -eq 0 ]
                       then echo "
The node listed in the consumer definition file is incorrect on node $node."
                            piDIS=y
                       fi
                  fi
             fi
        fi
     fi
fi

# Now see if we found anything and if so, abort.

if [ "$piDIS" = "y" ]
then echo -n "
This installation cannot be completed for the above reasons.

Press RETURN to continue ...\007"

     read resp
     exit 1
fi

echo "
Starting extraction of $idisvers software ...
"

cd $usrpath
if [ ! -d $iDIS ]
then mkdir $iDIS $ibasepath
     chmod 755 $iDIS $ibasepath
     chgrp 800 $iDIS $ibasepath
     chown 800 $iDIS $ibasepath
     preload=n
else if [ ! -d $ibasepath ]
     then mkdir $ibasepath
          chmod 755 $ibasepath
          chgrp 800 $ibasepath
          chown 800 $ibasepath
	  preload=n
     else # iBASE already here, assume pre-loaded.
	  echo "
Directory /usr/iDIS/iBASE found, assuming pre-loaded system ..."
          preload=y
     fi
fi

cd $ibasepath
umask 0000
    
if [ "$preload" = "n" ]
then ok=
     while : # (true)
     do
       case $ok in n* | N* ) break
                             ;;

                   s* | S* ) echo "
$idisvers installation stopped."

                             exit 1
                             ;;

                          *) if tar -xvf $tarpath
                             then sync
                                  if [ -f $tarpath ]
                                  then break
                                  fi
                                  echo -n "
Insert the next volume of the $idisvers installation media, then
press RETURN (type 'no' if there are no more volumes to be installed): "
                                  read ok
                                  echo "$ok" >> $updatepath/zaplog
                                  echo
                             else echo  -n "
Error while reading from ${tarpath}!

Re-insert the current volume of the installation media, then press RETURN
to retry (type 'stop' to give up): "
                                  read ok
                                  echo "$ok" >> $updatepath/zaplog
                             fi
                             ;;
        esac
      done
fi
sync

# Indicate that Phase I of the iDIS installation has completed.
# (This may need to be changed to accomodate the 'info' file)

a=`pwd`
if [ -d $usrpath/intel/scp/configurations ]
then cd $usrpath/intel/scp/configurations
     if [ -f current ]
     then cp current current.bidis
          sed -e /iBASE/d current > current.new
          mv current.new current
     fi
     if [ "$LNMASTER" = "n" ]
     then echo "iBASE,$idisvers,Stand-alone System,`date`" >>  current
     else echo "iBASE,$idisvers,Logical Network Master,`date`" >>  current
     fi
fi
cd $a

echo "
$idisvers extraction complete."

if [ "$PhaseII" = "y" ]
then cd $ibasepath
     if [ -f configure.idis ]
     then copy -o configure.idis /
          chmod 700 /configure.idis
          sh /configure.idis
     else echo "
Could not find the iBASE configuration program!"
     exit 1
     fi
fi

INSTALLEND
sh $tmppath/instlidis.tmp $* 2>&1 | tee -a $updatepath/zaplog
rm -f $tmppath/instlidis.tmp
chmod 440 INSTALL INSTALL- $ibasepath/INSTALL 2> $devnullpath
sync
sync
