#!/bin/bash -x

# This script assumes svn & make & doxygen are installed and trunk has
# already been checked out into mythtv-trunk.
# This is run by the mythtvdocs user as a cron job. This user is in
# the www-docs group and this group has write permissions to the the
# $DESTINATION directory. (DESTINATION is specified below)

cd /home/mythtvdocs # make sure we're in our home directory

SLEEPTIME=120 # 2 minutes, reduce when debugging...
DESTINATION=/var/www/www.cuymedia.net

## update svn checkouts
pushd mythtv-trunk
  git pull
popd

sleep $SLEEPTIME

echo Generate mythtv-trunk docs
date
pushd mythtv-trunk/mythtv/docs
  rm -Rf doxygen-dev-docs.tar doxygen-dev-docs
  nice nice make devdocs > /dev/null
  nice tar cf doxygen-dev-docs.tar doxygen-dev-docs
  mv doxygen-dev-docs.tar $DESTINATION/doxygen-dev-docs-trunk.tar
popd
date

sleep $SLEEPTIME

echo Update website for trunk
date
pushd $DESTINATION
  nice tar xf doxygen-dev-docs-trunk.tar
  mv mythtv-trunk tmp-mythtv-trunk
  mv doxygen-dev-docs/html mythtv-trunk
  rm -Rf doxygen-dev-docs
  cp $0 $DESTINATION/
popd
date

sleep $SLEEPTIME

echo Remove leftovers
date
pushd $DESTINATION
  nice nice rm -Rf doxygen-dev-docs-trunk.tar tmp-mythtv-trunk
popd
date

