#!/bin/ksh
#
# GenericCopy -- generically copy lsof 4.x sources to a specified destination
#
# Usage: GenericCopy <destination> <login> <dialect> [<directory>]
#
#	 <destination>	destination host
#
#	 <login>	login name at destination host
#
#	 <dialect>	dialect subdirectory name
#
#	 [<directory>]	directory if other than src/lsof4

if test $# -lt 1 -o $? -gt 4
then
  echo "Usage: <destination> <login> <dialect> [<directory>]"
  exit
fi
D=$1
L=$2
DSDIR=$3
if test $# -eq 4
then
  DDIR=$4
else
  DDIR=src/lsof4
fi

# Set useful definitions.

SDIR=src/lsof4
F="00DIALECTS AFSConfig Configure Customize Inventory arg.c lsof_fields.h lsof.h main.c misc.c node.c print.c proc.c proto.h regex.h store.c usage.c util.c version"

cd $HOME/$SDIR

# Make sure the destination directories exist.

rsh $D -l $L -n mkdir $DDIR $DDIR/dialects $DDIR/lib $DDIR/dialects/$DSDIR

# Copy new base directory files to destination.

rsh $D -l $L -n "(cd $DDIR; rm -f $F)"
for i in $F
do
  rcp $i ${L}@${D}:${DDIR}
  echo "$i \c"
done
echo ""

# Remove old files in lib/ and dialects/<dialect>/.

rsh $D -l $L -n "rm -rf $DDIR/lib/* $DDIR/dialects/$DSDIR/*"

# Copy lib/*.

cd lib
echo "lib: \c"
for i in *.c Makefile.skel
do
  if test ! -d $i
  then
    rcp $i ${L}@${D}:${DDIR}/lib
    echo "$i \c"
  fi
done
echo ""

# Copy dialects/<dialect>/*.

cd ../dialects/$DSDIR
echo "dialects/$DSDIR: \c"
for i in *
do
  if test -d $i
  then
    if test $i != OLD -a $i != NEW -a $i != RCS
    then
      rcp -r $i ${L}@${D}:${DDIR}/dialects/$DSDIR
      echo "$i \c"
    fi
  else
    rcp $i ${L}@${D}:${DDIR}/dialects/$DSDIR
    echo "$i \c"
  fi
done
echo ""
echo "done"
