#!/bin/sh
#A very simple script that recursively generates all.conf files
# (c) Vincent Deffontaines, KDX 2003
# This script is released under the GPL v2 licence.

WORK_DIR=/etc/apache2/

[ $1 ] && WORK_DIR=$1
echo "Working on $WORK_DIR"

cd $WORK_DIR
DIRS=`find security/rules -type d`

#First delete all.conf files all around in the security config tree
for EACHDIR in $DIRS; do
   FILE=$EACHDIR/all.conf
   if [ -f $FILE ]; then
      rm $FILE
   fi
done

#Generate all files, based on any file and dir in the security config tree.
for EACHDIR in $DIRS; do
   FILE=$EACHDIR/all.conf
   echo "Building $FILE..."
   for EACHFILE in `ls $EACHDIR`; do
      echo "Found $EACHDIR/$EACHFILE"
      if [ -d $EACHDIR/$EACHFILE ]; then
         echo "Include $EACHDIR/$EACHFILE/all.conf">>$FILE
      else
         echo "Include $EACHDIR/$EACHFILE">>$FILE
      fi
   done
done
