#sccs	"@(#)fndetc:rc	1.21"
if [ -z "$1" ]
then
	cd /etc/lddrv
	./mkifile /unix unix.syma
	cmp -s unix.sym unix.syma	2>/dev/null
	if [ $? != 0 ] 
	then
		mv unix.syma unix.sym	2>/dev/null
		rm -f wind		2>/dev/null
	fi
	sync
	> /etc/drvtab
	sync
	if [ ! "`grep wdinit unix.sym`" ]
	then
		./lddrv -av wind > /tmp/.winload 2>/tmp/.winload  || (
 			echo Window driver did not load because: > /dev/console
			cat /tmp/.winload > /dev/console
 			exec /bin/sh < /dev/console > /dev/console 2>&1 )
	fi
 	exec /bin/sh /etc/rc WINDOWED < /dev/window > /dev/w1 2>&1
fi

trap "" 2
rm -f /etc/.extra

/etc/.fontload 2> /dev/null

message -i "      Welcome to the AT&T UNIX pc.  \n\n     Stored files are being checked.\n\n           Please stand by ..." &
mpid=$!

TZ=`cat /etc/TZ`;export TZ
date -
DATE=`date '+%a %h %d, 19%y  %r' `
PATH=:/bin:/usr/bin:/etc
UA=/usr/lib/ua 
TERM=s4

export UA PATH TERM

stty sane

# PERFORM THE FILE SYSTEM CHECKS WITH AUTO-REBOOT IF SYSTEM WAS REPAIRED

/etc/fsck -pq  > /dev/null ||

#  THIS CODE IS EXECUTED IF THE FSCK FAILS

(trap "" 2 
if [ -r /etc/.installdate ] 
then

#     NOT THE FIRST BOOT ATTEMPT

message -i "\n\nSome stored files were damaged.\n\nThe damage will be repaired, and the stored files will be checked again.\n\n         Please stand by ..."  &

#   RECORD THE OUTPUT FROM THE fsck

date > /etc/.lastfsck
/etc/fsck -y >> /etc/.lastfsck

#  The above fsck will cause a reboot

else

#  IF FIRST BOOT ATTEMPT, GO INTO LOOP (allow shell access after three tries!)

trap 2
message -i "\nSerious hard disk damage detected.  Please refer to your Installation Guide and install the system from the floppy disk set provided.\n\n" 
echo " ENTERING EXPERT MODE - BE CAREFUL - FILE SYSTEM IS SUSPECT. "
/bin/sh
fi )

rm -f /usr/adm/drv.log
if [ -x /etc/.drvload ]
then
	message -i "\n           Loading drivers\n\n           Please stand by...\n" &
	kill $mpid > /dev/null 2>&1
	mpid=$!
	/etc/.drvload
fi


if [ -s /etc/.version ]
then
	setuname -v `cat /etc/.version`
fi

trap 2
cat >  /etc/.extra <<END
xxx
END

# Kill off last forked off window

kill $mpid > /dev/null 2>&1

#  IF THIS IS A BRAND NEW INSTALLATION (OUT OF THE BOX) THEN THE 
#  /etc/.installdate FILE WILL NOT EXIST.  IN THIS CASE, EXECUTE
#  /etc/.firstrc, WHICH WILL ASK FOR THE INITIALIZATION OF KEY PARAMETERS

if [ ! -r /etc/.installdate ]
then
	/etc/.firstrc
fi

TZ=`cat /etc/TZ`

# IF USER CHANGED THE TIME ZONE AND REBOOTED THE SYSTEM THEN .INSTALLDATE
# WILL BE EMPTY AT THIS POINT. WE MUST CALL .FIRSTRC ONE MORE TIME TO 
# COMPLETE THE SCRIPT

if [ ! -s /etc/.installdate ]
then
	/etc/.firstrc
fi


message -i "\n      The screen will now be set up.\n\n            Please stand by...\n" &
kill $mpid > /dev/null 2>&1
mpid=$!

# THERE ARE SEVERAL FILES WHICH START VARIOUS DAEMONS AND PERFORM 
#  ASSORTED TASKS.  IF THEY ARE PRESENT AND EXECUTABLE, RUN THEM!

# /etc/namesys executes either setuname or slaninit depending on whether
# STARLAN is installed

for i in .cleanup .cronstart .lpstartsched .syncstart namesys .phinit .modeminit wmgr smgr
do
	/etc/$i 2> /dev/null
done

# any additional daemons (such as slan initialization)
# can be put in /etc/daemons, and will be executed without
# changing /etc/rc.  Each should be run in the background.

if [ -d /etc/daemons ]
then
	DAEMONS=`ls /etc/daemons/*`
	if [ $? != 0 ] ; then DAEMONS=""; fi
	for i in $DAEMONS
	do
		if [ -x $i ]
		then	nohup $i > /dev/null 2>&1 &
		fi
	done
fi

# If a screen time out has been selected, then set it.

if [ -s /usr/lib/ua/.blanktime ]
then
	scrset `cat /usr/lib/ua/.blanktime`
fi

# Kill last window 
kill $mpid > /dev/null 2>&1
