#!/bin/bash

# set -x
out_dir=/home/jetico/v5/web_help
tmp_dir=out

mkdir -p $out_dir
mkdir -p $tmp_dir

function do_folder()
{
    if [ -d "$1" ]; then
	if [ -f "$1/.footer.inc" ]; then
	    echo Processing "$1"
	    svn up "$1"
	    rsync -aq -C --exclude=".footer.inc" $1 $tmp_dir
	    find "$1" -name "*.htm"  -exec ./actor.py $tmp_dir "$1/.footer.inc" {} \;
	    find "$1" -name "*.html" -exec ./actor.py $tmp_dir "$1/.footer.inc" {} \;
	    rsync -a -C --exclude=".footer.inc" $tmp_dir/$1 $out_dir
	fi
    fi
}

if [ x$1 = x ]; then
    # no params, publish everything
    for i in * ; do
	do_folder $i
    done

else 
    # publish folders from command line
    for i in $1 $2 $3 $4 $5 $6 $7 $8 $9 ; do
	do_folder $i
    done

fi

exit

if [ x$1 = x ]; then
    # no params, publish everything
    for i in * ; do
	if [ -d "$i" ]; then
	    if [ -f "$i/.footer.inc" ]; then
		echo Processing "$i"
		rsync -aq -C --exclude=".footer.inc" $i $tmp_dir
		find "$i" -name "*.htm"  -exec ./actor.py $tmp_dir "$i/.footer.inc" {} \;
		find "$i" -name "*.html" -exec ./actor.py $tmp_dir "$i/.footer.inc" {} \;
		rsync -a -C --exclude=".footer.inc" $tmp_dir/$i $out_dir
	    fi
	fi
    done

else 
    # publish folders from command line
    for i in $1 $2 $3 $4 $5 $6 $7 $8 $9 ; do
	if [ -d "$i" ]; then
	    if [ -f "$i/.footer.inc" ]; then
		echo Processing "$i"
		rsync -aq -C --exclude=".footer.inc" $i $tmp_dir
		find "$i" -name "*.htm"  -exec ./actor.py $tmp_dir "$i/.footer.inc" {} \;
		find "$i" -name "*.html" -exec ./actor.py $tmp_dir "$i/.footer.inc" {} \;
		rsync -a -C --exclude=".footer.inc" $tmp_dir/$i $out_dir
	    fi
	fi
    done

fi

