#! /bin/sh
# Copyright (c) 1987-1993 Frame Technology Corp. All rights reserved.
# $Id: fmcopy,v 1.4 1992/12/18 01:59:31 adl Exp $
# 
# fmcopy
#
# Command to "cp -r" a complete directory structure including links.
# The second argument should be a directory in which to place the 
# directory in the first argument. It is made if it doesn't exist.

if [ $# != 2 -o ! -d "$1" ]; then
	echo "Usage: fmcopy <source directory> <destination directory>

This command copies the contents of the source directory into
the destination directory (creating it if needed).  This command is 
similar to 'cp -r <dir1> <dir2>' except that it will CORRECTLY 
duplicate the entire structure of the directory including preserving 
symbolic links!

Use this command to copy a Frame products installation from one 
filesystem to another. Example:

    fmcopy /usr/server1/local/frame /usr/local/frame

will make a copy of '/usr/server1/local/frame' called '/usr/local/frame'.

Caution: if a file in the source directory does not have read permission,
a new file will not be created in the destination directory.
"
	exit 0
fi

case $FMARCH in
hp*)
	create=cf
	extract=xvlf
	;;
*)
	create=cf
	extract=xvlpf
	;;
esac

echo "fmcopy
Putting the contents of the directory \"$1\" into the directory \"$2\"..."
if [ "${PWD-XXX}" = "XXX" ]; then
	pwd=`pwd`
else
	pwd=$PWD
fi
# If destination directory doesn't exist, make it.
[ -d $2 ] || {
	echo Making directory $2
	mkdir $2
}
# You don't want to tar from $1 directly since $1 might be an absolute 
# path name and you wouldn't be creating relative files.
cd $1
tar $create - . | (cd $pwd; cd $2; tar $extract -)
