#!/bin/sh
# $Id: gen-include-file-list,v 1.4 2012/02/10 15:04:54 ineiev Exp $
# Copyright 2011 Free Software Foundation, Inc.
# 
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.
#
# This is run from gnun@fencepost cron.
# 
# The idea is to generate a list of the SSI fragments included in other
# pages.  We don't want Apache to localize those with MultiViews, since
# the translations (e.g., provide.de.html) already include the
# appropriate localized version (e.g., /server/header.de.html).
#
# Output from this script is to stdout for easy testing.  The checked-in
# list of files used from the web configuration is in
# [www]/server/include-file-list.txt.
# 
# Originally written by Ineiev.

# Root of hierarchy to search, the main web directory by default.
webroot=${1-`cd ../.. && pwd`}

# Use consistent sorting.
LC_ALL=C

# Output header
echo -n '#' Generated by gen-include-file-list on' '
date
echo '#' Do not edit.

# Look for ssi statements in .html and .shtml, nothing else.
find $webroot -type f \( -name \*.html -o -name \*.shtml \) ! -path \*/po/\* \
| while read i; do

    # In each file, look for SSI virtual includes like this:
    # <!--#include virtual="/server/header.html" -->
    # and extract just the path (/server/header), no .html.
    #
    # Then filter out the localized versions of those include files,
    # such as header.de.html and header.pt-br.html.

    sed -n 's/^.*#include virtual="\([^"]*\)\.html".*$/\1/p' $i \
    | grep -v "\...\(-..\)\?$"
   done \
| sort -u \
| sed "s/\(.*\)/\1 \1.en/"

# The last line ends by doubling the text and adding .en, so
#   /server/header
# becomes
#   /server/header /server/header.en
# The RewriteRule sequence in the vhost then sees the .en and doesn't
# try to localize /server/header.

# By the way, we don't look for #include file=... because there are no
# existing useful instances of that, and it shouldn't be used in the
# future, either.   Time will tell.
