#!/bin/sh

# update-ad1810-autoindex - generate index.html files through a directory tree
#    by invoking ad1810-autoindex at the right spots
#
# No copyright is claimed.  This code is in the public domain; do with it
# what you wish. Author: 2008 Joost van Baal

find . -path './*.git' -prune -o -type d -print  | while read dir
do
    cd $dir
    while read file flag
    do
        if test -f $file && ! grep -q "REMOVE THIS COMMENT TO PREVENT UPDATES OF THIS FILE BY update-ad1810-autoindex" $file
        then
            # index file is not generated by us, leave it alonne
            echo >&2 skipping update of $file in $dir
        else
# ad1810-autoindex > index.html
# ad1810-autoindex -S > index-size.html
# ad1810-autoindex -t > index-time.html

            ad1810-autoindex $flag > $file
            echo >&2 updated or created $file in $dir
         fi
    done <<EOT
index.html
index-size.html -S
index-time.html -t
EOT
    # echo -n "entering " >&2
    cd - >/dev/null
done
