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

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

if( $1 != "" ) then
	set mfgrtdir = $1/${rtdir}
else
	set mfgrtdir = `pwd | sed -e s,/tmp_mnt,,`/${rtdir}
endif
set rel_dir = `pwd | sed -e s,/tmp_mnt,,`
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

if ( -f /tmp/dirname.$$ ) then
	rm -f /tmp/dirname.$$
endif

cat > /tmp/dirname.$$ <<'EOF'
#! /bin/sh
#
#       @(#)dirname.sh 1.5 89/03/22 SMI; from S5R2 1.2
#
PATH=/bin:/usr/bin
expr \
  ${1-.}'/' : '\(/\)[^/]*//*$' \
  \| ${1-.}'/' : '\(.*[^/]\)//*[^/][^/]*//*$' \
  \| .
'EOF'

chmod a+x /tmp/dirname.$$
set dirname="/tmp/dirname.$$"

echo "This program will merge 6.1.1 and 6.1.2 release together."
echo "It must be run in the directory where you tar the"
echo "6.1.2 release.  It will *NOT* try to back up your file"

echo -n "Have you backup your file?  Hit return to continue, ^C to abort "

set a = $<

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]} >& /dev/null"'

# 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 = `/bin/ls -ld $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.2 CM2 Base System Software
Patch 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:





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


get-runtime:
set run = ""
/bin/echo -n "What is the name of you run time system directory [/usr/cm/cm-runtime-6104] ?"
set runtime = $<

if ( "$runtime" == "" ) then
	set runtime = /usr/cm/cm-runtime-6104
endif

if ( ! -d "$runtime" ) then
	echo
	echo "$runtime does not exist."
	echo
	goto get-runtime
endif

get-required:
set required = ""
/bin/echo -n "Where is the cm-required files [`$dirname $runtime`/cm-required] ?"
set required = $<

if ( "$required" == "" ) then
	set required = `$dirname $runtime`/cm-required
endif

if ( ! -d "$required" ) then
	echo "$required does not exist."
	goto get-required
endif

get-bands:
set bands = ""
/bin/echo -n "Where is the lisp-bands files [`$dirname $runtime`/bands] ?"
set bands = $<

if ( "$bands" == "" ) then
	set bands = `$dirname $runtime`/bands
endif

if ( ! -d "$bands" ) then
	echo "$bands does not exist."
	goto get-bands
endif


# ----------------------------------------------------------------------
# Find out where the user would like the "bug update" files installed
qbugupdate:
set qtag = bugupdate
set q = "Location to install the online bug update files (path,skip)?"

set default=`$cmbssconfig BUG-UPDATE-FILES`
set default_from_file = 0
if ( "$default" == "" ) then
	set default="/usr/cm/doc"
else
	set default_from_file = 1
endif

set orig_default = $default

goto ask

help-bugupdate:
   /bin/echo The bug update files contain information about specific
   /bin/echo customer-reported bugs that have been fixed in this patch
   /bin/echo release.  These bug update files will be sent out by TMC
   /bin/echo on a regular basis to allow customers to track the progress
   /bin/echo of a bug they have reported.
   goto qbugupdate

ret-bugupdate:
   set bug_loc = "$mfgrtdir/bugupdate"
   if("$a" == "skip") goto endbugupdate

   if( ! -e $a ) mkdir -p $a

   ${DEBUG} cp $bug_loc/* $a

   if( ! $default_from_file ) then
      echo "" >> $cmbssconfig
      echo "# Location of the bug update files" >> $cmbssconfig
      echo "BUG-UPDATE-FILES = $a" >> $cmbssconfig
   else
      if( $a != $orig_default ) then
	sed -e s,"BUG-UPDATE-FILES = $orig_default","BUG-UPDATE-FILES = $a", $cmbssconfig > /tmp/foobie
	cp /tmp/foobie $cmbssconfig
	rm /tmp/foobie
      endif
   endif

endbugupdate:


/bin/echo
/bin/echo Updating User commands

cd $rel_dir
set bindir = `$cmbssconfig BIN-DIR`
if ( ! -d ./cm-runtime-6104 ) then
	echo "Are you in the 6.1.2 directory? "
	echo "6.1.2 cm-runtime-6104 not found, stop."
	exit 0
endif

cd ./cm-runtime-6104; tar cf - . | (cd $runtime; tar xBpf - )
cd $rel_dir

/bin/echo "Updating lisp bands directory($bands)"
cd ./bands.$machine; tar cf - . | (cd $bands; tar xBf -)
cd $rel_dir


/bin/echo "Updating the cm-required directory($required)."
cd ./cm-required; tar cf - . | (cd $required; tar xBpf - )
cd $rel_dir



# ----------------------------------------------------------------------
# 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
#
cd $rel_dir/cm-runtime-6104/lib.$machine

/bin/echo
/bin/echo Updating User commands
set bindir = `$cmbssconfig BIN-DIR`

cd $rel_dir

if ( { /tmp/islink $bindir/cmattach } ) then
   /bin/echo User commands installed as symlinks
   foreach i ( `/bin/ls ./cm-runtime-6104/bin.$machine/` )
	${DEBUG} rm -f $bindir/$i:t
	${DEBUG} ln -s $runtime/bin.$machine/$i $bindir/$i:t
   end
else
   /bin/echo User commands installed as files
   foreach i ( `/bin/ls ./cm-runtime-6104/bin.$machine/` )
	${DEBUG} rm -f $bindir/$i:t
	${DEBUG} cp ./cm-runtime-6104/bin.$machine/$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 ( `/bin/ls ./cm-runtime-6104/etc.$machine/` )
	${DEBUG} rm -f $etcdir/$i:t
	${DEBUG} ln -s $runtime/etc.$machine/$i $etcdir/$i:t
   end
else
   /bin/echo Administrator commands installed as files
   foreach i ( `/bin/ls ./cm-runtime-6104/etc.$machine/` )
	${DEBUG} rm -f $etcdir/$i:t
	${DEBUG} cp ./cm-runtime-6104/etc.$machine/$i $etcdir/$i:t
   end
endif

#
# Special handling for the coldboot-paris and ts-daemon command
#
${DEBUG} rm -f $etcdir/coldboot-paris
${DEBUG} ln -s $etcdir/coldboot-paris-6104 $etcdir/coldboot-paris

${DEBUG} rm -f $etcdir/ts-daemon
${DEBUG} ln -s $etcdir/ts-daemon-6104 $etcdir/ts-daemon

cd $runtime/lib.$machine
rm libckpt.a
rm libckpt-pg.a
rm libcmfe.a
rm libcmfe-pg.a
rm libcmfs.a
rm libcmfs-pg.a
rm libparisfort.a
rm libparisfort-pg.a
rm libtoolkit.a
rm libtoolkit-pg.a
ln -s libckpt-6104.a libckpt.a
ln -s libckpt-6104-pg.a libckpt-pg.a
ln -s libcmfe-6104.a libcmfe.a
ln -s libcmfe-6104-pg.a libcmfe-pg.a
ln -s libcmfs-6104.a libcmfs.a
ln -s libcmfs-6104-pg.a libcmfs-pg.a
ln -s libparisfort-6104.a libparisfort.a
ln -s libparisfort-6104-pg.a libparisfort-pg.a
ln -s libtoolkit-6104.a libtoolkit.a
ln -s libtoolkit-6104-pg.a libtoolkit-pg.a




# ----------------------------------------------------------------------
# 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 $runtime/lib.$machine/libparis2-6104.a $libdir/libparis2-6104.a
   ${DEBUG} ln -s $runtime/lib.$machine/libparis2-6104.a $libdir/libparis.a
   ${DEBUG} ln -s $runtime/lib.$machine/libparis2-6104.a $libdir/libparis2.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/libparis2-6104.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 $runtime/lib.$machine/libparis2-6104-pg.a $libdir/libparis2-6104-pg.a
   ${DEBUG} ln -s $runtime/lib.$machine/libparis2-6104-pg.a $libdir/libparis-pg.a
   ${DEBUG} ln -s $runtime/lib.$machine/libparis2-6104-pg.a $libdir/libparis2-pg.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/libparis2-6104-pg.a
   
   ${DEBUG} rm -f $libdir/libckpt.a
   ${DEBUG} ln -s $runtime/lib.$machine/libckpt-6104.a $libdir/libckpt.a
   ${DEBUG} rm -f $libdir/libckpt-6104.a
   ${DEBUG} ln -s $runtime/lib.$machine/libckpt-6104.a $libdir/libckpt-6104.a
   ${DEBUG} rm -f $libdir/libckpt-pg.a
   ${DEBUG} ln -s $runtime/lib.$machine/libckpt-6104-pg.a $libdir/libckpt-pg.a
   ${DEBUG} rm -f $libdir/libckpt-6104-pg.a
   ${DEBUG} ln -s $runtime/lib.$machine/libckpt-6104-pg.a $libdir/libckpt-6104-pg.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/libckpt-6104.a 
   ${DEBUG} ranlib -t $runtime/lib.$machine/libckpt-6104-pg.a 


   ${DEBUG} rm -f $libdir/libcmfe.a
   ${DEBUG} ln -s $runtime/lib.$machine/libcmfe-6104.a $libdir/libcmfe.a
   ${DEBUG} rm -f $libdir/libcmfe-6104.a
   ${DEBUG} ln -s $runtime/lib.$machine/libcmfe-6104.a $libdir/libcmfe-6104.a
   ${DEBUG} rm -f $libdir/libcmfe-pg.a
   ${DEBUG} ln -s $runtime/lib.$machine/libcmfe-6104-pg.a $libdir/libcmfe-pg.a
   ${DEBUG} rm -f $libdir/libcmfe-6104-pg.a
   ${DEBUG} ln -s $runtime/lib.$machine/libcmfe-6104-pg.a $libdir/libcmfe-6104-pg.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/libcmfe-6104.a 
   ${DEBUG} ranlib -t $runtime/lib.$machine/libcmfe-6104-pg.a 


   ${DEBUG} rm -f $libdir/libtoolkit.a
   ${DEBUG} ln -s $runtime/lib.$machine/libtoolkit-6104.a $libdir/libtoolkit.a
   ${DEBUG} rm -f $libdir/libtoolkit-6104.a
   ${DEBUG} ln -s $runtime/lib.$machine/libtoolkit-6104.a $libdir/libtoolkit-6104.a
   ${DEBUG} rm -f $libdir/libtoolkit-pg.a
   ${DEBUG} ln -s $runtime/lib.$machine/libtoolkit-6104-pg.a $libdir/libtoolkit-pg.a
   ${DEBUG} rm -f $libdir/libtoolkit-6104-pg.a
   ${DEBUG} ln -s $runtime/lib.$machine/libtoolkit-6104-pg.a $libdir/libtoolkit-6104-pg.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/libtoolkit-6104.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/libtoolkit-6104-pg.a


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

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


   ${DEBUG} rm -f $libdir/libcmfs.a
   ${DEBUG} rm -f $libdir/libcmfs-6104.a
   ${DEBUG} ln -s $runtime/lib.$machine/libcmfs-6104.a $libdir/libcmfs-6104.a
   ${DEBUG} ln -s $runtime/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 $runtime/lib.$machine/libcmfs-6104-pg.a $libdir/libcmfs-6104-pg.a
   ${DEBUG} ln -s $runtime/lib.$machine/libcmfs-6104-pg.a $libdir/libcmfs-pg.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/libcmfs-6104.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/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} ln -s $runtime/lib.$machine/libcmrts-1.1-CM2-6104.a $libdir/libcmrts-1.1-CM2-6104.a
   ${DEBUG} ln -s $runtime/lib.$machine/libcmrts-1.1-CM2-6104_p.a $libdir/libcmrts-1.1-CM2-6104_p.a
   ${DEBUG} ln -s $runtime/lib.$machine/libcmrts-1.1-CM200-6104.a $libdir/libcmrts-1.1-CM200-6104.a
   ${DEBUG} ln -s $runtime/lib.$machine/libcmrts-1.1-CM200-6104.a $libdir/libcmrts-1.1-CM200-6104_p.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/libcmrts-1.1-CM2-6104.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/libcmrts-1.1-CM2-6104_p.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/libcmrts-1.1-CM200-6104.a
   ${DEBUG} ranlib -t $runtime/lib.$machine/libcmrts-1.1-CM200-6104_p.a


   ${DEBUG} ln -s $runtime/lib.$machine/libcmfs-stubs.o $libdir

else
   /bin/echo Libraries installed as files
	cd $libdir
	${DEBUG} rm libparis.a libparis2.a
	${DEBUG} ln -s libparis2-6104.a libparis.a
	${DEBUG} ln -s libparis2-6104.a libparis2.a
	${DEBUG} ln -s $runtime/lib.$machine/libparis2-6104.a $libdir/libparis.a

	${DEBUG} rm -f $libdir/libparis2-6104.a
	${DEBUG} cp $runtime/lib.$machine/libparis2-6104.a $libdir
	${DEBUG} ranlib -t $libdir/libparis2-6104.a
	${DEBUG} rm -f $libdir/libparis2-6104-pg.a
	${DEBUG} cp $runtime/lib.$machine/libparis2-6104-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libparis2-6104-pg.a
	${DEBUG} rm libparis2-pg.a
	${DEBUG} ln -s libparis2-6104-pg.a libparis2-pg.a

	${DEBUG} rm -f $libdir/libckpt-6104.a
	${DEBUG} cp $runtime/lib.$machine/libckpt-6104.a $libdir
	${DEBUG} ranlib -t $libdir/libckpt-6104.a
	${DEBUG} rm -f $libdir/libckpt-6104-pg.a
	${DEBUG} cp $runtime/lib.$machine/libckpt-6104-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libckpt-6104-pg.a
	${DEBUG} rm libckpt.a libckpt-pg.a
	${DEBUG} ln -s libckpt-6104.a libckpt.a
	${DEBUG} ln -s libckpt-6104-pg.a libckpt-pg.a


	${DEBUG} rm -f $libdir/libcmfe-6104.a
	${DEBUG} cp $runtime/lib.$machine/libcmfe-6104.a $libdir
	${DEBUG} ranlib -t $libdir/libcmfe-6104.a
	${DEBUG} rm -f $libdir/libcmfe-6104-pg.a
	${DEBUG} cp $runtime/lib.$machine/libcmfe-6104-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libcmfe-6104-pg.a
	${DEBUG} rm libcmfe.a libcmfe-pg.a
	${DEBUG} ln -s libcmfe-6104.a libcmfe.a
	${DEBUG} ln -s libcmfe-6104-pg.a libcmfe-pg.a

	${DEBUG} rm -f $libdir/libtoolkit-6104.a
	${DEBUG} cp $runtime/lib.$machine/libtoolkit-6104.a $libdir
	${DEBUG} ranlib -t $libdir/libtoolkit-6104.a
	${DEBUG} rm -f $libdir/libtoolkit-6104-pg.a
	${DEBUG} cp $runtime/lib.$machine/libtoolkit-6104-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libtoolkit-6104-pg.a
	${DEBUG} rm libtoolkit.a libtoolkit-pg.a
	${DEBUG} ln -s libtoolkit-6104.a libtoolkit.a
	${DEBUG} ln -s libtoolkit-6104-pg.a libtoolkit-pg.a

	if ( $machine == sun4 ) then
	   ${DEBUG} rm -f $libdir/libparis2-6104.sa.6104.0
	   ${DEBUG} rm -f $libdir/libparis2-6104.so.6104.0
	   ${DEBUG} cp $runtime/lib.$machine/libparis2-6104.sa.6104.0 $libdir
	   ${DEBUG} cp $runtime/lib.$machine/libparis2-6104.so.6104.0 $libdir
	   ${DEBUG} ranlib -t $libdir/libparis2-6104.sa.6104.0
	   ${DEBUG} rm -f $libdir/libparis.sa.6104.0
	   ${DEBUG} rm -f $libdir/libparis.so.6104.0
	   ${DEBUG} ln -s $libdir/libparis2-6104.sa.6104.0 $libdir/libparis.sa.6104.0
	   ${DEBUG} ln -s $libdir/libparis2-6104.so.6104.0 $libdir/libparis.so.6104.0
	endif

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

	${DEBUG} rm -f $libdir/libcmfs-6104.a
	${DEBUG} cp $runtime/lib.$machine/libcmfs-6104.a $libdir
	${DEBUG} ranlib -t $libdir/libcmfs-6104.a
	${DEBUG} rm -f $libdir/libcmfs-6104-pg.a
	${DEBUG} cp $runtime/lib.$machine/libcmfs-6104-pg.a $libdir
	${DEBUG} ranlib -t $libdir/libcmfs-6104-pg.a
	${DEBUG} rm libcmfs.a libcmfs-pg.a
	${DEBUG} ln -s libcmfs-6104.a libcmfs.a
	${DEBUG} ln -s libcmfs-6104-pg.a 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} cp $runtime/lib.$machine/libcmrts-1.1-CM2-6104.a $libdir
	${DEBUG} cp $runtime/lib.$machine/libcmrts-1.1-CM2-6104_p.a $libdir
	${DEBUG} cp $runtime/lib.$machine/libcmrts-1.1-CM200-6104.a $libdir
	${DEBUG} cp $runtime/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

	${DEBUG} cp $runtime/lib.$machine/libcmfs-stubs.o $libdir

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`

foreach i ( $mfgrtdir/include/cm/* )
	${DEBUG} rm -f $incdir/cm/$i:t
        ${DEBUG} cp $i $incdir/cm
end

# ----------------------------------------------------------------------
# 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/* )
	${DEBUG} rm -f $cm2uc/$i:t
 	${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 ( $runtime/microcode-cm200/* )
	${DEBUG} rm -f $cm200uc/$i:t
	${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 $runtime/nqsbin.$machine/qdel
   ${DEBUG} chown $NQS_OWNER $runtime/nqsbin.$machine/qdev
   ${DEBUG} chown $NQS_OWNER $runtime/nqsbin.$machine/qlimit
   ${DEBUG} chown $NQS_OWNER $runtime/nqsbin.$machine/qmgr
   ${DEBUG} chown $NQS_OWNER $runtime/nqsbin.$machine/qpr
   ${DEBUG} chown $NQS_OWNER $runtime/nqsbin.$machine/qstat
   ${DEBUG} chown $NQS_OWNER $runtime/nqsbin.$machine/qsub
   ${DEBUG} chown $NQS_OWNER $runtime/nqsbin.$machine/nmapmgr
   ${DEBUG} chown $NQS_OWNER $runtime/nqsbin.$machine/shownqs
   ${DEBUG} chown $NQS_OWNER $runtime/nqsbin.$machine/startnqs
   ${DEBUG} chown $NQS_OWNER $runtime/nqsbin.$machine/stopnqs
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqsbin.$machine/qdel
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqsbin.$machine/qdev
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqsbin.$machine/qlimit
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqsbin.$machine/qmgr
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqsbin.$machine/qpr
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqsbin.$machine/qstat
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqsbin.$machine/qsub
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqsbin.$machine/nmapmgr
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqsbin.$machine/shownqs
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqsbin.$machine/startnqs
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqsbin.$machine/stopnqs
   ${DEBUG} chmod 6111 $runtime/nqsbin.$machine/qdel
   ${DEBUG} chmod 6111 $runtime/nqsbin.$machine/qdev
   ${DEBUG} chmod 6111 $runtime/nqsbin.$machine/qlimit
   ${DEBUG} chmod 6111 $runtime/nqsbin.$machine/qmgr
   ${DEBUG} chmod 6111 $runtime/nqsbin.$machine/qpr
   ${DEBUG} chmod 6111 $runtime/nqsbin.$machine/qstat
   ${DEBUG} chmod 6111 $runtime/nqsbin.$machine/qsub
   ${DEBUG} chmod 755 $runtime/nqsbin.$machine/nmapmgr
   ${DEBUG} chmod 755 $runtime/nqsbin.$machine/shownqs
   ${DEBUG} chmod 744 $runtime/nqsbin.$machine/startnqs
   ${DEBUG} chmod 744 $runtime/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 $runtime/nqsbin.$machine/qdel $nqsbin/qdel
   ${DEBUG} ln -s $runtime/nqsbin.$machine/qdev $nqsbin/qdev
   ${DEBUG} ln -s $runtime/nqsbin.$machine/qlimit $nqsbin/qlimit
   ${DEBUG} ln -s $runtime/nqsbin.$machine/qmgr $nqsbin/qmgr
   ${DEBUG} ln -s $runtime/nqsbin.$machine/qpr $nqsbin/qpr
   ${DEBUG} ln -s $runtime/nqsbin.$machine/qstat $nqsbin/qstat
   ${DEBUG} ln -s $runtime/nqsbin.$machine/qsub $nqsbin/qsub
   ${DEBUG} ln -s $runtime/nqsbin.$machine/nmapmgr $nqsbin/nmapmgr
   ${DEBUG} ln -s $runtime/nqsbin.$machine/shownqs $nqsbin/shownqs
   ${DEBUG} ln -s $runtime/nqsbin.$machine/startnqs $nqsbin/startnqs
   ${DEBUG} ln -s $runtime/nqsbin.$machine/stopnqs $nqsbin/stopnqs

# Otherwise, they were physical files
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

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

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

if ( { /tmp/islink $nqslib/nqsdaemon } ) then
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/lpserver
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/netclient
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/pipeclient
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/shlexefai
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/sitename
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/nqsdaemon
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/logdaemon
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/netdaemon
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/netserver
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/nqsmkdirs
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/nqsmktrans
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/qmgr.hlp
   ${DEBUG} chown $NQS_OWNER $runtime/nqslib.$machine/qmkdir
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/lpserver
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/netclient
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/pipeclient
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/shlexefai
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/sitename
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/nqsdaemon
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/logdaemon
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/netdaemon
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/netserver
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/nqsmkdirs
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/nqsmktrans
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/qmgr.hlp
   ${DEBUG} chgrp $NQS_GROUP $runtime/nqslib.$machine/qmkdir
   ${DEBUG} chmod 555 $runtime/nqslib.$machine/lpserver
   ${DEBUG} chmod 100 $runtime/nqslib.$machine/netclient
   ${DEBUG} chmod 100 $runtime/nqslib.$machine/pipeclient
   ${DEBUG} chmod 6111 $runtime/nqslib.$machine/shlexefai
   ${DEBUG} chmod 744 $runtime/nqslib.$machine/sitename
   ${DEBUG} chmod 2100 $runtime/nqslib.$machine/nqsdaemon
   ${DEBUG} chmod 100 $runtime/nqslib.$machine/logdaemon
   ${DEBUG} chmod 100 $runtime/nqslib.$machine/netdaemon
   ${DEBUG} chmod 111 $runtime/nqslib.$machine/netserver
   ${DEBUG} chmod 755 $runtime/nqslib.$machine/nqsmkdirs
   ${DEBUG} chmod 755 $runtime/nqslib.$machine/nqsmktrans
   ${DEBUG} chmod 644 $runtime/nqslib.$machine/qmgr.hlp
   ${DEBUG} chmod 755 $runtime/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 $runtime/nqslib.$machine/lpserver $nqslib/lpserver
   ${DEBUG} ln -s $runtime/nqslib.$machine/netclient $nqslib/netclient
   ${DEBUG} ln -s $runtime/nqslib.$machine/pipeclient $nqslib/pipeclient
   ${DEBUG} ln -s $runtime/nqslib.$machine/shlexefai $nqslib/shlexefai
   ${DEBUG} ln -s $runtime/nqslib.$machine/sitename $nqslib/sitename
   ${DEBUG} ln -s $runtime/nqslib.$machine/nqsdaemon $nqslib/nqsdaemon
   ${DEBUG} ln -s $runtime/nqslib.$machine/logdaemon $nqslib/logdaemon
   ${DEBUG} ln -s $runtime/nqslib.$machine/netdaemon $nqslib/netdaemon
   ${DEBUG} ln -s $runtime/nqslib.$machine/netserver $nqslib/netserver
   ${DEBUG} ln -s $runtime/nqslib.$machine/nqsmkdirs $nqslib/nqsmkdirs
   ${DEBUG} ln -s $runtime/nqslib.$machine/nqsmktrans $nqslib/nqsmktrans
   ${DEBUG} ln -s $runtime/nqslib.$machine/qmgr.hlp $nqslib/qmgr.hlp
   ${DEBUG} ln -s $runtime/nqslib.$machine/qmkdir $nqslib/qmkdir
# They must be real files...
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} install -c -o $NQS_OWNER -g $NQS_GROUP -m 555 $runtime/nqslib.$machine/lpserver $nqslib/lpserver
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $runtime/nqslib.$machine/netclient $nqslib/netclient
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $runtime/nqslib.$machine/pipeclient $nqslib/pipeclient
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 6111 $runtime/nqslib.$machine/shlexefai $nqslib/shlexefai
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 744 $runtime/nqslib.$machine/sitename $nqslib/sitename
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 2100 $runtime/nqslib.$machine/nqsdaemon $nqslib/nqsdaemon
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $runtime/nqslib.$machine/logdaemon $nqslib/logdaemon
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 100 $runtime/nqslib.$machine/netdaemon $nqslib/netdaemon
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 111 $runtime/nqslib.$machine/netserver $nqslib/netserver
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $runtime/nqslib.$machine/nqsmkdirs $nqslib/nqsmkdirs
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $runtime/nqslib.$machine/nqsmktrans $nqslib/nqsmktrans
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 444 $runtime/nqslib.$machine/qmgr.hlp $nqslib/qmgr.hlp
   ${DEBUG} install -c -o $NQS_OWNER -g $NQS_GROUP -m 755 $runtime/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 $runtime/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

if ( -f /tmp/dirname.$$ ) then
	rm -f /tmp/dirname.$$
endif


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




