#! /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 'Restoring the old /usr/include include files'
    cd /usr/include
    foreach i (`tar tf $tar`)
      if ( -f $i-old ) cp $i-old $i
    end
    set new_ui=y
  endif
  if ( -d $sys/sundev ) then
    echo 'Restoring the old '$sys' include files'
    cd $sys
    foreach i (`tar tf $tar`)
      if ( -f $i-old ) cp $i-old $i
    end
    set new_si=y
    set tar=$here/srcs.tar
    if ( -f $tar ) then
	echo 'Restoring the old source files'
	cd $sys
	foreach i (`tar tf $tar`)
	  if ( -f $i-old ) cp $i-old $i
	end
	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 'Restoring the old '$ta' drivers'
    foreach i (`tar tf $here/$ta.tar`)
      if ( -f $i-old ) cp $i-old $i
    end
    set new_ob=y
    if ( -f flower.o ) then
     if ( -d $sys/$ta/conf ) then
      cd $sys/$ta/conf
      if ( -f files-old ) then
	echo 'Restoring '$ta' files list'
	cp files-old 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-old ) then
        echo 'Restoring sysdiag printer test'
        cp printer-old printer
      else
        set new_pr=n
      endif
    else
      set new_pr=n
    endif
  endif
  if ( x$new_sk == xy ) then
    cd /usr/etc
    if ( -f skyrc-old ) then
      echo 'Restoring sky startup code'
      cp skyrc-old 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
	restored in your standard include directory. User level programs
	that need to know details about the serial devices and that
	may have been recompiled with the patched include files may
	need to be recompiled, again.
'END'
if ( x$new_si == xy ) then
  cat <<'END'

	Several include files relating to serial drivers have been
	restored in your system include directory. Everything that
	depends on these files should be recompiled. The kernel
	makefiles should be able to handle the task.
'END'
endif
if ( x$new_ss == xy ) then
  cat <<'END'

	Some kernel source files have been restored. If you change
	source files, you might want to make sure that any new changes
	were also applied to the -old files. You may want to recompile
	from source anyway.
'END'
if ( x$new_ob == xy ) then
  cat <<'END'

	Several object modules have been restored 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 restored.
'END'
endif
if ( x$new_sk == xy ) then
  cat <<'END'

	The initialization code for your Sky board has been restored.
'END'
endif
