#! /bin/csh
# This script installs the CM Base System Software.
# Usage:  install-cm-bss <CM-runtime-tree>
#   where CM-runtime-tree is a directory containing the runtime system files

# ---------------- VERSION and CONFIG INFO ------------------
# Legal release version (comments and displays only)
set version = "6.1"
# TMC manufacturing directory (dir under /XXXmfg0) for local installs only
set reldir = "release-6.1"
# microcode version
set ucode = 6104
# manufacturing runtime directory (under /XXXmfg0/reldir)
set rtdir = cm-runtime-${ucode}
# ----------------- END VERSION and CONFIG ------------------

set self = $0
set today = `date`
set mfgrtdir = $1
set whoiam = `whoami`
set user=$whoiam
set script = "$cwd/do-installation.csh"
unset noclobber
unset install_as_default

onintr abort
#======================================================================
set didnothing = 1

cat <<EoI
CM2 Base System Software Version $version Installation Procedure

This procedure installs and/or configures:
   - Paris libraries, include files, and the FORTRAN/Paris interface
   - All CM2/CM200 Utility Programs (cmattach, etc.)
   - The CM2/CM200 File System libraries and utilites
   - CM2/CM200 Microcode Version ${ucode}
   - The CM2/CM200 Logger facility
   - Automatic startup of CM Daemons and logger
   - The CM Driver
   - Entries in CRONTAB for log rotation and diagnostic runs
   - Manual (man) pages for the CM2/CM200 utilities and Paris functions
   - The NQS batch system

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

# ----------------------------------------------------------------------
# Get machine type, either sun4 or vax and set variable 'machine'
if ( -f /vmb.exe ) then
  set machine="vax"
else if { sun4 } then
  set machine="sun4"
else if { sun4c } then
  set machine="sun4"
endif
if ($?machine) goto havemach
qmach:
set qtag = mach
set q = "Enter machine type (sun4,vax) ?"; set default=""; goto ask
help-mach:
  /bin/echo "Enter the machine type on which you are now running. The response"
  /bin/echo "must be \"sun4\" or \"vax\".
  /bin/echo ""
  goto qmach
ret-mach:
set machine="$a"
if (( "$machine" != "sun4" ) && ( "$machine" != "vax" )) then
  /bin/echo \?Incorrect response, must be \"sun4\" or \"vax\".
  goto qmach
endif
havemach:

#-----------------------------------------------------------------------------
# Figure out release area (user's first arg, in-house allow default)

checkmfg:

# Develop default for mfgrtdir if user did not type first arg
# For in-house use. Default is gross for poor user.
if ("$mfgrtdir" == "") then
  set mfgrtdir_omitted = 1
  if ("$machine" == "sun4") then
    set mfgrtdir = /sunmfg0/$reldir/$rtdir
  else
    if ("$machine" == "vax") then
      set mfgrtdir = /vaxmfg0/$reldir/$rtdir
    else
      /bin/echo "Unknown machine type: "$machine", must be sun4 or vax"
      exit 1
    endif
  endif
else
  set mfgrtdir_omitted = 0
endif

if ( -e $mfgrtdir ) goto mfgexists
/bin/echo 'Cannot find the release runtime directory' $mfgrtdir
wrong_mfg:
if ( $mfgrtdir_omitted ) then
  /bin/echo You omitted the argument to this script.
else
  /bin/echo The argument to this script \($1\) is incorrect.
endif
  /bin/echo It should be the directory into which you read the
  /bin/echo CM runtime software from the tape.
  /bin/echo "Usage: install-cm-bss /{path}/cm-runtime-${ucode}"
qgetmfg:
  set qtag = getmfg
  set q = "Location of the runtime software read from the tape (path) ?"; set default=""; goto ask
help-getmfg:
  /bin/echo Type the directory into which you read the runtime software component
  /bin/echo from the release tape.
  goto qgetmfg
ret-getmfg:
  set mfgrtdir="$a"
  set mfgrtdir_omitted = 0
  /bin/echo ""
  goto checkmfg

mfgexists:
# check that the directory is a release directory
if ( -e $mfgrtdir/install/install-cm-bss ) goto goodmfg
/bin/echo The specified runtime directory $mfgrtdir does not
/bin/echo contain the $version CM runtime software.
goto wrong_mfg

goodmfg:
# Note if release area is a remote disk (if so set remdisk=1)
set remdiskname=`df $mfgrtdir | tail -1`
set remdiskname=$remdiskname[1]
if ($remdiskname =~ *:/*) then
  set remdisk = 1
else
  set remdisk = 0
endif

if ( $remdisk ) then
  /bin/echo "Installing from directory: $mfgrtdir (a remote disk)"
else
  /bin/echo "Installing from directory: $mfgrtdir"
endif
echo "Machine type = $machine"
echo ""

#-----------------------------------------------------------------------------
# We have a release directory!, Give directions...
#-----------------------------------------------------------------------------

/bin/echo For each question below, the possible choices or the format of the
/bin/echo response is given in parentheses. The default taken if RETURN is typed
/bin/echo is shown in square brackets. Answering \"help\" or \"\?\" will describe the
/bin/echo question more fully and give help or advice about answering it.
/bin/echo YES/NO questions can be answered \"y\" or \"n\" if desired.
/bin/echo Answering any question with \"\!\" will invoke a subshell. When
/bin/echo you exit the subshell, the interrupted question will be repeated.
/bin/echo ""
/bin/echo NOTE: As you answer questions, a script is being written to perform the
/bin/echo actual installation/configuration at the end. No files will be copied,
/bin/echo deleted or moved until you confirm at the very end. Until then, typing
/bin/echo ^C^C or responding to a question with \"quit\" will terminate with NO EFFECT.

#----------------------------------------------------------------------
qinstcnf:
set qtag = "instcnf"
set q = "Install software or reconfigure it? (install,config)"; set default="install"; goto ask
help-instcnf:
  /bin/echo You will be asked below where to locate the various CM Base System Software
  /bin/echo components. If you say \"install\" \(the default\), you will actually copy
  /bin/echo software to the locations you specify. If you say \"config\", you will only
  /bin/echo generate the software configuration file \(cm-base-system-config\) to point
  /bin/echo to the components at the specified locations. The latter is used when moving
  /bin/echo already installed components to new locations.
  goto qinstcnf
ret-instcnf:
  if ( "$a" == "config" ) then
    set cnfonly = 1
    set instorcnf = "of"
  else if ( "$a" == "install" ) then
         set cnfonly = 0
         set instorcnf = "to install"
	 touch $script
         if ( ! -w $script ) then
           /bin/echo "ERROR: Cannot write installation script $script"
           goto abort
         endif
	 rm -f $script
         /bin/echo '#! /bin/csh -f' > $script
         /bin/echo "# Generated CM Base System Software Version $version Installation Script" >> $script
         /bin/echo "# Written $today by user '$whoiam'; System type: $machine" >> $script
         /bin/echo "# Installation from directory $mfgrtdir" >> $script
         /bin/echo "set echo" >> $script

       else
         /bin/echo '?Unrecognized response, must be "install" or "config"'
         goto qinstcnf
       endif
  endif
#-----------------------------------------------------------------------------
set locrtdir = "$mfgrtdir"
set copymfg = 0
if ( $cnfonly ) goto q1end

# Only ask about copying the stuff if it is actually remote
if ( ! $remdisk ) goto q1end

q1:
set qtag = 1
set q = "Make a local copy of the runtime SW on this system? (yes or no)"; set default="no"; goto ask-y-n
help-1:
  /bin/echo The CMSS $version runtime system software that was read from the tape is now
  /bin/echo in a directory on a remotely mounted file system \($remdiskname\).
  /bin/echo If you say \"yes\", the distributed software will be copied to a
  /bin/echo directory of your choice on a local disk. The installation will be
  /bin/echo done from this new location. Any files you elect to install as links
  /bin/echo will be linked to this new home. If you do not copy the software,
  /bin/echo all links will be to files within $mfgrtdir,
  /bin/echo and you run the risk of network downtime impairing your ability to use
  /bin/echo the runtine system.
  goto q1
ret-1:
  set copymfg = $a
q1end:
#----------------------------------------------------------------------
q2:
if (! $copymfg) goto skip2
set qtag = 2
set q = "Destination directory for $mfgrtdir/... ?"; set default=""; goto ask
help-2:
  /bin/echo "Enter the directory into which you wish to copy the CM2/CM200 runtime system"
  /bin/echo "software. For example, if you say "/foo/bar", the software will be"
  /bin/echo " copied to /foo/bar/..."
  /bin/echo ""
  goto skip2
ret-2:
  if (! -e $a) then
    /bin/echo "WARNING: $a does not currently exist."
    if ( ! $cnfonly ) /bin/echo "         Please choose another location or spawn a subshell and create the directory."
    goto q2
  else
    if ((! $cnfonly) && (! -w $a)) then
      /bin/echo "WARNING: $a is not writable."
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and change the permissions on the directory."
      goto q2
    endif
  endif
  /bin/echo "pushd $mfgrtdir" >> $script
  /bin/echo "tar cf - . | (cd $a; tar xpBvf -)" >> $script
  /bin/echo "popd" >> $script
  set locrtdir = "$a"
skip2:


#----------------------------------------------------------------------
# Get CM model (CM2 or CM200)
#----------------------------------------------------------------------
qmodel:
set qtag = model
set q = "Enter CM Model (cm2,cm200,cm2/cm200) ?"; set default="cm2"; goto ask
help-model:
  /bin/echo Enter the CM model type for which this software is being installed.
  /bin/echo Your response must be one of \"cm2\" or \"cm200\", or to install to
  /bin/echo support both machine models, type \"cm2/cm200\".
  /bin/echo ""
  goto qmodel
ret-model:
set cmmodel="$a"
if ( "$cmmodel" == "cm2") set cmmodel = "CM2"
if ( "$cmmodel" == "cm200") set cmmodel = "CM200"
if ( "$cmmodel" == "cm2/cm200") set cmmodel = "CM2/CM200"
if (( "$cmmodel" != "CM2" ) && ( "$cmmodel" != "CM200" ) && ( "$cmmodel" != "CM2/CM200" )) then
  /bin/echo \?Incorrect response, must be \"cm2\", \"cm200\", or \"cm2/cm200\".
  goto qmodel
endif
# Construct default machine type for IMPASS (written to config file). It is
# blank of both models are installed for.
set impassmodel = ""
if ( "$cmmodel" == "CM2") set impassmodel = "CM2"
if ( "$cmmodel" == "CM200") set impassmodel = "CM200"
if ( "$cmmodel" == "CM2/CM200") set impassmodel = ""
havemodel:

#-----------------------------------------------------------------------------
# Install the Paris libraries, and the FORTRAN slicewise RTS
#-----------------------------------------------------------------------------
q3:
set qtag = 3
set q = "Location $instorcnf Paris Libraries (path,skip) ?"
set default="/usr/local/lib"; goto ask
help-3:
  /bin/echo The PARIS Libraries are used for linking $cmmodel applications \(other than LISP\).
  /bin/echo If you say \"yes\" the following libraries will be installed:
  /bin/echo '  - The PARIS library libparis.a and its counterpart libparis-pg.a,'
  /bin/echo '    compiled for profiling with gprof.'
  /bin/echo '  - libparisfort.a (and libparisfort-pg.a) which contain'
  /bin/echo '    wrappers that allow PARIS to be called from FORTRAN.'
  /bin/echo '  - Four flavours of libcmrts.a, the slicewise runtime'
  /bin/echo '    system.  There are versions for the CM2 and the CM200,'
  /bin/echo '    and versions compiled -O and -pg.'
  /bin/echo It is recommended that you locate these in
  /bin/echo one of the places that \"ld\" and \"lk\" automatically look for libraries.
  /bin/echo Type \"skip\" to skip installation of libparis\[-pg\].a \(you will
  /bin/echo then have to link with them out of $locrtdir/lib.$machine\).
  goto q3
ret-3:
  set lib_loc = "$locrtdir/lib.$machine"
  if ("$a" == "skip") goto end3b
  if (! -e $a) then
    /bin/echo "WARNING: $a does not currently exist."
    if ( ! $cnfonly ) then
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and create the directory."
      goto q3
    endif
  else
    if ((! $cnfonly) && (! -w $a)) then
      /bin/echo "WARNING: $a is not writable."
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and change the permissions on the directory."
      goto q3
    endif
  endif
  set lib_loc = "$a"
skip3:
#-----------------------------------------------------------------------------
if ( $cnfonly ) goto end3a
q3a1:
set qtag = 3a1
set q = "Do you want to install the PARIS Libraries as the system defaults ?"; set default="yes"; goto ask-y-n
help-3a1:
  /bin/echo If you say \"yes\", the libraries will be installed with the names
  /bin/echo libparis, libparis-pg, libcmfs, libcmfs-pg, and so forth.
  /bin/echo If you say \"no\", they will only be installed as versioned libraries;
  /bin/echo with names libparis2-${ucode}\[-pg\].a, libcmfs-${ucode}\[-pg\].a,
  /bin/echo and so forth.
  goto q3a1
ret-3a1:
  if ( $a ) then
     set install_as_default
  else
     unset install_as_default
  endif
#--------------------------------------------------------------------------
q3a:
set qtag = 3a
set q = "How do you want to install the PARIS Libraries (skip,copy,link) ?"; set default="copy"; goto ask
help-3a:
  /bin/echo If you say \"copy\", libparis\[-pg\].a will be copied to
  /bin/echo $lib_loc/libparis2-${ucode}\[-pg\].a and a symbolic
  /bin/echo link $lib_loc/libparis\[-pg\].a will be created which points to it.
  /bin/echo If you say \"link\", two symbolic links, $lib_loc/libparis\[-pg\].a
  /bin/echo and $lib_loc/libparis2-${ucode}\[-pg\].a, will be created, both pointing
  /bin/echo $locrtdir/lib.$machine/libparis\[-pg\].a.
  /bin/echo If you say \"skip\", libparis\[-pg\].a will not be installed \(you will
  /bin/echo then have to link with them out of $locrtdir/lib.$machine\).
  /bin/echo NOTE: These libraries are each between 10 and 11 megabytes.
  goto q3a
ret-3a:

  if ("$a" == "copy") then
    # --------------------- PARIS library (copy)
    /bin/echo "rm -f $lib_loc/libparis2-${ucode}.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libparis.a $lib_loc/libparis2-${ucode}.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libparis2-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libparis.a $lib_loc/libparis2.a" >> $script
      /bin/echo "pushd $lib_loc; ln -s libparis2-${ucode}.a libparis.a; popd" >> $script
      /bin/echo "pushd $lib_loc; ln -s libparis2-${ucode}.a libparis2.a; popd" >> $script
    endif
    # --------------------- PARIS -PG library (copy)
    /bin/echo "rm -f  $lib_loc/libparis2-${ucode}-pg.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libparis-pg.a $lib_loc/libparis2-${ucode}-pg.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libparis2-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libparis-pg.a $lib_loc/libparis2-pg.a" >> $script
      /bin/echo "pushd $lib_loc; ln -s libparis2-${ucode}-pg.a libparis-pg.a; popd" >> $script
      /bin/echo "pushd $lib_loc; ln -s libparis2-${ucode}-pg.a libparis2-pg.a; popd" >> $script
    endif
    # --------------------- FORTRAN slicewise RTS (copy)
    /bin/echo "rm -f $lib_loc/libcmrts-1.1-CM2-${ucode}.a" >> $script
    /bin/echo "rm -f $lib_loc/libcmrts-1.1-CM2-${ucode}_p.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libcmrts-1.1-CM2-${ucode}.a $lib_loc/libcmrts-1.1-CM2-${ucode}.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libcmrts-1.1-CM2-${ucode}.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libcmrts-1.1-CM2-${ucode}_p.a $lib_loc/libcmrts-1.1-CM2-${ucode}_p.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libcmrts-1.1-CM2-${ucode}_p.a" >> $script

    /bin/echo "rm -f $lib_loc/libcmrts-1.1-CM200-${ucode}.a" >> $script
    /bin/echo "rm -f $lib_loc/libcmrts-1.1-CM200-${ucode}_p.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libcmrts-1.1-CM200-${ucode}.a $lib_loc/libcmrts-1.1-CM200-${ucode}.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libcmrts-1.1-CM200-${ucode}.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libcmrts-1.1-CM200-${ucode}_p.a $lib_loc/libcmrts-1.1-CM200-${ucode}_p.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libcmrts-1.1-CM200-${ucode}_p.a" >> $script
    # --------------------- Checkpointing library (copy)
    /bin/echo "rm -f  $lib_loc/libckpt-${ucode}.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libckpt.a $lib_loc/libckpt-${ucode}.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libckpt-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libckpt.a" >> $script
      /bin/echo "pushd $lib_loc; ln -s libckpt-${ucode}.a libckpt.a; popd" >> $script
    endif
    # --------------------- Checkpointing -PG library (copy)
    /bin/echo "rm -f  $lib_loc/libckpt-${ucode}-pg.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libckpt-pg.a $lib_loc/libckpt-${ucode}-pg.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libckpt-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libckpt-pg.a" >> $script
      /bin/echo "pushd $lib_loc; ln -s libckpt-${ucode}-pg.a libckpt-pg.a; popd" >> $script
    endif
    # --------------------- FE-support library (copy)
    /bin/echo "rm -f  $lib_loc/libcmfe-${ucode}.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libcmfe.a $lib_loc/libcmfe-${ucode}.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libcmfe-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libcmfe.a" >> $script
      /bin/echo "pushd $lib_loc; ln -s libcmfe-${ucode}.a libcmfe.a; popd" >> $script
    endif
    # --------------------- FE-support -PG library (copy)
    /bin/echo "rm -f  $lib_loc/libcmfe-${ucode}-pg.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libcmfe-pg.a $lib_loc/libcmfe-${ucode}-pg.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libcmfe-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libcmfe-pg.a" >> $script
      /bin/echo "pushd $lib_loc; ln -s libcmfe-${ucode}-pg.a libcmfe-pg.a; popd" >> $script
    endif
    # --------------------- C toolkit library (copy)
    /bin/echo "rm -f  $lib_loc/libtoolkit-${ucode}.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libtoolkit.a $lib_loc/libtoolkit-${ucode}.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libtoolkit-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libtoolkit.a" >> $script
      /bin/echo "pushd $lib_loc; ln -s libtoolkit-${ucode}.a libtoolkit.a; popd" >> $script
    endif
    # --------------------- C toolkit -PG library (copy)
    /bin/echo "rm -f  $lib_loc/libtoolkit-${ucode}-pg.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libtoolkit-pg.a $lib_loc/libtoolkit-${ucode}-pg.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libtoolkit-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libtoolkit-pg.a" >> $script
      /bin/echo "pushd $lib_loc; ln -s libtoolkit-${ucode}-pg.a libtoolkit-pg.a; popd" >> $script
    endif
    # --------------------- FORTRAN wrappers library (copy)
    /bin/echo "rm -f  $lib_loc/libparisfort-${ucode}.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libparisfort.a $lib_loc/libparisfort-${ucode}.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libparisfort-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libparisfort.a" >> $script
      /bin/echo "pushd $lib_loc; ln -s libparisfort-${ucode}.a libparisfort.a; popd" >> $script
    endif
    # --------------------- FORTRAN wrappers -PG library (copy)
    /bin/echo "rm -f  $lib_loc/libparisfort-${ucode}-pg.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libparisfort-pg.a $lib_loc/libparisfort-${ucode}-pg.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libparisfort-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libparisfort-pg.a" >> $script
      /bin/echo "pushd $lib_loc; ln -s libparisfort-${ucode}-pg.a libparisfort-pg.a; popd" >> $script
    endif
    # --------------------- CM File System library (copy)
    /bin/echo "rm -f $lib_loc/libcmfs-${ucode}.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libcmfs.a $lib_loc/libcmfs-${ucode}.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libcmfs-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libcmfs.a" >> $script
    /bin/echo "pushd $lib_loc; ln -s libcmfs-${ucode}.a libcmfs.a; popd" >> $script
    endif
    # --------------------- CM File System -PG library (copy)
    /bin/echo "rm -f  $lib_loc/libcmfs-${ucode}-pg.a" >> $script
    /bin/echo "cp $locrtdir/lib.$machine/libcmfs-pg.a $lib_loc/libcmfs-${ucode}-pg.a" >> $script
    /bin/echo "ranlib -t $lib_loc/libcmfs-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libcmfs-pg.a" >> $script
      /bin/echo "pushd $lib_loc; ln -s libcmfs-${ucode}-pg.a libcmfs-pg.a; popd" >> $script
    endif

  else if ("$a" == "link") then
    # --------------------- PARIS library (link)
    /bin/echo "rm -f $lib_loc/libparis2-${ucode}.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libparis.a $lib_loc/libparis2-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libparis.a $lib_loc/libparis2.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libparis.a $lib_loc/libparis2.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libparis.a $lib_loc/libparis.a" >> $script
    endif    
    # --------------------- PARIS -PG library (link)
    /bin/echo "rm -f $lib_loc/libparis2-${ucode}-pg.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libparis-pg.a $lib_loc/libparis2-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libparis-pg.a $lib_loc/libparis2-pg.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libparis-pg.a $lib_loc/libparis-pg.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libparis-pg.a $lib_loc/libparis2-pg.a" >> $script
    endif    
    # --------------------- FORTRAN slicewise RTS (link)
    /bin/echo "rm -f $lib_loc/libcmrts-1.1-CM2-${ucode}.a" >> $script
    /bin/echo "rm -f $lib_loc/libcmrts-1.1-CM2-${ucode}_p.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libcmrts-1.1-CM2-${ucode}.a $lib_loc/libcmrts-1.1-CM2-${ucode}.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libcmrts-1.1-CM2-${ucode}_p.a $lib_loc/libcmrts-1.1-CM2-${ucode}_p.a" >> $script

    if ($machine == "sun4" ) then
      /bin/echo "rm -f $lib_loc/libcmrts-1.1-CM200-${ucode}.a" >> $script
      /bin/echo "rm -f $lib_loc/libcmrts-1.1-CM200-${ucode}_p.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libcmrts-1.1-CM200-${ucode}.a $lib_loc/libcmrts-1.1-CM200-${ucode}.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libcmrts-1.1-CM200-${ucode}_p.a $lib_loc/libcmrts-1.1-CM200-${ucode}_p.a" >> $script
    endif
    # --------------------- FORTRAN wrappers library (link)
    /bin/echo "rm -f $lib_loc/libparisfort-${ucode}.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libparisfort.a $lib_loc/libparisfort-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libparisfort.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libparisfort.a $lib_loc/libparisfort.a" >> $script
    endif    
    # --------------------- FORTRAN wrappers -PG library (link)
    /bin/echo "rm -f $lib_loc/libparisfort-${ucode}-pg.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libparisfort-pg.a $lib_loc/libparisfort-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libparisfort-pg.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libparisfort-pg.a $lib_loc/libparisfort-pg.a" >> $script
    endif    
    # --------------------- Checkpointing library (link)
    /bin/echo "rm -f $lib_loc/libckpt-${ucode}.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libckpt.a $lib_loc/libckpt-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libckpt.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libckpt.a $lib_loc/libckpt.a" >> $script
    endif    
    # --------------------- Checkpointing -PG library (link)
    /bin/echo "rm -f $lib_loc/libckpt-${ucode}-pg.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libckpt-pg.a $lib_loc/libckpt-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libckpt-pg.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libckpt-pg.a $lib_loc/libckpt-pg.a" >> $script
    endif    
    # --------------------- FE-support library (link)
    /bin/echo "rm -f $lib_loc/libcmfe-${ucode}.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libcmfe.a $lib_loc/libcmfe-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libcmfe.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libcmfe.a $lib_loc/libcmfe.a" >> $script
    endif    
    # --------------------- FE-support -PG library (link)
    /bin/echo "rm -f $lib_loc/libcmfe-${ucode}-pg.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libcmfe-pg.a $lib_loc/libcmfe-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libcmfe-pg.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libcmfe-pg.a $lib_loc/libcmfe-pg.a" >> $script
    endif    
    # --------------------- C toolkit library (link)
    /bin/echo "rm -f $lib_loc/libtoolkit-${ucode}.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libtoolkit.a $lib_loc/libtoolkit-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libtoolkit.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libtoolkit.a $lib_loc/libtoolkit.a" >> $script
    endif    
    # --------------------- C toolkit -PG library (link)
    /bin/echo "rm -f $lib_loc/libtoolkit-${ucode}-pg.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libtoolkit-pg.a $lib_loc/libtoolkit-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libtoolkit-pg.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libtoolkit-pg.a $lib_loc/libtoolkit-pg.a" >> $script
    endif    
    # --------------------- CM File System library (link)
    /bin/echo "rm -f $lib_loc/libcmfs-${ucode}.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libcmfs.a $lib_loc/libcmfs-${ucode}.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libcmfs.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libcmfs.a $lib_loc/libcmfs.a" >> $script
    endif    
    # --------------------- CM File System -PG library (link)
    /bin/echo "rm -f $lib_loc/libcmfs-${ucode}-pg.a" >> $script
    /bin/echo "ln -s $locrtdir/lib.$machine/libcmfs-pg.a $lib_loc/libcmfs-${ucode}-pg.a" >> $script
    if ($?install_as_default) then
      /bin/echo "rm -f $lib_loc/libcmfs-pg.a" >> $script
      /bin/echo "ln -s $locrtdir/lib.$machine/libcmfs-pg.a $lib_loc/libcmfs-pg.a" >> $script
    endif    
  else if ("$a" == "skip") then
    goto end3b
  else
    /bin/echo "?Unrecognized response"
    goto q3a
  endif
  endif
  endif
end3a:
#-----------------------------------------------------------------------------
# Figure out if user will screw any existing libraries that are not links

if ( $cnfonly ) goto end3b
if (! $?install_as_default) goto end3b
set libs="$lib_loc/libparis.a $lib_loc/libparis2.a $lib_loc/libparis-pg.a $lib_loc/libparis2-pg.a $lib_loc/libckpt.a $lib_loc/libckpt-pg.a $lib_loc/libparisfort.a $lib_loc/libparisfort-pg.a $lib_loc/libcmfs.a $lib_loc/libcmfs-pg.a"

# deleted libcmsr - scc

set peril = ""
foreach lib($libs)
  if ( ! -e $lib ) goto skiplibc
  ls -l $lib | grep -s '^l'
  if ( $status == 0 ) goto skiplibc
  set peril = "$peril $lib"
  skiplibc:
end
if ("$peril" == "") goto end3b
/bin/echo ""
/bin/echo The following C/FORTRAN libraries exist and are not symbolic links:
ls -l $peril
/bin/echo These will be overwritten by this installation\!
/bin/echo "Type '\!' to get a subshell to fix them, 'yes' to continue, or"
/bin/echo "'no' to terminate the installation script."
set qtag = 3b
q3b:
  set q = "Continue with the installation (no,yes) :"; set default="yes"; goto ask-y-n
  help-3b:
    /bin/echo If you type \"\!\", you will enter a sub-shell \(csh\). 
    /bin/echo There, you may rename any libraries that you want to save.
    /bin/echo The customary procedure is to rename \"mylib.a\" to \"mylib-vvvv.a\"
    /bin/echo and \"mylib-pg.a\" to \"mylib-vvvv-pg.a\" where vvvv is the CM software version.
    /bin/echo If you type \"yes\" this installation will continue.
    goto q3b
  ret-3b:
  if ( ! $a ) goto abort
end3b:

#-----------------------------------------------------------------------------
# Install user executables (cmattach et al)
#-----------------------------------------------------------------------------
q4:
set qtag = 4
set q = "Location $instorcnf user executables (path,skip) ?"; set default="/usr/local/bin"; goto ask
help-4:
  /bin/echo Type the directory where you would like to locate the programs which
  /bin/echo users run to control their usage of the CM, such as \"cmattach\",
  /bin/echo \"cmdetach\", \"cmfinger\", etc. This location should be a directory
  /bin/echo which will be in the users\' search paths. Installation is done
  /bin/echo either by copying the files (which will occupy about 15 megabytes of
  /bin/echo disk) or by linking them to $locrtdir/bin.$machine.
  /bin/echo Type \"skip\" to skip installation of user executables, in which
  /bin/echo case you probably want to put $locrtdir/bin.$machine in the users\'
  /bin/echo search paths).
  goto q4	
ret-4:
  set bin_loc = $locrtdir/bin.$machine
  # "skip" skips the whole thing (next question too)
  if ("$a" == "skip") goto end4a
  set bin_loc = "$a"
end4:
#----------------------------------------------------------------------
q4a:
if ( $cnfonly ) goto end4a
set qtag = 4a
set q = "How do you want to install the User Executables (skip,copy,link) ?"; set default="copy"; goto ask
help-4a:
  /bin/echo If you say \"copy\", each user executable will be copied to
  /bin/echo $bin_loc. If you say \"link\", a symbolic link will be created
  /bin/echo in $bin_loc pointing to the executable in
  /bin/echo $locrtdir/bin.$machine.
  /bin/echo If you say \"skip\", the executables will not be installed, and
  /bin/echo you will want to put $locrtdir/bin.$machine in the
  /bin/echo users\' search paths.
  goto q4a
ret-4a:
  switch ("$a")
    case "skip":
      goto end4a
    case "link":
      if (! -e $bin_loc) then
        /bin/echo "WARNING: $bin_loc does not currently exist."
        if ( ! $cnfonly ) then
          /bin/echo "         Please choose another location or spawn a subshell"
          /bin/echo "         and create the directory."
	  goto q4
	endif
      else
        if ((! $cnfonly) && (! -w $bin_loc)) then
          /bin/echo "WARNING: $bin_loc is not writable."
          /bin/echo "         Please choose another location or spawn a subshell"
          /bin/echo "         and change the permissions on the directory."
	  goto q4
        endif
      endif
      /bin/echo "foreach file ($locrtdir/bin.$machine/*)" >> $script
      /bin/echo "  rm -f $bin_loc/"'$file:t' >> $script
      /bin/echo "  ln -s "'$file'" $bin_loc/"'$file:t' >> $script
      /bin/echo "end" >> $script
      breaksw
    case "copy":
      if (! -e $bin_loc) then
        /bin/echo "WARNING: $bin_loc does not currently exist."
        /bin/echo "         Please choose another location or spawn a subshell"
        /bin/echo "         and create the directory."
	goto q4
      else
        if (! -w $bin_loc) then
          /bin/echo "WARNING: $bin_loc is not writable."
          /bin/echo "         Please choose another location or spawn a subshell"
          /bin/echo "         and change the permissions on the directory."
	  goto q4
        endif
      endif
      /bin/echo "foreach file ($locrtdir/bin.$machine/*)" >> $script
      /bin/echo "  rm -f $bin_loc/"'$file:t' >> $script
      /bin/echo "  cp "'$file'" $bin_loc" >> $script
      /bin/echo "end" >> $script
      breaksw
    default:
      /bin/echo '?unrecognized response, must be "skip", "copy", or "link".'
      goto q4a 
  endsw
end4a:

#-----------------------------------------------------------------------------
# Install system executables (ts-daemon et al)
#-----------------------------------------------------------------------------
q5:
set qtag = 5
set q = "Location $instorcnf system executables (path,skip) ?"; set default="/usr/local/etc"; goto ask
help-5:
  /bin/echo Type the directory where you would like to locate the programs which are
  /bin/echo used by the system administrator or which are invoked automatically by the
  /bin/echo runtime system. This location need NOT \(and should not\) be a directory
  /bin/echo which is in the users\' search paths. Installation is done
  /bin/echo by copying the files which will occupy about 10-15 megabytes of disk.
  /bin/echo Type \"skip\" to skip installation of system executables \(the
  /bin/echo runtime system will execute them from $locrtdir/etc.$machine\).
  goto q5
ret-5:
  set etc_loc = $locrtdir/etc.$machine
  # "skip" skips the whole thing (next question too)
  if ("$a" == "skip") goto end5a
  set etc_loc = "$a"
end5:
#----------------------------------------------------------------------
q5a:
if ( $cnfonly ) goto end5a
set qtag = 5a
set q = "How do you want to install the System Executables (skip,copy,link) ?"; set default="copy"; goto ask
help-5a:
  /bin/echo If you say \"copy\", each system executable will be copied to
  /bin/echo $etc_loc. If you say \"link\", a symbolic link will be created
  /bin/echo in $etc_loc pointing to the executable in
  /bin/echo $locrtdir/etc.$machine.
  /bin/echo If you say \"skip\", the executables will not be installed, and
  /bin/echo you will have to execute them directly from
  /bin/echo $locrtdir/etc.$machine
  goto q5a
ret-5a:
  switch ("$a")
    case "skip":
      goto end5a
    case "link":
      if (! -e $etc_loc) then
        /bin/echo "WARNING: $etc_loc does not currently exist."
        /bin/echo "         Please choose another location or spawn a subshell"
        /bin/echo "         and create the directory."
	goto q5
      else
        if (! -w $etc_loc) then
          /bin/echo "WARNING: $etc_loc is not writable."
          /bin/echo "         Please choose another location or spawn a subshell"
          /bin/echo "         and change the permissions on the directory."
	  goto q5
        endif
      endif
      /bin/echo "foreach file ($locrtdir/etc.$machine/*)" >> $script
      /bin/echo "  rm -f $etc_loc/"'$file:t' >> $script
      /bin/echo "  ln -s "'$file'" $etc_loc/"'$file:t' >> $script
      /bin/echo "end" >> $script
      /bin/echo "rm -f $etc_loc/ts-daemon" >> $script
      /bin/echo "ln -s $etc_loc/ts-daemon-$ucode $etc_loc/ts-daemon" >> $script
      breaksw
    case "copy":
      if (! -e $etc_loc) then
        /bin/echo "WARNING: $etc_loc does not currently exist."
        /bin/echo "         Please choose another location or spawn a subshell"
        /bin/echo "         and create the directory."
	goto q5
      else
        if (! -w $etc_loc) then
          /bin/echo "WARNING: $etc_loc is not writable."
          /bin/echo "         Please choose another location or spawn a subshell"
          /bin/echo "         and change the permissions on the directory."
	  goto q5
        endif
      endif
      /bin/echo "foreach file ($locrtdir/etc.$machine/*)" >> $script
      /bin/echo "  rm -f $etc_loc/"'$file:t' >> $script
      /bin/echo "  cp "'$file'" $etc_loc" >> $script
      /bin/echo "end" >> $script
      /bin/echo "rm -f $etc_loc/ts-daemon" >> $script
      /bin/echo "ln -s $etc_loc/ts-daemon-$ucode $etc_loc/ts-daemon" >> $script
      /bin/echo "rm -f $etc_loc/coldboot-paris" >> $script
      /bin/echo "ln -s $etc_loc/coldboot-paris-$ucode $etc_loc/coldboot-paris" >> $script
      breaksw
    default:
      /bin/echo '?unrecognized response, must be "skip", "copy", or "link".'
      goto q5a 
  endsw
end5a:


#-----------------------------------------------------------------------------
# Install header files
#-----------------------------------------------------------------------------
q6a:
set qtag = 6a
set q = "Location $instorcnf CM2 header files (path,skip) ?"; set default="/usr/include"; goto ask
help-6a:
  /bin/echo Type the directory where you would like to locate the C header files
  /bin/echo used to compile C, C\* and FORTRAN programs for the $cmmodel. If you
  /bin/echo respond \"mydir\", the directory \"mydir/cm\" will be created containing the
  /bin/echo include files. Most existing programs use the syntax \"\#include \<cm/foo.h\>\"
  /bin/echo so you will probably want to install these where the compilers will look for
  /bin/echo them automatically.  Past versions have installed these in /usr/include/cm.
  /bin/echo Installing them elsewhere may cause existing programs to compile incorrectly.
  /bin/echo Installation is done by copying the files which will occupy about 4-6 megabytes
  /bin/echo of disk.  Type \"skip\" to skip installation of the C header files \(they can
  /bin/echo still be read from $locrtdir/include\).
  goto q6a
ret-6a:
  set inc_loc = $locrtdir/include
  if ("$a" == "skip") goto end6c
  if (! -e $a) then
    /bin/echo "WARNING: $a does not currently exist."
    /bin/echo "         Please choose another location or spawn a subshell"
    /bin/echo "         and create the directory."
    goto q6a
  else
    if ((! $cnfonly) && (! -w $a)) then
      /bin/echo "WARNING: $a is not writable."
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and change the permissions on the directory."
      goto q6a
    endif
  endif
  set inc_loc = "$a"
  if ( $cnfonly ) goto end6a
  /bin/echo "if ( ! -e $inc_loc/cm ) mkdir $inc_loc/cm" >> $script
  /bin/echo "foreach file ( $locrtdir/include/cm/*.h )" >> $script
  /bin/echo "  rm -f $inc_loc/cm/"'$file:t' >> $script
  /bin/echo "  cp "'$file'" $inc_loc/cm" >> $script
  /bin/echo "end" >> $script
end6a:

# These are left here for historical purposes (I deleted something)
q6b:
end6b:

#-----------------------------------------------------------------------------
# Figure out if user will screw any existing header files that are not links

if ( $cnfonly ) goto end6c
set hdrs="$inc_loc/cm/paris.h $inc_loc/cm/paris-internal.h"

set peril = ""
foreach hdr($hdrs)
  if ( ! -e $hdr ) goto skiphdrc
  ls -l $hdr | grep -s '^l'
  if ( $status == 0 ) goto skiphdrc
  set peril = "$peril $hdr"
  skiphdrc:
end
if ("$peril" == "") goto end6c
/bin/echo ""
/bin/echo The following C/FORTRAN include files exist and are not symbolic links:
ls -l $peril
/bin/echo These will be overwritten by this installation. To retain the ability to build
/bin/echo applications against the current version of the CM Software, you may want
/bin/echo to rename these files or move them elsewhere.
/bin/echo " "
/bin/echo "Type '\!' to get a subshell to fix them, 'yes' to continue, or"
/bin/echo "'no' to terminate the installation script."
/bin/echo " "
set qtag = 6c
q6c:
  set q = "Continue with the installation (no,yes) :"; set default="yes"; goto ask-y-n
  help-6c:
    /bin/echo If you type \"\!\", you will enter a sub-shell \(csh\). 
    /bin/echo There, you may rename or move include files if you want to.
    /bin/echo The customary procedure is to rename \"incfile.h\" to \"incfile-vvvv.h.\"
    /bin/echo where vvvv is the CM software version.
    /bin/echo If you type \"yes\" this installation will continue.
    goto q6c
  ret-6c:
  if ( ! $a ) goto abort
end6c:


#-----------------------------------------------------------------------------
# Install CM2 microcode
#-----------------------------------------------------------------------------
qcm2ucode:
set cm2_uc_loc = "---not-installed---"
if (("$cmmodel" != "CM2") && ("$cmmodel" != "CM2/CM200")) goto endcm2ucode
set qtag = cm2ucode
set q = "Location $instorcnf CM2 Microcode (skip,path) ?"
# default is to use copy on release directory if local, else copy
set default="skip"

goto ask

help-cm2ucode:
  /bin/echo Type the directory where you would like to locate the CM2 microcode
  /bin/echo and related files. These files are required by the runtime system
  /bin/echo in order to run ANY CM2 program. They can be located anywhere,
  /bin/echo but you may want to avoid unavailablity of these files in the event
  /bin/echo of network downtime by placing them in the local file systems of each
  /bin/echo CM2 host. If the directory you specify does not exist, it will be
  /bin/echo created \(along with all missing parent directories\).
  /bin/echo Type \"skip\" to skip installation of the microcode files \(they will
  /bin/echo be read from $locrtdir/microcode-cm2\).
  if ( "$cmmodel" == "CM2/CM200" ) then
    /bin/echo Note: This is CM2 microcode only, CM200 microcode will be installed next.
  endif
  goto qcm2ucode
ret-cm2ucode:
  set cm2_uc_loc = $locrtdir/microcode-cm2
  if ("$a" == "skip") goto endcm2ucode
  if (! -e $a) then
    if ( $cnfonly ) then
      /bin/echo "WARNING: $a does not currently exist."
    else
      /bin/echo "NOTE: $a does not currently exist"
      /bin/echo "         It will be created during installation"
    endif
  else
    if ((! $cnfonly) && (! -w $a)) then
      /bin/echo "WARNING: $a is not writable."
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and change the permissions on the directory."
      goto qcm2ucode
    endif
  endif
  set cm2_uc_loc = "$a"
  if ( $cnfonly ) goto endcm2ucode
  /bin/echo "if ( ! -e $cm2_uc_loc ) mkdir -p $cm2_uc_loc" >> $script
  /bin/echo "cp $locrtdir/microcode-cm2/* $cm2_uc_loc" >> $script
endcm2ucode:


#-----------------------------------------------------------------------------
# Install CM2 microcode
#-----------------------------------------------------------------------------
qcm200ucode:
set cm200_uc_loc = "---not-installed---"
if (("$cmmodel" != "CM200") && ("$cmmodel" != "CM2/CM200")) goto endcm200ucode
set qtag = cm200ucode
set q = "Location $instorcnf CM200 Microcode (skip,path) ?"
# default is to use copy on release directory if local, else copy
set default="skip"

goto ask

help-cm200ucode:
  /bin/echo Type the directory where you would like to locate the CM200 microcode
  /bin/echo and related files. These files are required by the runtime system
  /bin/echo in order to run ANY CM200 program. They can be located anywhere,
  /bin/echo but you may want to avoid unavailablity of these files in the event
  /bin/echo of network downtime by placing them in the local file systems of each
  /bin/echo CM200 host. If the directory you specify does not exist, it will be
  /bin/echo created \(along with all missing parent directories\).
  /bin/echo Type \"skip\" to skip installation of the microcode files \(they will
  /bin/echo be read from $locrtdir/microcode-cm200\).
  goto qcm200ucode
ret-cm200ucode:
  set cm200_uc_loc = $locrtdir/microcode-cm200
  if ("$a" == "skip") goto endcm200ucode
  if (! -e $a) then
    if ( $cnfonly ) then
      /bin/echo "WARNING: $a does not currently exist."
    else
      /bin/echo "NOTE: $a does not currently exist"
      /bin/echo "         It will be created during installation"
    endif
  else
    if ((! $cnfonly) && (! -w $a)) then
      /bin/echo "WARNING: $a is not writable."
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and change the permissions on the directory."
      goto qcm200ucode
    endif
  endif
  set cm200_uc_loc = "$a"
  if ( $cnfonly ) goto endcm200ucode
  /bin/echo "if ( ! -e $cm200_uc_loc ) mkdir -p $cm200_uc_loc" >> $script
  /bin/echo "cp $locrtdir/microcode-cm200/* $cm200_uc_loc" >> $script
endcm200ucode:

#-----------------------------------------------------------------------------
# Install the Paris lint libraries
#-----------------------------------------------------------------------------
qlint:
set qtag = lint
set q = "Location $instorcnf the $cmmodel lint libraries (path,skip) ?"; set default="/usr/lib/lint"; goto ask
help-lint:
  /bin/echo Libraries for use with lint which contain the PARIS and CMFS
  /bin/echo function and type definitions can be optionally installed. 
  /bin/echo You probably want to install these where lint will look for
  /bin/echo them automatically \(i.e. /usr/lib/lint\).
  /bin/echo Installation is done by copying the libraries to llib-libparis-${ucode}.ln
  /bin/echo and creating a symbolic link llib-lparis.ln which points to it.
  /bin/echo Type \"skip\" to skip installation of the lint libraries \(they can
  /bin/echo still be read from $locrtdir/lint\).
  goto qlint
ret-lint:
  set lint_loc = "$locrtdir/lint"
  if ("$a" == "skip") goto endlint
  if (! -e $a) then
    /bin/echo "WARNING: $a does not currently exist."
    if ( ! $cnfonly ) then
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and create the directory."
      goto qlint
    endif
  else
    if ((! $cnfonly) && (! -w $a)) then
      /bin/echo "WARNING: $a is not writable."
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and change the permissions on the directory."
      goto qlint
    endif
  endif
  set lint_loc = "$a"
  if ( $cnfonly ) goto endlint
  /bin/echo "cp $locrtdir/lint/llib-lparis.ln $lint_loc/llib-lparis2-${ucode}.ln" >> $script
  /bin/echo "rm -f $lint_loc/llib-lparis.ln" >> $script
  /bin/echo "pushd $lint_loc; ln -s llib-lparis2-${ucode}.ln llib-lparis.ln; popd" >> $script
  /bin/echo "cp $locrtdir/lint/llib-cmfs.ln $lint_loc/llib-lcmfs-${ucode}.ln" >> $script
  /bin/echo "rm -f $lint_loc/llib-lcmfs.ln" >> $script
  /bin/echo "pushd $lint_loc; ln -s llib-lcmfs-${ucode}.ln llib-lcmfs.ln; popd" >> $script
endlint:

#----------------------------------------------------------------------
# Install the man pages for the CM commands and Paris functions
#----------------------------------------------------------------------
qman:
set man_loc = "$locrtdir/man"

set trip = 0
set man_list=""
foreach product ($locrtdir/man/*)
  set component=$product:t
  if( $trip == 0 ) then
	set trip = 1
	set man_list=$man_loc/$component
  else
	set man_list=$man_list':'$man_loc/$component
  endif
end

if ( $cnfonly ) goto endman
set qtag = man
set q = "Location $instorcnf the $cmmodel man pages (path,skip) ?"; set default="/usr/local/man"; goto ask
help-man:
  /bin/echo Manual pages for use with the \"man\" program are available for the
  /bin/echo $cmmodel software. The default response \(/usr/local/man\) is man 
  /bin/echo subtree under which the install script will deposit the online
  /bin/echo man pages.  Each layered product will have a subdirectory with a
  /bin/echo man tree in this subdirectory, and the CMOST man pages will be
  /bin/echo installed in the man1 and man8 directories.
  /bin/echo Type \"skip\" to skip installation of the man pages.
  goto qman
ret-man:
  set man_loc = "$locrtdir/man"
  if ("$a" == "skip") goto endman
  if (! -e $a) then
    /bin/echo "WARNING: $a does not currently exist."
    if ( ! $cnfonly ) then
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and create the directory."
      goto qman
    endif
  else
    if ((! $cnfonly) && (! -w $a)) then
      /bin/echo "WARNING: $a is not writable."
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and change the permissions on the directory."
      goto qman
    endif
  endif
  set man_loc = "$a"

  /bin/echo 'set my_cwd = `pwd`' >> $script
  /bin/echo "cd $locrtdir/man" >> $script
  /bin/echo "tar cf - . | (cd $man_loc; tar xfpB -)" >> $script
  /bin/echo 'cd $my_cwd' >> $script

  /bin/echo "mkdir -p $man_loc/man1" >> $script
  /bin/echo "mkdir -p $man_loc/man8" >> $script
  /bin/echo "cp $locrtdir/man/CMOST/man1/"'*.1' "$man_loc/man1" >> $script
  /bin/echo "cp $locrtdir/man/CMOST/man8/"'*.8' "$man_loc/man8" >> $script

  set trip = 0
  set man_list=""
  foreach product ($locrtdir/man/*)
      set component=$product:t
      if( $trip == 0 ) then
	set trip = 1
	set man_list=$man_loc/$component
      else
	set man_list=$man_list':'$man_loc/$component
      endif
  end

endman:

#-----------------------------------------------------------------------------
# Install nqs software
#-----------------------------------------------------------------------------
qnqs:
set nqsusr_dst = $locrtdir/nqsbin.$machine
set nqslib_dst = $locrtdir/nqslib.$machine

if ( $cnfonly ) goto endnqs
set qtag = nqs
set q = "Install the NQS batch system? (yes or no)"; set default="yes";goto ask-y-n
help-nqs:
  /bin/echo If you say \"yes\", the installation procedure will prompt you for a location
  /bin/echo to install the NQS user commands, the NQS administration commands, and the
  /bin/echo associated man pages.  If you elected to install the online man pages above,
  /bin/echo the default for the installation of the man pages will be where you installed
  /bin/echo the rest of the CM man pages.
  goto qnqs

ret-nqs:
  if ( ! $a ) goto endnqs

qnqsu:
  set qtag = nqsu
  set q = "Location to install the NQS user commands?"; set default="/usr/local/bin"; goto ask
help-nqsu:
  /bin/echo Type the directory where you would like to locate the programs which are
  /bin/echo used by the user to enqueue and dequeue jobs, and the programs used by
  /bin/echo the site administrator to manage the batch queues.  Installation is done
  /bin/echo by copying files which will occupy about 2.5 megabytes of disk.
  goto qnqsu
ret-nqsu:
  set nqsusr_loc = $locrtdir/nqsbin.$machine
  set nqsusr_dst = "$a"

qnqsu-i:
  set qtag = nqsu-i
  set q = "How do you want to install the NQS user commands (copy,link) ? "; set default="copy"; goto ask
help-nqsu-i:
  /bin/echo If you say \"copy\", each NQS command will be copied to
  /bin/echo $nqsusr_dst. If you say \"link\", a symbolic link will be created
  /bin/echo in $nqsusr_dst pointing to the executable in
  /bin/echo $locrtdir/nqsbin.$machine.
  goto qnqsu-i
ret-nqsu-i:
  if ( "$machine" == "sun4" ) then
    set NQS_GROUP = wheel
  else
    set NQS_GROUP = system
  endif
  set NQS_OWNER = root

  switch ("$a")
    case "link":
      if (! -e $nqsusr_dst) then
        /bin/echo "WARNING: $nqsusr_dst does not currently exist."
        /bin/echo "         Please choose another location or spawn a subshell"
        /bin/echo "         and create the directory."
	goto qnqsu
      else
        if (! -w $nqsusr_dst) then
          /bin/echo "WARNING: $nqsusr_dst is not writable."
          /bin/echo "         Please choose another location or spawn a subshell"
          /bin/echo "         and change the permissions on the directory."
	  goto qnqsu
        endif
      endif
      /bin/echo "chown $NQS_OWNER $locrtdir/nqsbin.$machine/qdel" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqsbin.$machine/qdev" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqsbin.$machine/qlimit" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqsbin.$machine/qmgr" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqsbin.$machine/qpr" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqsbin.$machine/qstat" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqsbin.$machine/qsub" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqsbin.$machine/nmapmgr" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqsbin.$machine/shownqs" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqsbin.$machine/startnqs" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqsbin.$machine/stopnqs" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqsbin.$machine/qdel" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqsbin.$machine/qdev" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqsbin.$machine/qlimit" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqsbin.$machine/qmgr" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqsbin.$machine/qpr" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqsbin.$machine/qstat" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqsbin.$machine/qsub" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqsbin.$machine/nmapmgr" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqsbin.$machine/shownqs" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqsbin.$machine/startnqs" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqsbin.$machine/stopnqs" >> $script
      /bin/echo "chmod 6111 $locrtdir/nqsbin.$machine/qdel" >> $script
      /bin/echo "chmod 6111 $locrtdir/nqsbin.$machine/qdev" >> $script
      /bin/echo "chmod 6111 $locrtdir/nqsbin.$machine/qlimit" >> $script
      /bin/echo "chmod 6111 $locrtdir/nqsbin.$machine/qmgr" >> $script
      /bin/echo "chmod 6111 $locrtdir/nqsbin.$machine/qpr" >> $script
      /bin/echo "chmod 6111 $locrtdir/nqsbin.$machine/qstat" >> $script
      /bin/echo "chmod 6111 $locrtdir/nqsbin.$machine/qsub" >> $script
      /bin/echo "chmod 755 $locrtdir/nqsbin.$machine/nmapmgr" >> $script
      /bin/echo "chmod 755 $locrtdir/nqsbin.$machine/shownqs" >> $script
      /bin/echo "chmod 744 $locrtdir/nqsbin.$machine/startnqs" >> $script
      /bin/echo "chmod 744 $locrtdir/nqsbin.$machine/stopnqs" >> $script
      /bin/echo "rm -f $nqsusr_dst/qdel" >> $script
      /bin/echo "rm -f $nqsusr_dst/qdev" >> $script
      /bin/echo "rm -f $nqsusr_dst/qlimit" >> $script
      /bin/echo "rm -f $nqsusr_dst/qmgr" >> $script
      /bin/echo "rm -f $nqsusr_dst/qpr" >> $script
      /bin/echo "rm -f $nqsusr_dst/qstat" >> $script
      /bin/echo "rm -f $nqsusr_dst/qsub" >> $script
      /bin/echo "rm -f $nqsusr_dst/nmapmgr" >> $script
      /bin/echo "rm -f $nqsusr_dst/shownqs" >> $script
      /bin/echo "rm -f $nqsusr_dst/startnqs" >> $script
      /bin/echo "rm -f $nqsusr_dst/stopnqs" >> $script
      /bin/echo "ln -s $locrtdir/nqsbin.$machine/qdel $nqsusr_dst/qdel" >> $script
      /bin/echo "ln -s $locrtdir/nqsbin.$machine/qdev $nqsusr_dst/qdev" >> $script
      /bin/echo "ln -s $locrtdir/nqsbin.$machine/qlimit $nqsusr_dst/qlimit" >> $script
      /bin/echo "ln -s $locrtdir/nqsbin.$machine/qmgr $nqsusr_dst/qmgr" >> $script
      /bin/echo "ln -s $locrtdir/nqsbin.$machine/qpr $nqsusr_dst/qpr" >> $script
      /bin/echo "ln -s $locrtdir/nqsbin.$machine/qstat $nqsusr_dst/qstat" >> $script
      /bin/echo "ln -s $locrtdir/nqsbin.$machine/qsub $nqsusr_dst/qsub" >> $script
      /bin/echo "ln -s $locrtdir/nqsbin.$machine/nmapmgr $nqsusr_dst/nmapmgr" >> $script
      /bin/echo "ln -s $locrtdir/nqsbin.$machine/shownqs $nqsusr_dst/shownqs" >> $script
      /bin/echo "ln -s $locrtdir/nqsbin.$machine/startnqs $nqsusr_dst/startnqs" >> $script
      /bin/echo "ln -s $locrtdir/nqsbin.$machine/stopnqs $nqsusr_dst/stopnqs" >> $script
      breaksw
    case "copy":
      if (! -e $nqsusr_dst) then
        /bin/echo "WARNING: $nqsusr_dst does not currently exist."
        /bin/echo "         Please choose another location or spawn a subshell"
        /bin/echo "         and create the directory."
	goto qnqsu
      else
        if (! -w $nqsusr_dst) then
          /bin/echo "WARNING: $nqsusr_dst is not writable."
          /bin/echo "         Please choose another location or spawn a subshell"
          /bin/echo "         and change the permissions on the directory."
	goto qnqsu
        endif
      endif
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $locrtdir/nqsbin.$machine/qdel $nqsusr_dst/qdel" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $locrtdir/nqsbin.$machine/qdev $nqsusr_dst/qdev" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $locrtdir/nqsbin.$machine/qlimit $nqsusr_dst/qlimit" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $locrtdir/nqsbin.$machine/qmgr $nqsusr_dst/qmgr" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $locrtdir/nqsbin.$machine/qpr $nqsusr_dst/qpr" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $locrtdir/nqsbin.$machine/qstat $nqsusr_dst/qstat" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $locrtdir/nqsbin.$machine/qsub $nqsusr_dst/qsub" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $locrtdir/nqsbin.$machine/nmapmgr $nqsusr_dst/nmapmgr" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $locrtdir/nqsbin.$machine/shownqs $nqsusr_dst/shownqs" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 744 $locrtdir/nqsbin.$machine/startnqs $nqsusr_dst/startnqs" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 744 $locrtdir/nqsbin.$machine/stopnqs $nqsusr_dst/stopnqs" >> $script
      breaksw
    default:
      /bin/echo '?unrecognized response, must be "copy" or "link".'
      goto qnqsu-i
  endsw
endnqsu-i:
endnqsu:

qnqsl:
  set qtag = nqsl
  set q = "Location to install the NQS daemons?"; set default="/usr/local/lib/nqs"; goto ask
help-nqsl:
  /bin/echo Type the directory where you would like to locate the various NQS daemons
  /bin/echo and other miscellaneous NQS files.  Installation is done by copying
  /bin/echo files which will occupy about 3.1 megabytes of disk.
  goto qnqsl
ret-nqsl:
  set nqslib_loc = $locrtdir/nqslib.$machine
  set nqslib_dst = "$a"

qnqsl-i:
  set qtag = nqsl-i
  set q = "How do you want to install the NQS daemons (copy,link) ? "; set default="copy"; goto ask
help-nqsl-i:
  /bin/echo If you say \"copy\", each NQS daemon will be copied to
  /bin/echo $nqslib_dst. If you say \"link\", a symbolic link will be created
  /bin/echo in $nqslib_dst pointing to the executable in
  /bin/echo $locrtdir/nqslib.$machine.
  goto qnqsl-i
ret-nqsl-i:
  switch ("$a")
    case "link":
      if (! -e $nqslib_dst) then
        /bin/echo "WARNING: $nqslib_dst does not currently exist."
        /bin/echo "         It will be created during installation"
      else
        if (! -w $nqslib_dst) then
          /bin/echo "WARNING: $nqslib_dst is not writable."
          /bin/echo "         Please choose another location or spawn a subshell"
          /bin/echo "         and change the permissions on the directory."
	  goto qnqsl
        endif
      endif

      /bin/echo "if ( ! -e $nqslib_dst ) mkdir -p $nqslib_dst" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/lpserver" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/netclient" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/pipeclient" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/shlexefai" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/sitename" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/nqsdaemon" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/logdaemon" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/netdaemon" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/netserver" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/nqsmkdirs" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/nqsmktrans" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/qmgr.hlp" >> $script
      /bin/echo "chown $NQS_OWNER $locrtdir/nqslib.$machine/qmkdir" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/lpserver" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/netclient" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/pipeclient" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/shlexefai" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/sitename" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/nqsdaemon" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/logdaemon" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/netdaemon" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/netserver" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/nqsmkdirs" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/nqsmktrans" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/qmgr.hlp" >> $script
      /bin/echo "chgrp $NQS_GROUP $locrtdir/nqslib.$machine/qmkdir" >> $script
      /bin/echo "chmod 555 $locrtdir/nqslib.$machine/lpserver" >> $script
      /bin/echo "chmod 100 $locrtdir/nqslib.$machine/netclient" >> $script
      /bin/echo "chmod 100 $locrtdir/nqslib.$machine/pipeclient" >> $script
      /bin/echo "chmod 6111 $locrtdir/nqslib.$machine/shlexefai" >> $script
      /bin/echo "chmod 744 $locrtdir/nqslib.$machine/sitename" >> $script
      /bin/echo "chmod 2100 $locrtdir/nqslib.$machine/nqsdaemon" >> $script
      /bin/echo "chmod 100 $locrtdir/nqslib.$machine/logdaemon" >> $script
      /bin/echo "chmod 100 $locrtdir/nqslib.$machine/netdaemon" >> $script
      /bin/echo "chmod 111 $locrtdir/nqslib.$machine/netserver" >> $script
      /bin/echo "chmod 755 $locrtdir/nqslib.$machine/nqsmkdirs" >> $script
      /bin/echo "chmod 755 $locrtdir/nqslib.$machine/nqsmktrans" >> $script
      /bin/echo "chmod 644 $locrtdir/nqslib.$machine/qmgr.hlp" >> $script
      /bin/echo "chmod 755 $locrtdir/nqslib.$machine/qmkdir" >> $script
      /bin/echo "rm -f $nqslib_dst/lpserver" >> $script
      /bin/echo "rm -f $nqslib_dst/netclient" >> $script
      /bin/echo "rm -f $nqslib_dst/pipeclient" >> $script
      /bin/echo "rm -f $nqslib_dst/shlexefai" >> $script
      /bin/echo "rm -f $nqslib_dst/sitename" >> $script
      /bin/echo "rm -f $nqslib_dst/nqsdaemon" >> $script
      /bin/echo "rm -f $nqslib_dst/logdaemon" >> $script
      /bin/echo "rm -f $nqslib_dst/netdaemon" >> $script
      /bin/echo "rm -f $nqslib_dst/netserver" >> $script
      /bin/echo "rm -f $nqslib_dst/nqsmkdirs" >> $script
      /bin/echo "rm -f $nqslib_dst/nqsmktrans" >> $script
      /bin/echo "rm -f $nqslib_dst/qmgr.hlp" >> $script
      /bin/echo "rm -f $nqslib_dst/qmkdir" >> $script
      /bin/echo "rm -f $nqslib_dst/lpserver" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/lpserver $nqslib_dst/lpserver" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/netclient $nqslib_dst/netclient" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/pipeclient $nqslib_dst/pipeclient" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/shlexefai $nqslib_dst/shlexefai" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/sitename $nqslib_dst/sitename" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/nqsdaemon $nqslib_dst/nqsdaemon" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/logdaemon $nqslib_dst/logdaemon" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/netdaemon $nqslib_dst/netdaemon" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/netserver $nqslib_dst/netserver" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/nqsmkdirs $nqslib_dst/nqsmkdirs" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/nqsmktrans $nqslib_dst/nqsmktrans" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/qmgr.hlp $nqslib_dst/qmgr.hlp" >> $script
      /bin/echo "ln -s $locrtdir/nqslib.$machine/qmkdir $nqslib_dst/qmkdir" >> $script
      breaksw
    case "copy":
      if (! -e $nqslib_dst) then
	/bin/echo "WARNING: $nqslib_dst does not currently exist."
	/bin/echo "         It will be created during installation"
      else
        if (! -w $nqslib_dst) then
          /bin/echo "WARNING: $nqslib_dst is not writable."
          /bin/echo "         Please choose another location or spawn a subshell"
          /bin/echo "         and change the permissions on the directory."
	  goto qnqsl
        endif
      endif
      /bin/echo "if ( ! -e $nqslib_dst ) mkdir -p $nqslib_dst" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 555 $locrtdir/nqslib.$machine/lpserver $nqslib_dst/lpserver" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $locrtdir/nqslib.$machine/netclient $nqslib_dst/netclient" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $locrtdir/nqslib.$machine/pipeclient $nqslib_dst/pipeclient" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $locrtdir/nqslib.$machine/shlexefai $nqslib_dst/shlexefai" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 744 $locrtdir/nqslib.$machine/sitename $nqslib_dst/sitename" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 2100 $locrtdir/nqslib.$machine/nqsdaemon $nqslib_dst/nqsdaemon" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $locrtdir/nqslib.$machine/logdaemon $nqslib_dst/logdaemon" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $locrtdir/nqslib.$machine/netdaemon $nqslib_dst/netdaemon" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 111 $locrtdir/nqslib.$machine/netserver $nqslib_dst/netserver" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $locrtdir/nqslib.$machine/nqsmkdirs $nqslib_dst/nqsmkdirs" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $locrtdir/nqslib.$machine/nqsmktrans $nqslib_dst/nqsmktrans" >> $script
      /bin/echo "install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $locrtdir/nqslib.$machine/qmkdir $nqslib_dst/qmkdir" >> $script
      breaksw
    default:
      /bin/echo '?unrecognized response, must be "copy" or "link".'
      goto qnqsl-i
  endsw
endnqsl-i:
endnqsl:
# Last phase in the NQS install is to be sure to rebuild the NQS database
# and to make /usr/spool/nqs
      /bin/echo "mkdir -p /usr/spool/nqs" >> $script

endnqs:


#-----------------------------------------------------------------------------
# Locate the configuration.lisp file
#-----------------------------------------------------------------------------
q9:
set qtag = 9
set q = "Location of your configuration.lisp (path,skip) ?"; set default="/cm/configuration"; goto ask
help-9:
  /bin/echo The configuration.lisp file is read by the $cmmodel utilities and runtime system
  /bin/echo to determine the hardware configuration of your $cmmodel\(s\). Traditionally,
  /bin/echo this file has been located in /cm/configuration. LISP bands will continue
  /bin/echo to look for it there, so if your site uses LISP, this is where it ought to
  /bin/echo be. If no LISP usage is expected, you can locate the file anywhere. NOTE:
  /bin/echo this installation does not create or copy configuration.lisp. You are
  /bin/echo responsible for making sure that it exists where you now say it will exist.
  /bin/echo A sample configuration.lisp can be found in
  /bin/echo /cm/configuration/sample-configuration.lisp
  goto q9
ret-9:
  set config_loc = "/cm/configuration"
  if ("$a" == "skip") goto end9
  if ( ! -e $a/configuration.lisp ) then
    /bin/echo 'WARNING: The file "configuration.lisp" does not currently exist in'
    /bin/echo '         the directory '$a
    /bin/echo '         You will need to create one and install it manually. '
    /bin/echo '         A sample configuration.lisp can be found in'
    /bin/echo '         /cm/configuration/sample-configuration.lisp.'
  endif
  set config_loc = "$a"
end9:


#-----------------------------------------------------------------------------
# Create the cm-base-system-config file
#-----------------------------------------------------------------------------
set cfile = "$cwd/cm-base-system-config.install"
config:
set qtag = "config"
set q = "Location to write cm-base-system-config? (path,skip)"; set default="/etc"; goto ask
help-config:
  /bin/echo The file cm-base-system-config is used by the $cmmodel runtime system to find
  /bin/echo the various files it requires to operate the $cmmodel. This file is
  /bin/echo required on all $cmmodel host systems. For general public use, this file
  /bin/echo must be in /etc. You are strongly advised to locate it there \(it is
  /bin/echo the default response\).
  goto config
ret-config:
  set cnf_loc = "/etc"
  if ("$a" == "skip") goto config-gen
  set cnf_loc = "$a"
  if ("$cnf_loc" == "/etc") goto sanecnf
  /bin/echo WARNING: Locating cm-base-system-config other than in /etc will
  /bin/echo probably cause the system to work incorrectly.
qcnfconf:
  set qtag = cnfconf
  set q = "Confirm that you want cm-base-system-config in $cnf_loc (Yes or no)"; set default=""; goto ask-y-n
echo "after confirmation:  value of a is" $a
  help-cnfconf:
  /bin/echo Answer \"yes\" to confirm that you want to install the software
  /bin/echo configuration file, cm-base-system-config, in $cnf_loc,
  /bin/echo which will probably cause incorrect system operation.
  /bin/echo Answer \"no\" to change your mind.
  goto qcnfconf
ret-cnfconf:
  if ( ! $a ) goto config

sanecnf:
  if (! -e $cnf_loc) then
    /bin/echo "WARNING: $cnf_loc does not currently exist."
    if ( ! $cnfonly ) then
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and create the directory."
      goto config
    endif
  else
    if ((! $cnfonly) && (! -w $cnf_loc)) then
      /bin/echo "WARNING: $cnf_loc is not writable."
      /bin/echo "         Please choose another location or spawn a subshell"
      /bin/echo "         and change the permissions on the directory."
      goto config
    endif
  endif
# Generate the file (we do this even if they say skip)
config-gen:
  touch $cfile
  if ( ! -w $cfile ) then
    /bin/echo "ERROR: Cannot write $cfile"
    goto abort
  endif

# Find out where the lisp bands were stuffed
set bands_dir = (foo)

if ( -e /tmp/tape-file-locations ) then
   set bands_dir = `grep -i ^bands /tmp/tape-file-locations`
endif
if ($#bands_dir < 2) then
   set bands_dir = (bands.foo /cm/lucid/$version/$machine/)
endif

  cat > $cfile <<EoI
#! /bin/csh -f
# $cmmodel CMSS $version Base System Configuration File
# Generated by installation procedure $today, by user $user
# following allows this to be executed by the CSH
# Usage:  cm-base-system-config [ tag ]   {print tag translation}
#         cm-base-system-config           {print location of this file}
$bin_loc/cm-config-lookup \$1
exit \$status

# Actual TAG/VALUE translations begin here
# Microcode version number
UCODE=${ucode}

# Location of the microcode and IMP libraries
CM2-UCODE-DIR = $cm2_uc_loc/
CM200-UCODE-DIR = $cm200_uc_loc/

# Location of User Executables
BIN-DIR = $bin_loc/

# Location of System Executables
ETC-DIR = $etc_loc/

# Program run by cmattach and cmcoldboot to cold-boot the CM
COLDBOOT-PROGRAM = $etc_loc/coldboot-paris-${ucode}

# Program to run when the cached config file is out of date
CONFIG-FILE-COMPILER =  $etc_loc/cm-update-config

# Location of the CM include file tree
INCLUDE-DIR = $inc_loc/

# Location of the CM libraries
LIBRARY-DIR = $lib_loc/

# Location of the hardware configuration file
CM-CONFIGURATION-FILE = $config_loc/configuration.lisp

# Where the ts-daemon looks for its user-notifier
TS-DAEMON-NOTIFY-USER = $etc_loc/notify-user.sh

# Where run-ts-daemon looks to find the ts-daemon
TS-DAEMON = $etc_loc/ts-daemon

# Where NQS looks for daemon, sysadmin executables
NQS-LIB-DIR = $nqslib_dst/

# Where NQS looks for qmgr helpfile
NQS-QMGR-HELPFILE = $nqslib_dst/qmgr.hlp

# Where NQS looks for user executables
NQS-USR-DIR = $nqsusr_dst/

# Where automatic diagnostics look for lisp bands
# This path will be fixed up by install-cm-software
# if you install the preconfigured bands.
BANDS-DIR = $bands_dir[2]

# Default machine type for IMPASS
IMPASS-MACHINE-TYPE = $impassmodel

# Location of the online man pages
ONLINE-MANPAGE-DIRS = $man_list

EoI

  chmod +x $cfile

  if ( $cnfonly ) goto configend
  if ("$a" == "skip") goto config-noinst
  /bin/echo "rm -f $cnf_loc/cm-base-system-config-${ucode}" >> $script
  /bin/echo "cp $cfile $cnf_loc/cm-base-system-config-${ucode}" >> $script
  /bin/echo "chmod +x $cnf_loc/cm-base-system-config-${ucode}" >> $script
  if ($?install_as_default) then
    /bin/echo "rm -f $cnf_loc/cm-base-system-config" >> $script
    /bin/echo "pushd $cnf_loc; ln -s cm-base-system-config-${ucode} cm-base-system-config; popd" >> $script
  endif

config-noinst:
configend:


#-----------------------------------------------------------------------------
# Auto-startup of daemons, etc
#-----------------------------------------------------------------------------
qsys:
if ( $cnfonly ) goto endsys
set qtag = "sys"
set q = "Install autostartup of CM daemons and logger? (yes or no)"; set default="yes"; goto ask-y-n
help-sys:
  /bin/echo If you say \"yes\", the installation procedure will:
  /bin/echo '  1. Include the CM daemons in /etc/rc.local, which causes them to be started'
  /bin/echo '     automatically during system boot.'
  /bin/echo '  2. Install cm-logger and cm-logger-conn services in services database.'
  /bin/echo '     Note: If a site is running Yellow Pages, this edit must be made on'
  /bin/echo '     the appropriate machine for YP Service to take effect.'
  /bin/echo '     If you installed NQS, nqs will also be added to the services database.'
  /bin/echo '  3. Install running of diagnostics in crontab.  Default is to run them' 
  /bin/echo '     at one minute past 5 AM every morning, and mail the results to'
  /bin/echo '     "tmc-ae".'
  /bin/echo '  4. Install log rotation in crontab. Default is weekly rotation of'
  /bin/echo '     files (at one minute past midnight).'
  /bin/echo Installation is performed by executing the CSH script
  /bin/echo $mfgrtdir/install/update-system-files.
  /bin/echo You may want to edit this file and execute it manually to specify, for
  /bin/echo example, different crontab settings.
  goto qsys
ret-sys:
  if ( $a ) then
    /bin/echo "$mfgrtdir/install/update-system-files" >> $script
  endif
endsys:


#-----------------------------------------------------------------------------
# Auto-startup of daemons, etc
#-----------------------------------------------------------------------------
qdriver:
if ( $cnfonly ) goto enddriver
set qtag = "driver"
set q = "Build and install the CM Driver on this system? (yes or no)"; set default=""; goto ask-y-n
help-driver:
  /bin/echo If you say \"yes\", the installation procedure will build and install the
  /bin/echo CM Driver for the local $machine system.
  /bin/echo Installation is performed by executing the CSH script
  /bin/echo $mfgrtdir/install/install-$machine-driver.
  /bin/echo You may prefer to execute this script at another time, in which
  /bin/echo case, say \"no\".
  goto qdriver
ret-driver:
  if ( $a ) then
    /bin/echo "$mfgrtdir/install/install-$machine-driver $mfgrtdir" >> $script
  endif
enddriver:


#-----------------------------------------------------------------------------
# The point of no return...
#-----------------------------------------------------------------------------
qconfirm:
# If only reconfiguring
if ( $cnfonly ) goto qdo-cnf
set qtag = "confirm"
set q = "Perform the requested installation now? (yes or no)"; set default=""; goto ask-y-n
help-confirm:
  /bin/echo If you say yes, the installation will be performed as you have
  /bin/echo indicated by executing the generated script file \"$script\".
  /bin/echo This script copies or links the distributed files as you have
  /bin/echo indicated, and copies the generated software configuration file
  /bin/echo $cfile to $cnf_loc.
  /bin/echo This will probably overwrite existing files from previous versions.
  /bin/echo If you say \"no\" you can still execute $script later
  /bin/echo \(it is an executable csh script\), and/or copy $cfile
  /bin/echo to $cnf_loc manually.
  goto qconfirm
ret-confirm:
  chmod +x $script
  if ( $a ) goto doit
  goto canit

doit:
  # show we have started breaking things
  set didnothing = 0
  /bin/echo ---- Executing $script ----
  $script
  set sstat = $status
  if ($sstat) then
    /bin/echo \?Installation script returned status $sstat
    exit $sstat
  endif
  goto done

canit:
  /bin/echo ""
  /bin/echo --- Installation will not be performed ---
  /bin/echo ""
  /bin/echo The file \"$script\"
  /bin/echo contains the generated installation commands. It is an executable shell script.
  /bin/echo Executing it \(no arguments are required\) will perform the installation you
  /bin/echo just decided not to do.
  /bin/echo ""
  /bin/echo The file \"$cfile\"
  /bin/echo contains the generated software configuration file. You can just copy
  /bin/echo this to \"$cnf_loc/cm-base-system-config-${ucode}\" to configure your
  /bin/echo system as you have indicated, without installing files.
  goto abort
#-----------------------------------------------------------------------------
qdo-cnf:
set qtag = "do-cnf"
set q = "Write the configuration file now? (yes or no)"; set default=""; goto ask-y-n
help-do-cnf:
  /bin/echo If you say yes, the configuration file resulting from your answers
  /bin/echo above will be written to $cnf_loc/cm-base-system-config-${ucode}
  /bin/echo If you say \"no\" the configuration file will not be copied,
  /bin/echo but will be left in $cfile for you to copy manually.
  goto qdo-cnf
ret-do-cnf:
  chmod +x $script
  if ( $a ) goto do-cnf
  goto cancnf

do-cnf:
  set echo
  rm -f $cnf_loc/cm-base-system-config $cnf_loc/cm-base-system-config-${ucode}
  cp $cfile $cnf_loc/cm-base-system-config-${ucode}
  chmod +x $cnf_loc/cm-base-system-config-${ucode}
  pushd $cnf_loc; ln -s cm-base-system-config-${ucode} cm-base-system-config; popd
  unset echo
  /bin/echo Configuration file $cnf_loc/cm-base-system-config-${ucode} written.
  goto done

cancnf:
  /bin/echo --- Configuration file not copied ---
  /bin/echo ""
  /bin/echo The file \"$cfile\"
  /bin/echo contains the generated software configuration file. You can copy
  /bin/echo this to \"$config_loc/cm-base-system-config-${ucode}\" to configure your
  /bin/echo system as you have indicated.
  goto abort
#----------------------------------------------------------------------
#Natural successful end
done:
exit 0
  
#----------------------------------------------------------------------
#here on ^C's or user bail-outs
abort:
  /bin/echo "Installation terminated"
  if ($didnothing) then
    /bin/echo No system changes were effected, no harm done
  else
    /bin/echo Actual installation was in progress. System state unpredictable\!
  endif
  exit 1

#==========================================================================
# 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
