#!/bin/csh -f
#
# This script currently will not update itself.
# This is bound to be a problem someday.
#

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}
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"
foreach file (`find ${dirs} ${newer} -type f ! -name updatealex -print`)
    echo $file
    cp $file ${alexdst}/$file
end

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

rm -f ${stampfile}.cur

echo "We have the new code.  You can run: "
echo "    make install                    "
echo "to compile/install it and then:     "
echo "    grepnkill alexd                 "
echo "To kill alexd which will then be restarted by alex.nanny"

