#!/bin/bash

pushd `dirname $0`
ROOT=`pwd`
if [ "`uname -s`" == "FreeBSD" ]; then
  PATCH=gpatch
else
  PATCH=patch
fi

# Setup symlinks for includes
for inc in include include_cz include_czop include_hu include_la; do
  rm -r -f $ROOT/assets/$inc
  mkdir -p $ROOT/assets/$inc
  for i in $ROOT/../$inc/*; do
    ln -s "../../../$inc/`basename $i`" $ROOT/assets/$inc/"`basename "$i" | sed 's/^_/x/'`"
  done
  rm -f $ROOT/assets/$inc/index.htm
done

rm -f $ROOT/assets/breviar-web.cfg $ROOT/assets/breviar-android.cfg
ln -s $ROOT/../cgi-bin/breviar-android.cfg $ROOT/assets/breviar-web.cfg
ln -s $ROOT/../cgi-bin/breviar-android.cfg $ROOT/assets/breviar-android.cfg

rm -f $ROOT/assets/katechezy.htm
cp $ROOT/../katechezy.htm $ROOT/assets/katechezy.htm

./setup-templates

pushd $ROOT/assets
$PATCH -p0 --merge <../assets.diff

# Setup alternative background colors
# For now, we use fixed override css.
#CSS="breviar-background-override.css"
#rm -f $CSS
#cat <breviar.css >$CSS
#$PATCH -p0 --merge <../breviar-background-override.diff

popd
popd
