#!/bin/sh
#
# This script users synctree to copy the sipb cell copy of the sipb locker
# to the athena cell copy
#
# based on the original script by Derek Atkins <warlord@mit.edu>
# 
# rewritten in sh to save us all by Garry Zacheiss <zacheiss@mit.edu>
#
# $Id$
#
# $Log$
#

# define some variables it might be neat to have
KRB5CCNAME=/tmp/krb5cc_sync
KRBTKFILE=/tmp/tkt_sync

fromcell=sipb.mit.edu
fromdir=project/sipb
frompath=/afs/.${fromcell}/${fromdir}
fromvol=`echo $fromdir | sed -e 's/\//\./'`

tocell=athena.mit.edu
todir=contrib/sipb
topath=/afs/.${tocell}/${todir}

errs=/tmp/syncerr.$$
header=/tmp/syncheader.$$

host=`/bin/hostname`
mailto=sipb-afsreq,bug-sipb
mailrepl=sipb-afsreq@mit.edu

synctree=/usr/athena/etc/synctree

vos=/usr/afs/bin/vos

# get tickets and authenticate to both cells
/usr/athena/bin/kinit -k
/bin/athena/aklog $tocell $fromcell

# do the actual work
$synctree -q -s $frompath -d $topath -a $frompath/.rconf 2>&1 | \
    egrep -v 'Parsing|Fixing|chown.*failed|chown|chmod' >>$errs

# send mail if we've had any errors we care about
if [ -s $errs]; then
    cat > $header <<EOF
From: root@${host}
To: $mailto
Reply-To: $mailrepl
Subject: $fromcell to $tocell synctree errors

EOF

    (cat $header; cat $errs) | /usr/lib/sendmail -t -f${mailrepl}
else 
    rm -f $errs
fi

# release the sipb cell volume 
$vos release $fromvol -cell $fromcell -localauth

#clean up
unlog $fromcell $tocell
kdestroy
 
exit 0

