#sccs	"@(#)fndetc:profile	1.7"

#
#  FILE:  /etc/profile
#	Initialization script for all logins.
#

trap '' 1 2 3

set `who -r`
if [ "$3" = "S" ]
then
	sync;sync;sync
	/etc/killall

	##  Any shutdown procedures (such as slancard reset) can be
	##  put in /etc/shutdaemon, and will be executed without
	##  changing /etc/profile.

	if [ -d /etc/shutdaemon ]
	then
		for i in /etc/shutdaemon/*
		do
			if [ -x $i ] ; then $i ; fi
		done
	fi

	sync;sync;sync
	echo "\n\nReady to power off or reset the machine.\nPress RETURN to reboot."
	read inputline
	reboot
fi
SHELL=/bin/sh 
PATH=:/bin:/usr/bin:/etc
UA=/usr/lib/ua 
TZ=`cat /etc/TZ`;export TZ

#The following line (if uncommented) will set TERM and TERMCAP (see ttytype)
#eval `tset -s -Q`
#For now, just set TERM to s4
NAME=`tty`
if [ \( "`expr $NAME : '/dev/w' `"      != "0" -o \
	"`expr $NAME : '/dev/sys' `"    != "0" \) ]
then
#						A Console Window 
	TERM=s4
elif  [ "`expr $NAME : '/dev/con' `" != "0" ]
then
#						A Windowless Console
	TERM=adm3
else
#						A Remote Login
	trap "exit" 1 2 3
	SHFLAG=0
	PHRASE=" "
	ADDEDINFO=", '?' for help, or 'exit' to exit,\n"
	while true
	do
		echo "\n\
Please type the terminal name${PHRASE}and press RETURN:  \c"
		read TNAME
		PHRASE="$ADDEDINFO"
		case $TNAME in

		"?")	##  DISPLAY HELP INFO, THEN START AGAIN
			if [ -s /usr/lib/termhelp ]
			then	/usr/lib/termhelp
			else	echo "Sorry.  No help is available."
			fi
			continue ;;

		"exit")	##  EXIT FROM PROFILE, RETURNING TO LOGIN
			exit ;;

		"")	##  ERROR - NO BLANK ENTRIES
			echo "You must provide a terminal name."
			continue ;;
		esac

		##  CHECK THAT TERMINAL GIVEN IS UA-COMPATIBLE

		if [ -s $UA/uaTermList ]
		then
			if grep ":$TNAME:" $UA/uaTermList > /dev/null
			then	break
			fi
		fi

		##  IF NOT UA-COMPATIBLE, CHECK TERMCAP FOR AN ENTRY

		echo > /dev/null    ##  THIS KLUGES AROUND A SHELL BUG
		getterm $TNAME
		if [ $? != 0 ]
		then
			cat << -END-

The terminal you have chosen may not work well with your Office.
You may:

      1 - Run the default shell
      2 - Retype the terminal name
      3 - Proceed to the Office anyway
      4 - Exit now
      ? - Get help

-END-
			echo "Type a number or '?' and press RETURN:  \c"
			read CHOICE
			case $CHOICE in

			"1")	##  RUN THE DEFAULT SHELL
				SHFLAG=1
				break ;;

			"3")	##  RUN THE USER-AGENT ANYWAY
				break ;;

			"4")	##  EXIT FOR PROGRAM
				exit ;;

			"?")	##  DISPLAY HELP INFO
				if [ -s /usr/lib/termhelp ]
				then	/usr/lib/termhelp
				else	echo "Sorry.  No help available."
				fi
				continue ;;
			esac
		else
			cat << -END-

The terminal you have chosen is not supported.  You may:

      1 - Run the default shell anyway
      2 - Retype the terminal name
      3 - Exit now
      ? - Get help

-END-
			echo "Type a number or '?' and press RETURN:  \c"
			read "CHOICE"
			case $CHOICE in

			"1")	##  RUN THE DEFAULT SHELL
				SHFLAG=1
				break ;;

			"3")	##  EXIT PROFILE AND RETURN TO LOGIN
				exit ;;

			"?")	##  DISPLAY HELP INFO
				if [ -s /usr/lib/termhelp ]
				then	/usr/lib/termhelp
				else	echo "Sorry.  No help available."
				fi
				continue ;;
			esac
		fi
	done

	export SHFLAG
	TERM=$TNAME
	if [ -z "$TERM" ] ; then TERM=adm3; fi
fi
umask 022

S4=/
S4TOOLS=$S4
MAKEINC=$S4/usr/include
LIBROOT=$S4
BINROOT=$S4TOOLS
# This gets touch targets on a 510d
if [ $TERM = "510a" ] ||
   [ $TERM = "510A" ] ||
   [ $TERM = "510D" ] ||
   [ $TERM = "510d" ]
then
	TERM=510
fi

export S4TOOLS BINROOT LIBROOT MAKEINC S4 TERM SHELL PATH UA
if [ -x /etc/localprofile ]
then
	. /etc/localprofile
fi

set `df -t /`
AVSPACE=`expr ${3}00 / $8`
echo "\n           ${AVSPACE}% of the storage space is available."
cat /etc/motd
#ATATE IS THE ENVIRONMENT VARIABLE FOR dBASE III
ATATE=/usr/lib/dbase; export ATATE
trap 1 2 3
