#!/bin/sh
#ident	"$Header: Uutry 1.5 90/04/25 $@(#)uucp:Uutry	2.6.1.1"

# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
# Sequent Computer Systems, Inc.   All rights reserved.
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.

#	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=/usr/spool/uucp/.Status

if [ -x "./uucico" ]; then
	UUCICO=./uucico
else
	UUCICO=/usr/lib/uucp/uucico
fi

REMOVE=""
X="-x5"
SYS=
while [ $# -gt 0 ]
do
	case $1 in
	-x)  shift; X="-x$1"; shift;;
	-x*) X=$1; shift;;
	-r) REMOVE="y"; shift;;
	-?) echo "$0: unrecognized flag $1\nUSAGE: $0 [-r] [-xdebug_level] system";exit 1;;
	*) SYS="$1"; shift;;
	esac
done

if [ -z "$SYS" ]
then
	echo "$0:  system name required"
	exit 1
fi

#  check for existence in Systems file
#  only accept match of full name
#  (important because some names may be prefixes of others!)
XX=
XX=`uuname | grep "^${SYS}$" `
if [ -z "$XX" ]
then
	echo "Invalid system name \"$SYS\""
	exit
fi

STMP=/tmp/$SYS
rm -f $STMP
> $STMP
chmod 622 $STMP
#  remove old status file (can't actually remove, since $STATUS isn't
#  publicly writable, but zero-ing it out works fine)
if [ -n "$REMOVE" ]; then
    cp /dev/null $STATUS/${SYS} 2>/dev/null
fi

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

echo "tmp=$STMP"
#	on heavily loaded systems, may take a moment for uucico
#	to create debug file.
if [ ! -f $STMP ]
then
	sleep 5
fi
tail -f $STMP
