#!/bin/csh -f
#
# Script to install CMSS V6.1.1
# (command, library and microcode patches)
#

# ---------------- VERSION and CONFIG INFO ------------------
# Legal release version (comments and displays only)
set version = "6.1.1"
# TMC manufacturing directory (dir under /XXXmfg0) for local installs only
set reldir = "release-6.1-patch1"
# microcode version
set ucode = 6104
# manufacturing runtime directory (under /XXXmfg0/reldir)
set rtdir = cm-runtime-${ucode}
#
set self = $0
set mfgrtdir = `pwd | sed -e s,/tmp_mnt,,`/${rtdir}
set whoiam = `whoami`
set user=$whoiam

set cmbssconfig=/etc/cm-base-system-config-6104
if (! -e $cmbssconfig) set cmbssconfig=/usr/local/etc/cm-base-system-config
if (! -e $cmbssconfig) then
   echo "Cannot locate CM base system config file"
   exit 1
endif

# ----------------- END VERSION and CONFIG ------------------

set DEBUG = ""

set nonomatch

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

# Make a little helper program which tells us if a file is a symlink or not.
rm -f /tmp/islink
cat > /tmp/islink << 'EoI'
#
# Return true if the file is a link
#
set foo = `ls -l $1`
if ( $#foo == 10 ) then
	exit 0
else
	exit 1
endif
'EoI'
chmod +x /tmp/islink

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

This procedure installs patches for the 6.1 Final CM2 Base System Software
Release.

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 || sun4c || sun4m) } 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:

# ----------------------------------------------------------------------
# Find out if the user wants backup copies of the executables.
qmkbackup:
set qtag = mkbackup
set q = "Back up old versions of executables and libraries? (yes or no)"
set default="no"
goto ask-y-n

help-mkbackup:
   /bin/echo If you say \"yes\", the patch installation procedure will rename
   /bin/echo any executables or libraries it replaces to files with the same
   /bin/echo name but with a trailing date extension.  This will require
   /bin/echo approximately 68mb of space on a Sun front-end, and 50mb of space
   /bin/echo on a Vax front-end.  If you say \"no\", the old files will be
   /bin/echo deleted.  If you installed any parts of your release with the
   /bin/echo \"link\" option in the original installation script, only the
   /bin/echo links will be removed, and new ones will be installed pointing
   /bin/echo to where you untarred the patch release.
   goto qmkbackup

ret-mkbackup:
   set dobackups = 0
   if ( $a ) then
	set dobackups = $a
   endif

# ----------------------------------------------------------------------
# Walk over each of the product directories, and attempt to install the
# patched executables or libraries, based on the info in the base system
# config file.  If the files are raw files, we move them to an old date,
# and copy in the new files.  If the files are symlinks, we remove the
# symlinks and point them at where we are now.
#
# There are some special cases.  We only make backup copies of the ucode,
# to avoid having to edit the base-system-config file.  We only make backup
# copies of the header files, also.
#
# First the user commands
#
/bin/echo
/bin/echo Updating User commands
set bindir = `$cmbssconfig BIN-DIR`

if ( { /tmp/islink $bindir/cmattach } ) then
   /bin/echo User commands installed as symlinks
   foreach i ( $mfgrtdir/bin.$machine/* )
	${DEBUG} rm -f $bindir/$i:t
	${DEBUG} ln -s $i $bindir/$i:t
   end
else
   /bin/echo User commands installed as files
   foreach i ( $mfgrtdir/bin.$machine/* )
	if ( $dobackups ) then
		BackUpFile $bindir/$i:t
	else
		${DEBUG} rm -f $bindir/$i:t
	endif
	${DEBUG} cp $i $bindir/$i:t
   end
endif
	
# ----------------------------------------------------------------------
# Now the administrator commands
#
/bin/echo
/bin/echo Updating Administrator commands
set etcdir = `$cmbssconfig ETC-DIR`

if ( { /tmp/islink $etcdir/cmts-admin } ) then
   /bin/echo Administrator commands installed as symlinks
   foreach i ( $mfgrtdir/etc.$machine/* )
	${DEBUG} rm -f $etcdir/$i:t
	${DEBUG} ln -s $i $etcdir/$i:t
   end
else
   /bin/echo Administrator commands installed as files
   foreach i ( $mfgrtdir/etc.$machine/* )
	if ( $dobackups ) then
		BackUpFile $etcdir/$i:t
	else
		${DEBUG} rm -f $etcdir/$i:t
	endif
	${DEBUG} cp $i $etcdir/$i:t
   end
endif
	
# ----------------------------------------------------------------------
# Now the libraries.  This is a bit more complicated, and has to be done
# semi-manually.  Well, it's really brute force!
#
/bin/echo
/bin/echo Updating Libraries
set libdir = `$cmbssconfig LIBRARY-DIR`

if ( { /tmp/islink $libdir/libparis2-6104.a } ) then
   /bin/echo Libraries installed as symlinks

   ${DEBUG} rm -f $libdir/libparis.a
   ${DEBUG} rm -f $libdir/libparis2.a
   ${DEBUG} rm -f $libdir/libparis2-6104.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libparis2-6104.a $libdir/libparis2-6104.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libparis2-6104.a $libdir/libparis.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libparis2-6104.a $libdir/libparis2.a
   ${DEBUG} rm -f $libdir/libparis-pg.a
   ${DEBUG} rm -f $libdir/libparis2-pg.a
   ${DEBUG} rm -f $libdir/libparis2-6104-pg.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libparis2-6104-pg.a $libdir/libparis2-6104-pg.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libparis2-6104-pg.a $libdir/libparis-pg.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libparis2-6104-pg.a $libdir/libparis2-pg.a

   ${DEBUG} rm -f $libdir/libckpt.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libckpt.a $libdir/libckpt.a
   ${DEBUG} rm -f $libdir/libckpt-pg.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libckpt-pg.a $libdir/libckpt-pg.a
   ${DEBUG} rm -f $libdir/libcmfe.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libcmfe.a $libdir/libcmfe.a
   ${DEBUG} rm -f $libdir/libcmfe-pg.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libcmfe-pg.a $libdir/libcmfe-pg.a
   ${DEBUG} rm -f $libdir/libtoolkit.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libtoolkit.a $libdir/libtoolkit.a
   ${DEBUG} rm -f $libdir/libtoolkit-pg.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libtoolkit-pg.a $libdir/libtoolkit-pg.a

   if ( $machine == "sun4" ) then
	${DEBUG} ln -s $mfgrtdir/lib.$machine/libparis.sa.6104.0 $libdir/libparis.sa.6104.0
	${DEBUG} ln -s $mfgrtdir/lib.$machine/libparis.so.6104.0 $libdir/libparis.so.6104.0
   endif

   ${DEBUG} rm -f $libdir/libparisfort-6104.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libparisfort-6104.a $libdir/libparisfort-6104.a
   ${DEBUG} rm -f $libdir/libparisfort-6104-pg.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libparisfort-6104-pg.a $libdir/libparisfort-6104-pg.a

   ${DEBUG} rm -f $libdir/libcmfs.a
   ${DEBUG} rm -f $libdir/libcmfs-6104.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libcmfs-6104.a $libdir/libcmfs-6104.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libcmfs-6104.a $libdir/libcmfs.a
   ${DEBUG} rm -f $libdir/libcmfs-pg.a
   ${DEBUG} rm -f $libdir/libcmfs-6104-pg.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libcmfs-6104-pg.a $libdir/libcmfs-6104-pg.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libcmfs-6104-pg.a $libdir/libcmfs-pg.a

   ${DEBUG} rm -f $libdir/libcmrts-1.1-CM2-6104.a
   ${DEBUG} rm -f $libdir/libcmrts-1.1-CM2-6104_p.a
   ${DEBUG} rm -f $libdir/libcmrts-1.1-CM200-6104.a
   ${DEBUG} rm -f $libdir/libcmrts-1.1-CM200-6104_p.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libcmrts-1.1-CM2-6104.a $libdir/libcmrts-1.1-CM2-6104.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libcmrts-1.1-CM2-6104_p.a $libdir/libcmrts-1.1-CM2-6104_p.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libcmrts-1.1-CM200-6104.a $libdir/libcmrts-1.1-CM200-6104.a
   ${DEBUG} ln -s $mfgrtdir/lib.$machine/libcmrts-1.1-CM200-6104.a $libdir/libcmrts-1.1-CM200-6104_p.a

else
   /bin/echo Libraries installed as files
   if ( $dobackups ) then
	BackUpFile $libdir/libparis2-6104.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libparis2-6104.a $libdir
	${DEBUG} ranlib -t $libdir/libparis2-6104.a
	BackUpFile $libdir/libparis2-6104-pg.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libparis2-6104-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libparis2-6104-pg.a

	BackUpFile $libdir/libckpt.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libckpt.a $libdir
	${DEBUG} ranlib -t $libdir/libckpt.a
	BackUpFile $libdir/libckpt-pg.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libckpt-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libckpt-pg.a
	BackUpFile $libdir/libcmfe.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmfe.a $libdir
	${DEBUG} ranlib -t $libdir/libcmfe.a
	BackUpFile $libdir/libcmfe-pg.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmfe-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libcmfe-pg.a
	BackUpFile $libdir/libtoolkit.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libtoolkit.a $libdir
	${DEBUG} ranlib -t $libdir/libtoolkit.a
	BackUpFile $libdir/libtoolkit-pg.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libtoolkit-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libtoolkit-pg.a

	if ( $machine == sun4 ) then
	   ${DEBUG} cp $mfgrtdir/lib.$machine/libparis.sa.6104.0 $libdir
 	   ${DEBUG} cp $mfgrtdir/lib.$machine/libparis.so.6104.0 $libdir
	   ${DEBUG} ranlib -t $libdir/libparis.sa.6104.0
	endif

	BackUpFile $libdir/libparisfort-6104.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libparisfort-6104.a $libdir
	${DEBUG} ranlib -t $libdir/libparisfort-6104.a
	BackUpFile $libdir/libparisfort-6104-pg.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libparisfort-6104-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libparisfort-6104-pg.a

	BackUpFile $libdir/libcmfs-6104.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmfs-6104.a $libdir
	${DEBUG} ranlib -t $libdir/libcmfs-6104.a
	BackUpFile $libdir/libcmfs-6104-pg.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmfs-6104-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libcmfs-6104-pg.a

	BackUpFile $libdir/libcmrts-1.1-CM2-6104.a
	BackUpFile $libdir/libcmrts-1.1-CM2-6104_p.a
	BackUpFile $libdir/libcmrts-1.1-CM200-6104.a
	BackUpFile $libdir/libcmrts-1.1-CM200-6104_p.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmrts-1.1-CM2-6104.a $libdir
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmrts-1.1-CM2-6104_p.a $libdir
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmrts-1.1-CM200-6104.a $libdir
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmrts-1.1-CM200-6104_p.a $libdir
	${DEBUG} ranlib -t $libdir/libcmrts-1.1-CM2-6104.a
	${DEBUG} ranlib -t $libdir/libcmrts-1.1-CM2-6104_p.a
	${DEBUG} ranlib -t $libdir/libcmrts-1.1-CM200-6104.a
	${DEBUG} ranlib -t $libdir/libcmrts-1.1-CM200-6104_p.a
   else
	${DEBUG} rm -f $libdir/libparis2-6104.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libparis2-6104.a $libdir
	${DEBUG} ranlib -t $libdir/libparis2-6104.a
	${DEBUG} rm -f $libdir/libparis2-6104-pg.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libparis2-6104-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libparis2-6104-pg.a

	if ( $machine == sun4 ) then
	   ${DEBUG} cp $mfgrtdir/lib.$machine/libparis.sa.6104.0 $libdir
	   ${DEBUG} cp $mfgrtdir/lib.$machine/libparis.so.6104.0 $libdir
	   ${DEBUG} ranlib -t $libdir/libparis.sa.6104.0
	endif

	${DEBUG} rm -f $libdir/libparisfort-6104.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libparisfort-6104.a $libdir
	${DEBUG} ranlib -t $libdir/libparisfort-6104.a
	${DEBUG} rm -f $libdir/libparisfort-6104-pg.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libparisfort-6104-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libparisfort-6104-pg.a

	${DEBUG} rm -f $libdir/libcmfs-6104.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmfs-6104.a $libdir
	${DEBUG} ranlib -t $libdir/libcmfs-6104.a
	${DEBUG} rm -f $libdir/libcmfs-6104-pg.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmfs-6104-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libcmfs-6104-pg.a

	${DEBUG} rm -f $libdir/libcmrts-1.1-CM2-6104.a
	${DEBUG} rm -f $libdir/libcmrts-1.1-CM2-6104_p.a
	${DEBUG} rm -f $libdir/libcmrts-1.1-CM200-6104.a
	${DEBUG} rm -f $libdir/libcmrts-1.1-CM200-6104_p.a
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmrts-1.1-CM2-6104.a $libdir
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmrts-1.1-CM2-6104_p.a $libdir
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmrts-1.1-CM200-6104.a $libdir
	${DEBUG} cp $mfgrtdir/lib.$machine/libcmrts-1.1-CM200-6104_p.a $libdir
	${DEBUG} ranlib -t $libdir/libcmrts-1.1-CM2-6104.a
	${DEBUG} ranlib -t $libdir/libcmrts-1.1-CM2-6104_p.a
	${DEBUG} ranlib -t $libdir/libcmrts-1.1-CM200-6104.a
	${DEBUG} ranlib -t $libdir/libcmrts-1.1-CM200-6104_p.a
   endif
endif

# ----------------------------------------------------------------------
# Now the header files.  Backups only, as these couldn't be installed
# as symlinks originally
#
/bin/echo
/bin/echo Updating Header files
set incdir = `$cmbssconfig INCLUDE-DIR`

if ( $dobackups ) then
   foreach i ( $mfgrtdir/include/* )
	BackUpFile $incdir/cm/$i:t
	${DEBUG} cp $i $incdir/cm
   end
else
   foreach i ( $mfgrtdir/include/* )
	${DEBUG} rm -f $incdir/cm/$i:t
        ${DEBUG} cp $i $incdir/cm
   end
endif

# ----------------------------------------------------------------------
# Now the microcode.  Again, backups only, as we don't do editting of the
# config file.  Thus, if the user installed the microcode in /usr/local/mumble,
# they'll get in-place backups and the new ucode.  If they originally said "skip"
# when installing the microcode, it was assumed to be "in place", and again
# we'll do backups only.
#
set cm2uc = `$cmbssconfig CM2-UCODE-DIR`
if ( "$cm2uc" != "---not-installed---/" ) then
   /bin/echo
   /bin/echo Updating CM2 microcode

   foreach i ( $mfgrtdir/microcode-cm2/* )
	if ( $dobackups ) then
	   BackUpFile $cm2uc/$i:t
	else
	   ${DEBUG} rm -f $cm2uc/$i:t
	endif
	${DEBUG} cp $i $cm2uc
   end
endif
	
set cm200uc = `$cmbssconfig CM200-UCODE-DIR`
if ( "$cm200uc" != "---not-installed---/" ) then
   /bin/echo
   /bin/echo Updating CM200 microcode

   foreach i ( $mfgrtdir/microcode-cm200/* )
	if ( $dobackups ) then
	   BackUpFile $cm200uc/$i:t
	else
	   ${DEBUG} rm -f $cm200uc/$i:t
	endif
	${DEBUG} cp $i $cm200uc
   end
endif

# ----------------------------------------------------------------------
# NQS.  Unfortunately, you can't tell whether or not NQS was installed or not,
# just from looking at the config file.  If the user said "no", the
# variable has the value of the location of where the tape was untarred (kind
# of like the way the ucode is handled sometimes).  So, we have to do some
# more elaborate testing.  Also, due to stupid NQS permissions, we do this
# by hand.
#
set nqsbin = `$cmbssconfig NQS-USR-DIR`
set nqslib = `$cmbssconfig NQS-LIB-DIR`
if ( ! -e $nqsbin/qmgr ) goto has-no-nqs

/bin/echo
/bin/echo Updating NQS User commands

if ( "$machine" == "sun4" ) then
   set NQS_GROUP = wheel
else
   set NQS_GROUP = system
endif
set NQS_OWNER = root

if ( { /tmp/islink $nqsbin/qmgr } ) then
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqsbin.$machine/qdel
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqsbin.$machine/qdev
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqsbin.$machine/qlimit
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqsbin.$machine/qmgr
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqsbin.$machine/qpr
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqsbin.$machine/qstat
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqsbin.$machine/qsub
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqsbin.$machine/nmapmgr
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqsbin.$machine/shownqs
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqsbin.$machine/startnqs
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqsbin.$machine/stopnqs
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqsbin.$machine/qdel
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqsbin.$machine/qdev
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqsbin.$machine/qlimit
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqsbin.$machine/qmgr
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqsbin.$machine/qpr
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqsbin.$machine/qstat
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqsbin.$machine/qsub
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqsbin.$machine/nmapmgr
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqsbin.$machine/shownqs
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqsbin.$machine/startnqs
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqsbin.$machine/stopnqs
   ${DEBUG} chmod 6111 $mfgrtdir/nqsbin.$machine/qdel
   ${DEBUG} chmod 6111 $mfgrtdir/nqsbin.$machine/qdev
   ${DEBUG} chmod 6111 $mfgrtdir/nqsbin.$machine/qlimit
   ${DEBUG} chmod 6111 $mfgrtdir/nqsbin.$machine/qmgr
   ${DEBUG} chmod 6111 $mfgrtdir/nqsbin.$machine/qpr
   ${DEBUG} chmod 6111 $mfgrtdir/nqsbin.$machine/qstat
   ${DEBUG} chmod 6111 $mfgrtdir/nqsbin.$machine/qsub
   ${DEBUG} chmod 755 $mfgrtdir/nqsbin.$machine/nmapmgr
   ${DEBUG} chmod 755 $mfgrtdir/nqsbin.$machine/shownqs
   ${DEBUG} chmod 744 $mfgrtdir/nqsbin.$machine/startnqs
   ${DEBUG} chmod 744 $mfgrtdir/nqsbin.$machine/stopnqs
   ${DEBUG} rm -f $nqsbin/qdel
   ${DEBUG} rm -f $nqsbin/qdev
   ${DEBUG} rm -f $nqsbin/qlimit
   ${DEBUG} rm -f $nqsbin/qmgr
   ${DEBUG} rm -f $nqsbin/qpr
   ${DEBUG} rm -f $nqsbin/qstat
   ${DEBUG} rm -f $nqsbin/qsub
   ${DEBUG} rm -f $nqsbin/nmapmgr
   ${DEBUG} rm -f $nqsbin/shownqs
   ${DEBUG} rm -f $nqsbin/startnqs
   ${DEBUG} rm -f $nqsbin/stopnqs
   ${DEBUG} ln -s $mfgrtdir/nqsbin.$machine/qdel $nqsbin/qdel
   ${DEBUG} ln -s $mfgrtdir/nqsbin.$machine/qdev $nqsbin/qdev
   ${DEBUG} ln -s $mfgrtdir/nqsbin.$machine/qlimit $nqsbin/qlimit
   ${DEBUG} ln -s $mfgrtdir/nqsbin.$machine/qmgr $nqsbin/qmgr
   ${DEBUG} ln -s $mfgrtdir/nqsbin.$machine/qpr $nqsbin/qpr
   ${DEBUG} ln -s $mfgrtdir/nqsbin.$machine/qstat $nqsbin/qstat
   ${DEBUG} ln -s $mfgrtdir/nqsbin.$machine/qsub $nqsbin/qsub
   ${DEBUG} ln -s $mfgrtdir/nqsbin.$machine/nmapmgr $nqsbin/nmapmgr
   ${DEBUG} ln -s $mfgrtdir/nqsbin.$machine/shownqs $nqsbin/shownqs
   ${DEBUG} ln -s $mfgrtdir/nqsbin.$machine/startnqs $nqsbin/startnqs
   ${DEBUG} ln -s $mfgrtdir/nqsbin.$machine/stopnqs $nqsbin/stopnqs

# Otherwise, they were physical files
else
   if ( $dobackups ) then
	BackUpFile $nqsbin/qdel
 	BackUpFile $nqsbin/qdev
	BackUpFile $nqsbin/qlimit
	BackUpFile $nqsbin/qmgr
	BackUpFile $nqsbin/qpr
	BackUpFile $nqsbin/qstat
	BackUpFile $nqsbin/qsub
	BackUpFile $nqsbin/nmapmgr
	BackUpFile $nqsbin/shownqs
	BackUpFile $nqsbin/startnqs
	BackUpFile $nqsbin/stopnqs
   else
	${DEBUG} rm -f $nqsbin/qdel
	${DEBUG} rm -f $nqsbin/qdev
	${DEBUG} rm -f $nqsbin/qlimit
	${DEBUG} rm -f $nqsbin/qmgr
	${DEBUG} rm -f $nqsbin/qpr
	${DEBUG} rm -f $nqsbin/qstat
	${DEBUG} rm -f $nqsbin/qsub
	${DEBUG} rm -f $nqsbin/nmapmgr
	${DEBUG} rm -f $nqsbin/shownqs
	${DEBUG} rm -f $nqsbin/startnqs
	${DEBUG} rm -f $nqsbin/stopnqs
   endif

   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $mfgrtdir/nqsbin.$machine/qdel $nqsbin/qdel
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $mfgrtdir/nqsbin.$machine/qdev $nqsbin/qdev
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $mfgrtdir/nqsbin.$machine/qlimit $nqsbin/qlimit
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $mfgrtdir/nqsbin.$machine/qmgr $nqsbin/qmgr
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $mfgrtdir/nqsbin.$machine/qpr $nqsbin/qpr
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $mfgrtdir/nqsbin.$machine/qstat $nqsbin/qstat
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $mfgrtdir/nqsbin.$machine/qsub $nqsbin/qsub
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $mfgrtdir/nqsbin.$machine/nmapmgr $nqsbin/nmapmgr
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $mfgrtdir/nqsbin.$machine/shownqs $nqsbin/shownqs
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 744 $mfgrtdir/nqsbin.$machine/startnqs $nqsbin/startnqs
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 744 $mfgrtdir/nqsbin.$machine/stopnqs $nqsbin/stopnqs
endif

/bin/echo
/bin/echo Updating NQS Administrator commands

if ( { /tmp/islink $nqslib/nqsdaemon } ) then
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/lpserver
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/netclient
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/pipeclient
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/shlexefai
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/sitename
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/nqsdaemon
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/logdaemon
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/netdaemon
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/netserver
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/nqsmkdirs
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/nqsmktrans
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/qmgr.hlp
   ${DEBUG} chown $NQS_OWNER $mfgrtdir/nqslib.$machine/qmkdir
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/lpserver
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/netclient
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/pipeclient
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/shlexefai
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/sitename
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/nqsdaemon
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/logdaemon
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/netdaemon
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/netserver
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/nqsmkdirs
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/nqsmktrans
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/qmgr.hlp
   ${DEBUG} chgrp $NQS_GROUP $mfgrtdir/nqslib.$machine/qmkdir
   ${DEBUG} chmod 555 $mfgrtdir/nqslib.$machine/lpserver
   ${DEBUG} chmod 100 $mfgrtdir/nqslib.$machine/netclient
   ${DEBUG} chmod 100 $mfgrtdir/nqslib.$machine/pipeclient
   ${DEBUG} chmod 6111 $mfgrtdir/nqslib.$machine/shlexefai
   ${DEBUG} chmod 744 $mfgrtdir/nqslib.$machine/sitename
   ${DEBUG} chmod 2100 $mfgrtdir/nqslib.$machine/nqsdaemon
   ${DEBUG} chmod 100 $mfgrtdir/nqslib.$machine/logdaemon
   ${DEBUG} chmod 100 $mfgrtdir/nqslib.$machine/netdaemon
   ${DEBUG} chmod 111 $mfgrtdir/nqslib.$machine/netserver
   ${DEBUG} chmod 755 $mfgrtdir/nqslib.$machine/nqsmkdirs
   ${DEBUG} chmod 755 $mfgrtdir/nqslib.$machine/nqsmktrans
   ${DEBUG} chmod 644 $mfgrtdir/nqslib.$machine/qmgr.hlp
   ${DEBUG} chmod 755 $mfgrtdir/nqslib.$machine/qmkdir
   ${DEBUG} rm -f $nqslib/lpserver
   ${DEBUG} rm -f $nqslib/netclient
   ${DEBUG} rm -f $nqslib/pipeclient
   ${DEBUG} rm -f $nqslib/shlexefai
   ${DEBUG} rm -f $nqslib/sitename
   ${DEBUG} rm -f $nqslib/nqsdaemon
   ${DEBUG} rm -f $nqslib/logdaemon
   ${DEBUG} rm -f $nqslib/netdaemon
   ${DEBUG} rm -f $nqslib/netserver
   ${DEBUG} rm -f $nqslib/nqsmkdirs
   ${DEBUG} rm -f $nqslib/nqsmktrans
   ${DEBUG} rm -f $nqslib/qmgr.hlp
   ${DEBUG} rm -f $nqslib/qmkdir
   ${DEBUG} rm -f $nqslib/lpserver
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/lpserver $nqslib/lpserver
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/netclient $nqslib/netclient
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/pipeclient $nqslib/pipeclient
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/shlexefai $nqslib/shlexefai
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/sitename $nqslib/sitename
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/nqsdaemon $nqslib/nqsdaemon
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/logdaemon $nqslib/logdaemon
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/netdaemon $nqslib/netdaemon
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/netserver $nqslib/netserver
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/nqsmkdirs $nqslib/nqsmkdirs
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/nqsmktrans $nqslib/nqsmktrans
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/qmgr.hlp $nqslib/qmgr.hlp
   ${DEBUG} ln -s $mfgrtdir/nqslib.$machine/qmkdir $nqslib/qmkdir
# They must be real files...
else
   if ( $dobackups ) then
	BackUpFile $nqslib/lpserver
	BackUpFile $nqslib/netclient
	BackUpFile $nqslib/pipeclient
	BackUpFile $nqslib/shlexefai
	BackUpFile $nqslib/sitename
	BackUpFile $nqslib/nqsdaemon
	BackUpFile $nqslib/logdaemon
	BackUpFile $nqslib/netdaemon
	BackUpFile $nqslib/netserver
	BackUpFile $nqslib/nqsmkdirs
	BackUpFile $nqslib/nqsmktrans
	BackUpFile $nqslib/qmgr.hlp
	BackUpFile $nqslib/qmkdir
	BackUpFile $nqslib/lpserver
   else
	${DEBUG} rm -f $nqslib/lpserver
	${DEBUG} rm -f $nqslib/netclient
	${DEBUG} rm -f $nqslib/pipeclient
	${DEBUG} rm -f $nqslib/shlexefai
	${DEBUG} rm -f $nqslib/sitename
	${DEBUG} rm -f $nqslib/nqsdaemon
	${DEBUG} rm -f $nqslib/logdaemon
	${DEBUG} rm -f $nqslib/netdaemon
	${DEBUG} rm -f $nqslib/netserver
	${DEBUG} rm -f $nqslib/nqsmkdirs
	${DEBUG} rm -f $nqslib/nqsmktrans
	${DEBUG} rm -f $nqslib/qmgr.hlp
	${DEBUG} rm -f $nqslib/qmkdir
	${DEBUG} rm -f $nqslib/lpserver
   endif

   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 555 $mfgrtdir/nqslib.$machine/lpserver $nqslib/lpserver
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $mfgrtdir/nqslib.$machine/netclient $nqslib/netclient
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $mfgrtdir/nqslib.$machine/pipeclient $nqslib/pipeclient
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $mfgrtdir/nqslib.$machine/shlexefai $nqslib/shlexefai
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 744 $mfgrtdir/nqslib.$machine/sitename $nqslib/sitename
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 2100 $mfgrtdir/nqslib.$machine/nqsdaemon $nqslib/nqsdaemon
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $mfgrtdir/nqslib.$machine/logdaemon $nqslib/logdaemon
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $mfgrtdir/nqslib.$machine/netdaemon $nqslib/netdaemon
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 111 $mfgrtdir/nqslib.$machine/netserver $nqslib/netserver
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $mfgrtdir/nqslib.$machine/nqsmkdirs $nqslib/nqsmkdirs
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $mfgrtdir/nqslib.$machine/nqsmktrans $nqslib/nqsmktrans
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $mfgrtdir/nqslib.$machine/qmkdir $nqslib/qmkdir

endif
# Phew!

has-no-nqs:

# ----------------------------------------------------------------------
# Man pages.  No option of backup here, even.
#
set mandirs = `$cmbssconfig ONLINE-MANPAGE-DIRS`
set mandir  = `echo $mandirs | awk -F: '{print $1}'`
set mandir  = $mandir:h

/bin/echo
/bin/echo Updating Manual pages

pushd $mfgrtdir/man >& /dev/null
tar cf - . | (cd $mandir; tar xfp -) >& /dev/null
popd >& /dev/null

# ----------------------------------------------------------------------
# All done.  Remind user to do the CM device driver.

/bin/echo
/bin/echo Patch installation complete.
/bin/echo
/bin/echo Please install the files in $mfgrtdir/sys
/bin/echo into the suncm or vaxcm directory where you install kernels,
/bin/echo and rebuild the kernel for your front-end to get the patches
/bin/echo to the CM device driver.
/bin/echo

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
