#!/bin/ksh -
#
# @(#)mk-afs-inetd	1.4 (hursley) 10/31/96
# /afs/hursley.ibm.com/common/src/afs/@cell/rs_aix32/usr/local/sbin/mk-afs-inetd/SCCS/s.mk-afs-inetd
#
# NAME		mk-afs-inetd
# AUTHOR	Paul Blackburn <mpb@acm.org>
# PURPOSE	Start AFS authenticating version of inetd
# USAGE		Normally invoked in /etc/rc.afs at system boot time

X=${afs_install_base}/usr/local/sbin/mk-afs-cf

if [[ ! -f ${X} ]]; then
        echo "fatal error: ${X} not found" >&2
        exit 1
fi

# source global config for AFS installation

. ${X}

start_it()
{

# If inetd.afs is already running, we will kill and restart it
# (to make sure of shell variables being unset)

inetd_afs_pid=`ps -ef|fgrep inetd.afs|grep -v grep|awk '{print $2'}`
if [ ! -z "${inetd_afs_pid}" ]; then
	doit "kill -9 ${inetd_afs_pid}"
fi

kip=4
again="true"
while [ "${again}" = "true" ]; do
	doit "sleep ${kip}; ${X} ${F}"
	inetd_afs_pid=`ps -ef| fgrep inetd.afs| grep -v grep| awk '{print $2'}`
	if [ -z "${inetd_afs_pid}" ]; then
		let kip=${kip}\*2
	else
		again="false"
	fi
	if [ ${kip} -gt 256 ]; then
		tstamp "taking too long, giving up"
		again="false"
	fi
done
}

tstamp "version 1.4 commenced on $(date '+%a %d %h %y')"

# In case we are not starting at boot time but from a root login,
# make sure certain root shell variables are not set so that user
# rsh do not inherit these variables.

unset HOME FXFOLDER FXNAME FXNUM FXTERM MAIL MAILBOX USER EXINIT ENVDONE
PS1="$ "

F=/etc/inetd.conf.afs
if [ -s	${F} ];	then
	X=/usr/etc/inetd.afs
	if [ -x	${X} ];	then
		start_it
	else
		warning "${X} not executable"
	fi
else
	warning "${F} missing"
fi

tstamp "completed"
echo
