#!/bin/csh -f

set alexsrc=/alex/edu/cmu/cs/nectar/burgundy/src/alexsrvr
set alexdst=~alexsrvr

set alexold=${alexdst}/old.`/bin/date | awk '{print $2_$3_$4}'`
set dirs={doc,src,usr.lib,usr.man,usr.src}
set stampfile=~alexsrvr/.lastUpdate

if (! -d /alex/edu) then
  echo "Sorry, but ALEX has not been mounted on /alex - terminating"
  exit
endif

if (-f ${stampfile}) then
  mv -f ${stampfile} ${stampfile}.cur
  set newer="-newer ${stampfile}.cur"
else
  set newer=
endif

touch ${stampfile}

echo "Saving current tree to ${alexold}"
cd ${alexdst}
mkdir ${alexold}
tar cf - ${dirs} | (cd ${alexold}; tar xfBp -)

echo "Updating directory information"
cd ${alexsrc}
foreach dir (`find ${dirs} -type d -print`)
  cat ${dir}/.alex.update >& /dev/null
end

echo "Updating current tree"
find ${dirs} ${newer} -type f ! -name ".alex*" -print | cpio -pdlm ${alexdst}

foreach file (src/Makefile src/config.h)
  if ( ! { cmp -s ${file} ${alexold}/${file} } ) then
    echo "The ${file} file has been changed! "
  endif
end

rm -f ${stampfile}.cur
