
#!/bin/sh
#	ATT:#ident	"uucp:Cvt	2.2"

#ident	"@(#)uucp:Cvt	25.1"


#	execute this as root and in the /usr/spool/uucp directory.
#	execute
#	    Cvt C*
#	This will create required directories and move the
#	C. and D. files to the proper place.
#
#	use -n option to tell what will be done, but without doing it
#
# NOTE!!
#	It does not take care of X. files yet.

set +e
SPOOL=/usr/spool/uucp
TMP=/tmp/CVT

NC=`/bin/ls $SPOOL | grep -c "^C."`
if [ $NC -eq 0 ]
then
  echo "There are no old C. files in /usr/spool/uucp\nexiting"
  exit
fi

echo "
This shell (Cvt) will attempt to take the old C. and D. files
that are in $SPOOL and put them in the proper directories for
the new version of uucp.

If the files are not moved, they will never get executed after the
new uucp is installed.

There are $NC C. files in $SPOOL.

Do you wish to continue (Type y to continue)? \
\c"

read A
if [ x$A != "xy" ]; then exit; fi

while [ $# -gt 0 ]
do
	case $1 in
	-n)	ECHO=echo
		shift
		;;

	*)	break
		;;

	esac
done

cd $SPOOL
for i in C*
do 
# S is the 6 character system name
# E is the last 5 characters of C. name

  echo Processing: $i
  S=`echo $i | sed "s/..\(.*\)....../\1/"`
  E=`echo $i | sed "s/.*\(.....\)/\1/"`
  DIR=
  DIR=`uuname | grep "^$S"` 
  if [ -z "$DIR" ]
  then
	echo "*****Warning: There is no system=$S in the /usr/lib/uucp/Systems file. ******"
	DIR=$S
  fi
  DIR=`echo $DIR | sed "s/ .*//"`
  if [ ! -d $SPOOL/$DIR ]
	then
	    $ECHO  mkdir $SPOOL/$DIR
	    $ECHO  chmod 755 $SPOOL/$DIR
	    $ECHO  chown uucp $SPOOL/$DIR
  fi

    cat $i | while read AA ; do
	D=`echo $AA | cut -d" " -f6`
	if [ -n "$D" -a -f "$D" ]
	    then $ECHO mv $D $DIR/$D
	fi
    done
    S=`echo $DIR | sed "s/\(.......\).*/\1/"`
    $ECHO mv $i $DIR/C.$S$E

done
