#!/bin/sh
#
#	@(#)deinstall_snc	1.3 93/03/23 Copyright (C) 1992  Sun Microsystems, Inc
#
#########################################################################
# Uninstall Sun Network CoProcessor software
# Execute this from /var/tmp/unbundled/SNC or from /cdrom/Snc/_install
#########################################################################

MYNAME=$0
OWD=`pwd`
DEINSTALL_DIR=/var/tmp/unbundled/SNC
PROD="Sun Network CoProcessor"
ANS=""
ARCH=`arch -k`
OVER_SRC=snc.overwritten
OVER=/tmp/${OVER_SRC}
NEW_SRC=snc.newfiles
NEW=/tmp/${NEW_SRC}

sed -e "s/\${ARCH}/$ARCH/" < $OVER_SRC > $OVER
sed -e "s/\${ARCH}/$ARCH/" < $NEW_SRC > $NEW

for i in $OVER $NEW
do
	if [ ! -f $i ]
	then
		echo "File \"$i\" is not found in the current directory."
		echo
		echo "Please cd to $DEINSTALL_DIR or"
		echo "mount the $PROD CD and cd to Snc/_install,"
		echo "then re-execute this script."
		echo
		echo $PROD software not removed
		exit 1
	fi
done
while [ \( "$ANS" = "" \) ]
do
	echo "De-installing $PROD software"
	echo -n "Would you like to see a list of files to be restored/removed? [y|n]? "
	read ANS
	case $ANS in
		y*) echo ""
		    echo "$PROD files to be restored"
		    echo ""
		    more $OVER
		    echo ""
		    echo "$PROD files to be removed"
		    echo ""
		    more $NEW
		    continue;;
		n*) continue;;
		*)  echo
		    echo "Enter \"y\" or \"n\""
		    ANS="";;
	esac
done

ANS=""
while [ \( "$ANS" = "" \) ]
do
	echo ""
	echo -n "Do you want to continue [y|n]? "
	read ANS
	case $ANS in
		y*) echo ""
		    echo "De-installing $PROD software"
		    echo ""
		    continue;;
		n*) echo
		    echo $PROD software not removed
		    exit 4;;
		*)  echo
		    echo "Enter \"y\" or \"n\""
		    ANS="";;
	esac
done

cd /
for FILE in `cat $OVER`
do
	echo restoring $FILE
	if [ -f $FILE.presnc ]
	then
		mv $FILE.presnc $FILE
	else
		echo "	$FILE.presnc doesn't exist"
		echo "	couldn't restore $FILE"
	fi
done

for FILE in `cat $NEW`
do
	echo removing $FILE
	rm -f $FILE
done

rm -rf $DEINSTALL_DIR/deinstall_snc $DEINSTALL_DIR/snc.newfiles $DEINSTALL_DIR/snc.overwritten $OVER $NEW
rm -rf $DEINSTALL_DIR
echo ""
echo "De-installation of $PROD complete."
exit 0
