#!/bin/sh -e
#
# @(#)@(#)sys_install.sh	1.22 9/29/93 Copyright SMI 1991
#
# Install the system files for SunLink Token Ring
#

PRODUCT="TRIS"
product="tris"
PRODUCT_NAME="TRI/S"

INS="install"
ulib="/usr/lib"
SYS="sys"
UTC="usr.etc"
SYS_PATH="/usr/share/$SYS"
SYS_INS="sys_$INS"
SYSN="System Config File"
#PRODUCT_PATH="/usr/sunlink/$product"
PRODUCT_PATH="/usr/sunlink/tr"
PRODSYS_PATH="$PRODUCT_PATH/$SYS"
PRODINS_PATH="$PRODUCT_PATH/$INS"

ARCHK=`arch -k`

# Operating System
SOS_LEVEL=`strings /vmunix \
	| egrep '^Sun UNIX|^SunOS (Release)' \
	| sed -e 's/.*Release \([^ ][^ ]*\) .*/\1/'`

# copy sys files including kernel objects to appropriate sys directories
# Patch for diskless boot overwrites if.h so it is saved to if.h.tr
# Same goes for if.o and swapgeneric.o
# This patch is not needed for 4.1.1. (ie only for 4.1)
# May want a check later on to *ONLY ADD* these files if 4.1
#
if test ! -d /sys
then
	echo "can't install Token Ring without a /sys directory"
	exit 1
fi

cd $PRODSYS_PATH
# Fixup for non-sun4c architectures
if [ ! -d $ARCHK ]
then
 	mkdir $ARCHK
	cd sun4c
	find . -print | cpio -pvduma $ARCHK
fi


cd $PRODSYS_PATH
SYS_FILES="sunif netinet $ARCHK"
echo "copying sys files ..."
tar cf - $SYS_FILES | ( cd /sys; tar xvfp - )
echo ""
if [ $SOS_LEVEL = "4.1" ] 
then
	if test -s /usr/include/net/if.h
	then
		mv /usr/include/net/if.h /usr/include/net/if.h.tr
		mv /sys/net/if.h /sys/net/if.h.tr
		mv /sys/sun4c/OBJ/if.o /sys/sun4c/OBJ/if.o.tr
		mv /sys/sun4c/OBJ/swapgeneric.o /sys/sun4c/OBJ/swapgeneric.o.tr
	fi
	cd $PRODUCT_PATH
	cp ./patch/net/if.h /sys/net/if.h
	cp ./patch/net/if.h /usr/include/net/if.h
	cp ./patch/sun4c/OBJ/if.o /sys/sun4c/OBJ/if.o
	cp ./patch//sun4c/OBJ/swapgeneric.o /sys/sun4c/OBJ/swapgeneric.o
fi

# update "files" for building Token Ring kernels
#
cd $SYS_PATH/`arch -k`/conf
cp files $PRODINS_PATH/saved.files
cp files saved.files
rm -f files
sort saved.files $PRODUCT.files.add | awk '{ if (($1 != prev1) || ($3 != prev3)) \
{ print $0; prev1 = $1; prev3 = $3; } } ' > files

# copy usr.etc files
cd $PRODUCT_PATH/usr.etc
echo "copying usr.etc files ..."
tar cf - * | (cd /usr/etc; tar xvfp - )
echo ""

exit 0
