#!/bin/csh 
#
# $Id: update_www 19708 2010-10-29 18:04:21Z d3y133 $

# Script to automate updating of web pages for the
# user and programmers manuals.

if ($#argv != 1) then
  echo usage: update_www document 
  echo        where document.tex is the main file
  exit 1
endif

set document = $argv[1]

echo Updating WWW pages for $document.tex
#...............   public 
#foreach WWWDIR (/msrc/www/pub/docs/nwchem/doc)
foreach WWWDIR (/msrc/emslweb/docs/nwchem/doc)
#
# Now copy the revised source into the EMSL public WWW tree
  echo "update_www: Public pages .. "
  if (! -e $WWWDIR) then
    echo "update_www:    Making $WWWDIR"
    /bin/mkdir -p $WWWDIR
  endif
  if (-e $WWWDIR/$document) then  
    echo "update_www:    Saving current web documentation in:"
    echo "update_www:        $WWWDIR/$document"
    echo "update_www:    to "
    echo "update_www:        $WWWDIR/${document}.bak"
    if (-e $WWWDIR/${document}.bak) then 
       echo "update_www:    Deleting current $WWWDIR/${document}.bak"
       rm -rf $WWWDIR/${document}.bak
    endif
    mv $WWWDIR/$document $WWWDIR/${document}.bak
  endif

  echo "update_www:    Copying $document into $WWWDIR"

  /bin/cp -r $document $WWWDIR
  
  if ($status != 0) then
    echo "update_www: copy to $WWWDIR of $document failed"
    exit 1
  endif
#
# reset directory and file permissions
#
  echo "update_www: Making /msrc directories/files public"
  chmod go+rx $WWWDIR/$document
  if ($status) then
     echo "update_www: could not make $WWWDIR/$document public"
     exit 911
  endif
  find $WWWDIR/$document -type f -exec chmod go+r "{}" ";"

# Now run Pawel's magic perl script to make the frames
#doit:
#  if (! $?NWCHEM_TOP ) then
#    echo "   NWCHEM_TOP is not defined ... cannot generate frames"
#  else if (! -e $NWCHEM_TOP/doc/make_manual.pl) then
#    echo "   $NWCHEM_TOP/doc/make_manual.pl missing ... cannot generate frames"
#  else
#    echo "   Making frames"
#    pushd $WWWDIR/$document > /dev/null
#    if ($document == "user") then
#      set title = "NWChem User Manual"
#    else if ($document == "prog") then
#      set title = "NWChem Programmers Manual"
#    else
#      set title = "NWChem Manual"
#    endif
#
#    $NWCHEM_TOP/doc/make_manual.pl $document.html "$title"
#
#    if ($status != 0) then
#      echo "   Making the frames failed"
#    endif
#   
#    popd > /dev/null
#  endif

end
# Hopefully all is OK

echo "update_www:    Done with $document"

/bin/rm -rf $document
exit 0
