#!/bin/sh

root=/tmp/xhtml
PATH="${PATH}:/usr/pkg/bin"

cp -a /var/xhtml $root
for file in `find $root -name "*.xhtml"`
do
  sed "s/\"\//\"\/~stone\//g" $file > /tmp/tmp.xhtml
  mv -f /tmp/tmp.xhtml $file

  # The web server on tilde.club does not look for index.xhtml. Fix this.
  if test `basename $file` = index.xhtml
  then
    ln $file `echo $file | sed "s/\.xhtml$/\.html/"`
  fi
done
rsync -a -H --delete -e ssh $root/ stone@tilde.club:/home/stone/public_html/

if test $? -ne 0
  then
    logger Failed to sync website with remote server
    exit 1
fi
logger Successfully synced website with remote server
rm -fr $root
