#!/usr/bin/bsh
# @(#)73	1.5  src/bos/usr/bin/uucp/Nutry, cmduucp, bos411, 9428A410j 3/11/94 17:24:39
# 
# COMPONENT_NAME: CMDUUCP Nutry
# 
# FUNCTIONS: 
#
# ORIGINS: 10  27  3 
#
# (C) COPYRIGHT International Business Machines Corp. 1985, 1989
# All Rights Reserved
# Licensed Materials - Property of IBM
#
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
#
#	This shell will start a uucico for the system given.
#	Options:
#	  -xN the debugging level for uucico (-x5 default)
#	  -r  force the removal of the status file
#	The output is put in /tmp/Name where Name is the name
#	of the system name.  A tail -f is performed after uucico is started.

STATUS=/var/spool/uucp/.Status
CMD=`basename $0`
TMP=/tmp/U$$U
UUCICO=/usr/sbin/uucp/uucico
trap 'rm -f $TMP' 0 1 2 3 15

REMOVE=""
X="-x5"
SYS=
for arg
do
	case $arg in
	-x*) X=$arg;;
	-r) REMOVE="y";;
	*) SYS="$arg";;
	esac
done
if [ -z "$SYS" ]
then
     	if [ -x /usr/bin/dspmsg ];
		then dspmsg uucp.cat 1 "%s:  system name required" $CMD;
		else echo "$CMD:  system name required"
	fi
	exit 1
fi

#  use 7 character maximum name length (SYSNSIZE in uucp.h) for search
SYSTEM=`echo $SYS | cut -c1-7`

#  check for existence in L.sys
#  This is a bit complicated because one has to worry about
#  names that may be prefixes of others!
XX=
XX=`uuname | grep $SYSTEM `
if [ -z "$XX" ]
then
     	if [ -x /usr/bin/dspmsg ];
	        then dspmsg uucp.cat 2 "Invalid system name \"%s\"" $SYSTEM;
        	else echo "Invalid system name \"$SYSTEM\""
     	fi
	exit
fi
set $XX
FULLNAME=$1
for i
do
    if [ $i = $SYS ]; then
	FULLNAME=$SYS
	break
    fi
done

STMP=/tmp/$FULLNAME
rm -f $STMP
> $STMP
chmod 666 $STMP
#  remove old status file
if [ -n "$REMOVE" ]; then
    rm -f $STATUS/${FULLNAME}
fi

echo "$UUCICO -r1 -s$FULLNAME  $X >$STMP 2>&1&"
$UUCICO  -r1 -s$FULLNAME  $X >$STMP 2>&1&

echo "tmp=$STMP"
tail -f $STMP
