#! /bin/csh -fx
set arch=`arch` here=`pwd` sys=/sys
set new_ob=n new_pr=n new_si=n new_sk=n new_ss=n new_ui=n
if ( ! -f $here/$arch.tar ) set here=/tmp
if ( ! -f $here/$arch.tar ) set here=/usr/tmp
if ( ! -f $here/$arch.tar ) then
  echo 'unable to find '$arch'.tar'
  echo 'extract tape into /tmp or /usr/tmp and try again.'
  exit 1
endif
echo $arch'.tar found in '$here
set tar=$here/incs.tar
if ( -f $tar ) then
  if ( -d /usr/include/sundev ) then
    echo 'Saving the old /usr/include include files'
    cd /usr/include
    foreach i (`tar tf $tar`)
      if ( -f $i ) mv $i $i-old
    end
    echo Installing new include files in /usr/include
    tar xvf $tar
    touch `tar tf $tar`
    set new_ui=y
  endif
  if ( -d $sys/sundev ) then
    echo 'Saving the old '$sys' include files'
    cd $sys
    foreach i (`tar tf $tar`)
      if ( -f $i ) mv $i $i-old
    end
    echo 'Installing new include files in '$sys
    tar xvf $tar
    touch `tar tf $tar`
    set new_si=y
    set tar=$here/srcs.tar
    if ( -f $tar ) then
	echo 'Saving the old source files'
	cd $sys
	foreach i (`tar tf $tar`)
	  if ( -f $i ) mv $i $i-old
	end
	echo 'Installing new source files in '$sys/...
	tar xvf $tar
 	touch `tar tf $tar`
	set new_ss=y
    endif
  endif
endif
set tar=$here/$arch.tar
foreach ta (sun2 sun3 sun4)
 if ( -f $here/$ta.tar ) then
  if ( -d $sys/$ta/OBJ ) then
    cd $sys/$ta/OBJ
    echo 'Saving the old '$ta' drivers'
    foreach i (`tar tf $here/$ta.tar`)
      if ( -f $i ) mv $i $i-old
    end
    echo 'Extracting new drivers into '$ta'/OBJ'
    tar xvf $here/$ta.tar `tar tf $here/$ta.tar | grep '\.o$'`
    touch `tar tf $here/$ta.tar | grep '\.o$'`
    set new_ob=y
    if ( -f flower.o ) then
     if ( -d $sys/$ta/conf ) then
      cd $sys/$ta/conf
      grep -s '^sun/flower.c	' files
      if ( $status == 1 ) then
	echo 'Adding flow control module to '$ta' files list'
	mv files files-old
	cp files-old files
	echo 'sun/flower.c	standard' >> files
      endif
    endif
   endif
  endif
 endif
end
if ( -f $tar ) then
  tar tf $tar | grep -s printer
  if ( $status == 0 ) set new_pr=y
  tar tf $tar | grep -s skyrc
  if ( $status == 0 ) set new_sk=y
  if ( x$new_pr == xy ) then
    if ( -d ~sysdiag ) then
      cd ~sysdiag
      if ( -f printer ) then
        rm -f printer-old
        mv -f printer printer-old
      endif
      echo 'Extracting new sysdiag printer test module'
      tar xvf $tar printer
    else
      set new_pr=n
    endif
  endif
  if ( x$new_sk == xy ) then
    cd /usr/etc
    if ( -f skyrc ) then
      rm -f skyrc-old
      mv -f skyrc skyrc-old
      echo 'Extracting new sky startup code'
      tar xvf $tar skyrc
    else
      set new_sk=n
    endif
  endif
endif
if ( x$new_ui == xy ) then
  cat <<'END'

	Several include files relating to serial drivers have been
	changed in your standard include directory. User level programs
	that need to know details about the serial devices may need to
	be recompiled; try them first.
'END'
endif
if ( x$new_si == xy ) then
  cat <<'END'

	Several include files relating to serial drivers have been
	changed in your system include directory. Locally written
	device drivers that need to know details about the serial
	devices may need to be recompiled. The kernel makefiles should
	be able to handle this.
'END'
endif
if ( x$new_ss == xy ) then
  cat <<'END'

	Some kernel source files have been updated; the old files have
	been saved under the old name with "-old" appended. If you
	changed these source files, you will need to merge your changes
	into the new files. You may want to recompile from source
	anyway.
'END'
endif
if ( x$new_ob == xy ) then
  cat <<'END'

	Several object modules have been updated in your system OBJ
	directory. If you configure your own kernels, you should go back
	to the "conf" directory, do another "config" on your kernel, and
	another "make" in the build directory.
'END'
endif
if ( x$new_pr == xy ) then
  cat <<'END'

	Sysdiag's printer test has been replaced.
'END'
endif
if ( x$new_sk == xy ) then
  cat <<'END'

	The initialization code for your Sky board has been replaced.
'END'
endif
if ( x'$new_ss''$new_ob' == x ) then
  cat <<'END'

	Things look just too weird for this script. I cant seem to get
	a new system together for you. Look at the contents of the tape
	by hand and give it your best shot, or call an expert.
'END'
endif
