#! /bin/sh
#
#** Copyright (c) 1991 Sun Microsystems, Inc.  All Rights Reserved.
#** Sun considers its source code as an unpublished, proprietary trade 
#** secret, and it is available only under strict license provisions.  
#** This copyright notice is placed here only to protect Sun in the event
#** the source is deemed a published work.  Disassembly, decompilation, 
#** or other means of reducing the object code to human readable form is 
#** prohibited by the license agreement under which this code is provided
#** to the user or company in possession of this copy.
#** 
#** RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the 
#** Government is subject to restrictions as set forth in subparagraph 
#** (c)(1)(ii) of the Rights in Technical Data and Computer Software 
#** clause at DFARS 52.227-7013 and in similar clauses in the FAR and 
#** NASA FAR Supplement.

#
# This is the installation script for ToolTalk and Link Manager.  This
# script is normally run by the openwindows master install script.
#
# This script installs the ToolTalk dbserver in inetd.conf,
# and HUP's the inetd.
#

PATH="/sbin:/bin"
export PATH

case `uname -r` in
	4.*)	tsys=4X;;
	*) 	tsys=SVR4;;
esac	

case $tsys in
	4X)	whoami=`/usr/ucb/whoami`
		psflags='-ax'
		PATH="/bin:/usr/bin:/usr/ucb"
		export PATH
		;;

	SVR4)	whoami=`id | sed -e 's/[^(]*(//' -e 's/).*//'`
		psflags='-e'
		PATH="/sbin:/usr/sbin:/usr/bin"
		export PATH
		;;
esac	

if [ "$whoami" != "root" ]
then
	echo "install_tt: Must be run in super-user mode."
	exit 1
fi

if [ "$OPENWINHOME" = "" ]
then
	echo 'Installation failed because $OPENWINHOME is undefined.'
	echo 'Please set $OPENWINHOME and rerun this script.'
	exit 1
fi

echo
echo "Saving your old /etc/inetd.conf into /etc/inetd.conf.$$"
cp /etc/inetd.conf /etc/inetd.conf.$$

echo_n() {
	case $tsys in
		4X)	echo -n $*
			;;
		SVR4)	echo $*'\c'
			;;
	esac
}

echo_n "Adding ToolTalk database server to /etc/inetd.conf ... "
chmod u+w /etc/inetd.conf
ex - /etc/inetd.conf <<TT_EOF >/dev/null
g/^# Sun ToolTalk/d
g/rpc\.ttdbserverd/d
$
a
# Sun ToolTalk Database Server
100083/1	stream  rpc/tcp wait root $OPENWINHOME/bin/rpc.ttdbserverd rpc.ttdbserverd
.
w
q
TT_EOF
if [ "$tsys" = "SVR4" ]
then
	chmod u-w /etc/inetd.conf
fi
echo "done."

#
# Tell inetd it's got new customers
#
echo
echo_n "Asking inetd to re-read its config file... "
INETD=`ps $psflags | egrep inetd | egrep -v egrep | head -1 | awk '{print $1}'`
kill -HUP $INETD
echo "done."
