#!/bin/bash

ROOT=`dirname $0`

# Setup symlinks for includes
for inc in include include_cz include_czop include_hu; do
  mkdir -p $ROOT/assets/$inc
  pushd $ROOT/assets/$inc
  rm -f *
  wget -r -l 1 http://www.breviar.sk/$inc
  for i in www.breviar.sk/$inc/*; do
    mv "www.breviar.sk/$inc/`basename $i`" "`basename "$i" | sed 's/^_/x/'`"
  done
  rm -rf www.breviar.sk
  rm index.htm
  popd
  rm -f $ROOT/assets/$inc/index.htm
done

### Setup symlinks for docs

rm -f $ROOT/assets/katechezy.htm
wget http://www.breviar.sk/katechezy.htm -O $ROOT/assets/katechezy.htm

rm -f $ROOT/assets/breviar-web.cfg
cp $ROOT/../cgi-bin/breviar-web.cfg $ROOT/assets/breviar-web.cfg

rm -f $ROOT/assets/breviar-android.cfg
cp $ROOT/../cgi-bin/breviar-android.cfg $ROOT/assets/breviar-android.cfg

pushd $ROOT/assets
patch -p0 --merge <../assets.diff
find . -name "*.orig" | xargs rm -f
popd

