#!/bin/sh
# Author:	Ola Lundqvist <opal@debian.org>
# Description:	Automates the update of a web.
#	It searches for Makefiles which have a omlcs: target and
#	executes it in the specified directory. It is always recursive
#	so do not use it on deep directories especially in nfs-mounted
#	partitions if you need good performance.

if [ -f /etc/omlcs/defaultauto ] ; then
    . /etc/omlcs/defaultauto
fi

for A in /etc/omlcs/*.auto ; do
    . /etc/omlcs/defaultauto

    for OD in $DIRECTORIES ; do
	find $OD -name Makefile | {
	    while read MAKEF ; do
		if grep "^$TARGET:" $MAKEF > /dev/null 2>&1 ; then
		    DIR=$(echo "$MAKEF" | sed -e "s|/Makefile||;")
		    if [ -e $LASTLOG ] ; then
			rm -f $LASTLOG
		    fi
		    cd $DIR
		    if [ "$VERBOSITY" = "nothing" ] ; then
			make $TARGET > $LASTLOG 2>&1
		    elif [ "$VERBOSITY" = "quiet" ] ; then
			if ! make $TARGET > $LASTLOG 2>&1 ; then
			    cat $LASTLOG
			fi
		    elif [ "$VERBOSITY" = "normal" ] ; then
			make $TARGET > $LASTLOG
		    else
			echo "MAKEDIR=$DIR" > $LASTLOG
			make $TARGET > $LASTLOG
		    fi
		    
		    if [ -f $LASTLOG -a "$LOGING" != "no" ] ; then
			cat $LASTLOG >> $LOGFILE
		    fi
		    cd /
		fi
	    done
	}
    done
done
