#!/bin/sh
#
#  Copyright 1993 by TransSys, Inc.
#  All rights reserved.
#
#  '$Header: /local/SRCS/slip2/util/pnilogin,v 1.1 1993/08/10 03:44:49 louie Exp $'
#
#  This shell script is intended to be listed as the login shell for
#  logins used to handle an "incoming" network connection.  We distinguish
#  between different login sessions by looking at the USER environment
#  variable.
#

# emit an error message and die.

err() {
    echo; echo "ERROR: $1"
    #  wait a bit for the message to get out..
    sleep 2; stty 0; sleep 2
    #  that's all
    exit 0
}

: set -x

PATH=/usr/ucb:/usr/bin:/bin:/etc/pni/support ;	export PATH
LOGSHELL="$SHELL" ;				export LOGSHELL
SHELL=/bin/sh ;					export SHELL
unset TERM

#
#  All this is to accomodate the broken rlogind program that doesn't
#  pass an open and valid /dev/tty to its shell.  Sigh.
#
if ( exec 5>/dev/tty ) >/dev/null 2>&1 ; then
   echo "/dev/tty is OK"
   exec 5>&-
else
   echo "/dev/tty is broken"
   if T=`tty`; then
	export T
   else
	err "Shell has no tty!"
   fi

   exec 5<$T
   if [ ! -t 5 ]; then
	err "Login shell has no valid tty"
   fi
   exec 5>&-

   if ( exec 5>/dev/tty ) >/dev/null 2>&1 ; then
	exec 5>&-
   else
	err "Process has no /dev/tty"
   fi
fi


# try to ensure that the tty isn't in too weird a shape

stty -tostop -crterase -crtkill -ctlecho -nohang tabs

# make sure we're not disturbed

biff n ; mesg n

if [ ! -d /etc/pni ]; then
    err "/etc/pni directory does not exist."
fi

cd /etc/pni

for s in cfg-in config-inbound cfg-inbound; do

   f="config/${USER}.$s"

   if [ -f $f ]; then
	echo; echo "OK: starting PNI"
	exec /etc/pni/pnid -s -n ${USER} -f $f -C
   fi

done

err "Inbound connection is not configured for $USER"


