#!/bin/csh -f
#
# @(#)@(#)tr_deinstall.sh	1.12 9/29/93 Copyright SMI 1991
#
#   Copyright (c) 1988 by Sun Microsystems, Inc.
#
#
#  tr_deinstall:  Cshell Script to Restore the Kernel and system files
#    to the state before installing the SunNet TRI/S product.
#
#   Arguments:
#
#   Exit Conditions:
#
#	In any case where an error in this procedure is detected, an immediate
#  exit with a negative code will be taken.
#
#
unalias rm
unalias cat
unset noclobber
setenv PATH /usr/ucb:/bin:/usr/bin:/etc:/usr/etc

set PRODUCT="TRIS"
set product="tris"

set ARCH = `arch`
set ARCHK = `arch -k`

set INS = "install"
set SYS = "sys"

# XXX
# XXX hetero server installations may be screwed.  Fix this.
# XXX
set USR_PATH    = "/export/exec/$ARCH"
set SYS_PATH    = "/export/exec/kvm/$ARCHK/$SYS"

set ULIB = "$USR_PATH/lib"
set DIAG_PATH   = "$USR_PATH/diag/sundiag"

set PRODUCT_PATH = "$USR_PATH/sunlink/tr"
set PRODSYS_PATH = "$PRODUCT_PATH/$SYS"
set PRODDIAG_PATH = "$PRODUCT_PATH/diag"

set TRHDR = "sunif/if_trreg.h sunif/if_trvar.h netinet/if_trreg.h sunif/tr_conf.c"
set TRUSRINC = "sunif/if_trreg.h sunif/if_trvar.h netinet/if_token.h"
set TROBJ = "if_tr.o if_tr_subr.o"
#
cd /
#			Verify that owner is root
set me = `whoami`
if ($me != "root") then
	echo "This script must be run as root ... fatal error"
	exit (-1)
endif
#
if (!(-w $ULIB)) then
	echo "No root write access to $ULIB ... fatal error"
	echo "This script cannot be run on a client"
	exit (-1)
endif
#
cd $PRODSYS_PATH
cp saved.files $SYS_PATH/$ARCHK/conf/files >& /dev/null

################################################################################
# NOTE: main idea here is to avoid screwing up /sys files, not to be
# a complete undo of the tr_install.
################################################################################
cd $USR_PATH/include
echo removing include files ...
ls -l $TRUSRINC
rm -f $TRUSRINC >& /dev/null
if (-e if.h.tr) then
	mv -f net/if.h.tr net/if.h
endif
echo ""

#OBSOLETE echo removing sundiag files ...
#OBSOLETE cd $DIAG_PATH
#OBSOLETE if ( `ls -i .usertest | awk '{ print $1 }'` == \
#OBSOLETE      `ls -i tr.usertest | awk '{ print $1 }'` ) then
#OBSOLETE 	ls -l .usertest
#OBSOLETE 	rm -f .usertest >& /dev/null
#OBSOLETE endif
#OBSOLETE ls -l tr.usertest # too dangerous to remove nettest
#OBSOLETE rm -f tr.usertest >& /dev/null # too dangerous to remove nettest
#OBSOLETE echo ""


cd $SYS_PATH
echo removing sys files ...
ls -l $TRHDR
rm -f $TRHDR >& /dev/null
if (-e if.h.tr) then
	mv net/if.h.tr net/if.h
endif
echo ""

cd $SYS_PATH/$ARCHK/OBJ
echo removing object files ...
ls -l $TROBJ
rm -f $TROBJ >& /dev/null
if (-e if.o.tr) then
	mv -f if.o.tr if.o
	mv -f swapgeneric.o.tr swapgeneric.o
endif
echo ""
echo "tr_deinstall complete."
