#!/bin/csh -f
#
# A script to install the VMEIO software on a TMC CMIOP system.
# Don't run this on anything other than a CMIOP!
#

# ----------------------------------------------------------------------------
set path=(/bin /usr/bin /usr/ucb /usr/local /usr/local/etc /etc /usr/etc .)

set VMEIO_MAJOR=104
set STC_MAJOR=105
set DEBUG=""
set iscmiop = 0

alias BackUpFile 'set now=`date`; if ( ! -f \!*%TMC%${now[2]}_${now[3]}_${now[6]}) sh -c "${DEBUG} mv \!* \!*%TMC%${now[2]}_${now[3]}_${now[6]} && echo \!* saved as \!*%TMC%${now[2]}_${now[3]}_${now[6]}"'
alias CopyBackUpFile 'set now=`date`; if ( ! -f \!*%TMC%${now[2]}_${now[3]}_${now[6]}) sh -c "${DEBUG} cp \!* \!*%TMC%${now[2]}_${now[3]}_${now[6]} && echo \!* saved as \!*%TMC%${now[2]}_${now[3]}_${now[6]}"'

set home = `pwd`
set date = `date`
set whoiam = `whoami`

cat <<EoI
VMEIO 6.1.2 installation procedure

This procedure installs all software to use the VMEIO and StorageTek
hardware on a Thinking Machines CMIOP system.  Software installed includes:

   - CM filesystem user commands
   - CMIOP tape commands
   - CM filesystem libraries and system commands
   - VMEIO, Ciprico, and StorageTek device drivers
EoI

if ("$whoiam" != "root") then
  /bin/echo 'WARNING: You are not "root", this may make it impossible to perform'
  /bin/echo '         the actual installation or configuration.'
  /bin/echo '         You are advised to "su root"\!'
  /bin/echo ""
endif


#-----------------------------------------------------------------------------
# Ask user if she really wants to run this
#-----------------------------------------------------------------------------
qcmiop:
set qtag = cmiop
set q = "Is this install being done on a TMC CMIOP system [y/n/help]? "
set default = "y"
goto ask-y-n

help-cmiop:
   /bin/echo This installation script is tailored to install the VMEIO system
   /bin/echo software on a TMC CMIOP system in certain pre-configured locations.
   /bin/echo If you answer yes to this question, the installation script will
   /bin/echo install the software in the standard location for one of these
   /bin/echo systems without asking for confirmation \(the standard location
   /bin/echo is subdirectories of /usr/local\).  If you answer no, you will
   /bin/echo be prompted for the location of each package.
   goto qcmiop

ret-cmiop:
   set cmiop = 0
   if ( $a ) set iscmiop = 1

qcmiopend:

#-----------------------------------------------------------------------------
# Install user commands
#-----------------------------------------------------------------------------
commands:

set default = "/usr/local/bin"
if ( $iscmiop ) goto do-commands

qcommands:
set qtag = "commands"
set q = "Location to install user and tape commands (path,skip) ?"
goto ask

help-commands:
   /bin/echo This component of the software consists of the CMFS UNIX-equivalent
   /bin/echo commands such as cmls, cmcp, etc, and the tape utilities cmdd
   /bin/echo and ibmtape.  Much of this software is released with the base system
   /bin/echo software, so if you're installing this on a front-end machine
   /bin/echo feel free to skip this phase.
   goto qcommands

ret-commands:

if ( "$a" != "$default" ) set default = $a

do-commands:

/bin/echo
/bin/echo Installing user commands and tape software in $default

mkdir -p $default
(cd ${home}/usr/bin; tar cf - .) | (cd $default; tar xBpf -)

#-----------------------------------------------------------------------------
# Install system commands, verifiers
#-----------------------------------------------------------------------------
syscmds:

set default = "/usr/local/etc"
if ( $iscmiop ) goto do-syscmds

qsyscmds:
set qtag = "syscmds"
set q = "Location to install system commands and verifiers (path,skip) ?"
goto ask

help-syscmds:
   /bin/echo This component of the software consists of the CM2 fileserver and
   /bin/echo error logger, diagnostics and configuration software for the VMEIO
   /bin/echo hardware, and system verifiers for the StorageTek tape system and
   /bin/echo associated hardware.  These tools are generally run as root by the
   /bin/echo system administrator, and with the exception of the fileserver are
   /bin/echo not shipped with the base system.
   goto qsyscmds

ret-syscmds:

if ( "$a" != "$default" ) set default = $a

do-syscmds:

/bin/echo
/bin/echo Installing system commands and verifiers in $default

mkdir -p $default
(cd ${home}/usr/etc; tar cf - .) | (cd $default; tar xBpf -)

#-----------------------------------------------------------------------------
# Install libcmfs and friends
#-----------------------------------------------------------------------------
lib:

set default = "/usr/local/lib"
if ( $iscmiop ) goto do-lib

qlib:
set qtag = "lib"
set q = "Location to install CMFS library (path,skip) ?"
goto ask

help-lib:
   /bin/echo This component of the software is the CMFS library and the
   /bin/echo parallel \"stubs\" object file.  If you're installing on a front-end,
   /bin/echo you can skip this section.
   goto qlib

ret-lib:

if ( "$a" != "$default" ) set default = $a

do-lib:

/bin/echo
/bin/echo Installing library files in $default

mkdir -p $default

cp ${home}/usr/lib/libcmfs-6104.a $default
ranlib -t $default/libcmfs-6104.a
cp ${home}/usr/lib/libcmfs-6104-pg.a $default
ranlib -t $default/libcmfs-6104-pg.a
cp ${home}/usr/lib/libcmfs-stubs.o $default

#-----------------------------------------------------------------------------
# Install misc. header files
#-----------------------------------------------------------------------------
hdr:

set default = "/usr/include"
if ( $iscmiop ) goto do-hdr

qhdr:
set qtag = "hdr"
set q = "Location to install header files (path,skip) ?"
goto ask

help-hdr:
   /bin/echo This component consists of various CMFS-specific header files.
   /bin/echo They are only used if you intend to write CMFS programs to run
   /bin/echo on the CMIOP\; they can be skipped if you are only using the
   /bin/echo tape utilities.
   goto qhdr

ret-hdr:

if ( "$a" != "$default" ) set default = $a

do-hdr:

/bin/echo
/bin/echo Installing header files in $default

mkdir -p $default
mkdir -p $default/cm
cp ${home}/usr/include/cm/* $default/cm


#-----------------------------------------------------------------------------
# Update system files
#-----------------------------------------------------------------------------
sysfiles:

if ( $iscmiop ) goto do-sysfiles

qsysfiles:
set qtag = sysfiles
set q = "Do you want to update the system files (rc.local, crontab, etc)? "
set default = "y"
goto ask-y-n

help-sysfiles:
   /bin/echo The installation script will automatically update the rc.local
   /bin/echo startup script on your system to automatically start a fileserver,
   /bin/echo and error logger, and to configure the VMEIO board in your system.
   /bin/echo It will also start a cron job to rotate any log files that are
   /bin/echo created.  This part may be safely skipped, but the VMEIO board
   /bin/echo should always be configured to a known state after the reboot
   /bin/echo of a system.
   goto qsysfiles

ret-sysfiles:

if( "$a" == "n" ) goto end-sysfiles

do-sysfiles:

csh ./update-system-files

end-sysfiles:


#-----------------------------------------------------------------------------
# Update the kernel
#-----------------------------------------------------------------------------
kernel:

if ( $iscmiop ) goto do-kernel

qkernel:
set qtag = kernel
set q = "Do you want to build a kernel for this system (y/n)? "
set default = "y"
goto ask-y-n

help-kernel:
   /bin/echo To use the VMEIO hardware, you need to install the VMEIO device
   /bin/echo driver on your system.  If you choose \"yes\", the installation script
   /bin/echo will modify the appropriate kernel files and build a sample kernel
   /bin/echo called \"CMIOP\" that you can use.  However, if you have any custom
   /bin/echo device drivers installed on your system, you will have to install
   /bin/echo the device driver manually.  You can still install with this script,
   /bin/echo but the references to any non-Sun device drivers in conf.c will be
   /bin/echo removed \(and conf.c will be backed up\).
   goto qkernel

ret-kernel:

if ( ! $a ) goto byebye

do-kernel:

csh ./update-device-driver

byebye:
 

exit


#==========================================================================
# question asker. setup beforehand: q (question text), default (default answer) and
# qtag (question name). does a "goto ret-$qtag" on success, does a "goto help-$qtag"
# if the user asked for help. Returns users response in variable 'a'.

ask:
/bin/echo ""
reask:
/bin/echo -n "$q [$default] : "
set a = $<
if ("$a" == "") then
  if ("$default" != "") then
    set a = "$default"
  else
    /bin/echo '?There is no default'
    goto reask
  endif
endif
if (("$a" == "quit") || ("$a" == "QUIT") || ("$a" == "Quit")) goto abort
if ( "$a" == "\!" ) then
  echo 'Entering CSH subshell. Type ctrl-D or "exit" to return.'
  csh -i
  echo "\!"
  echo ""
  goto reask
endif
if (("$a" == "Y") || ("$a" == "YES") || ("$a" == "Yes") || ("$a" == "y") || ("$a" == "yes")) set a = 1
if (("$a" == "N") || ("$a" == "NO") || ("$a" == "No") || ("$a" == "n") || ("$a" == "no")) set a = 0
if (("$a" == "?") || ("$a" == "help") || ("$a" == "HELP")) then
  /bin/echo ""
  goto help-$qtag
endif
goto ret-$qtag

#yes/no version. sets "a" to 1 (yes) or 0 (no), otherwise, same as ASK above
ask-y-n:
/bin/echo ""
reask-y-n:
/bin/echo -n "$q [$default] : "
set a = $<
if ("$a" == "") then
  if ("$default" != "") then
    set a = "$default"
  else
    /bin/echo '?There is no default'
    goto reask-y-n
  endif
endif
if (("$a" == "?") || ("$a" == "help") || ("$a" == "HELP")) then
  /bin/echo ""
  goto help-$qtag
endif
if ("$a" == "\!") then
  echo 'Entering CSH subshell. Type ctrl-D or "exit" to return.'
  csh -i
  echo "\!"
  echo ""
  goto reask-y-n
endif
if (("$a" == "quit") || ("$a" == "QUIT") || ("$a" == "Quit")) goto abort
if (("$a" == "Y") || ("$a" == "YES") || ("$a" == "Yes") || ("$a" == "y") || ("$a" == "yes")) then
    set a = 1
else if (("$a" == "N") || ("$a" == "NO") || ("$a" == "No") || ("$a" == "n") || ("$a" == "no")) then
    set a = 0
else
    /bin/echo 'Please answer "yes" or "no"'
    goto reask-y-n
endif
endif
goto ret-$qtag
