#!/bin/csh -f 
# 
# $Header: copylocker,v 1.1 89/03/11 19:54:35 qjb Exp $
# $Source: /mit/qjb/scripts/RCS/copylocker,v $
# $Author: qjb $
#
# This script copies a hierarchy from place to another using tar.
#
# Usage: copy_locker <oldpath> <newpath>
#

unset print_exit_status

if ($#argv != 2) then
   echo "Usage: copy_locker <oldpath> <newpath>"
   echo "Example: copy_locker cyrus:/u1/lockers/newuser priam:/mit/newuser"
   exit 1
endif

set oldpath = $1
set newpath = $2
set srcdir = /lc/old.$$
set destdir = /lc/new.$$

attach -q -m $srcdir -e $oldpath
if (($status) || (! -e $srcdir)) then
   detach -q /lc/*
   exit 1
endif

attach -q -m $destdir -e $newpath
if (($status) || (! -e $destdir)) then
   detach -q /lc/*
   exit 1
endif

alias hcp '(cd \!:1;tar cf - .) | (cd \!:2;tar xvpf -)'

hcp $srcdir $destdir

rm -rf /tmp/copylocker.err

set noglob
set files = `cd $srcdir; find . -xdev -type f -print | sed 's;^./;;'`
foreach file ($files)
   if ($file == .) continue
   echo -n "${file}: "
   cmp $srcdir/$file $destdir/$file
   if ($status == 0) then
      echo copied succesfully
   else
      echo not copied succesfully
      echo $file >>! /tmp/copylocker.err
   endif
end

if (-e /tmp/copylocker.err) then
   echo "The following files didn't copy successfully.  Use cp to"
   echo "copy them by hand."
   cat /tmp/copylocker.err
else
   echo "All files were copied succesfully."
endif  

echo -n  > /dev/tty

detach -q $srcdir $destdir

exit 0
