#!/bin/sh
#
# Copyright (C) 1991 Texas Instruments Incorporated.
#
# Permission is granted to any individual or institution to use, copy, modify,
# and distribute this software, provided that this complete copyright and
# permission notice is maintained, intact, in all copies and supporting
# documentation.
#
# Texas Instruments Incorporated provides this software "as is" without
# express or implied warranty.
#
# Shell script to copy ice (the current directory) to specified host
# on specified path.
#
# Usage: cd ice; util/copy_ice <host> <path>
#
# Example: cd ice; util/copy_ice osage /epoch/misc/ice
#

rsh $1 rm -rf "$2/*" &
rm -f /tmp/icefiles /tmp/unice
find . -print > /tmp/icefiles

# don't copy *.o *.a *.txt *.s *.i *..c *.bak *.3T
egrep '^.*\.(o|a|txt|s|i|\.c|bak|3T)$' /tmp/icefiles > /tmp/unice

# don't copy */core */.?* *# *~
egrep '.*/core$|.*/\..+|.*#$|.*~$' /tmp/icefiles >> /tmp/unice

# don't copy RCS directories
find . -name 'RCS' -print >> /tmp/unice

# don't copy program executables, except for bin directories
find . -perm -0111 -type f -print | egrep -v 'bin' >> /tmp/unice;

#don't copy these directories
echo "./buglist" >> /tmp/unice
echo "./foils" >> /tmp/unice
echo "./papers" >> /tmp/unice
echo "./pos" >> /tmp/unice
echo "./iv" >> /tmp/unice
echo "./util" >> /tmp/unice

sort /tmp/unice > /tmp/unicesorted
mv /tmp/unicesorted /tmp/unice
rm /tmp/icefiles

# wait for "rm -rf" on other machine to finish
wait
echo "tar XhcofB /tmp/unice - . | rsh $1 cd $2 \; umask 22 \; tar xfB -"
tar XhcofB /tmp/unice - . | \
    rsh $1 cd $2 \; umask 22 \; tar xfB -
rm /tmp/unice
