[BALUG-Talk] script du jour (.unroll) - "unroll" Apache Include / IncludeOptional

Michael Paoli Michael.Paoli@cal.berkeley.edu
Mon Jul 10 22:52:02 PDT 2017


So ... for an Apache configuration ... with lots of
Name-based Virtual Hosts ... it's generally quite convenient
to have that complex configuration split into many files,
with lots of use of Include and IncludeOptional.  That
also allows what would otherwise be many repeated common
sections, to simply be brought in via Include or IncludeOptional,
so they can simply be updated in some common place(s), rather than
all the redundant sections scattered throughout some huge
monolithic configuration file.

But *sometimes* order does or may matter - and that can be a bit
trickier to then see/determine exactly what comes first,
and also exactly what optional bits are and aren't included.
Sometimes it's nice to "pretend", or have the perspective *as if*
it were one big monolithic configuration file - even though one
really does *not* want to actually have or manage it like that.

Well, for the quick-and-dirty, what would it look like if ...
if we "unrolled" all those Include and IncludeOptional configuration
bits, as if it then looked like one (huge) configuration file?

Well, enter the script du jour (at the moment, using it for some
troubleshooting - where order does matter):

$ expand -t 4 < .unroll
#!/bin/sh

set -e
while read -r line
do
     set -- $line
     case "$1" in
         Include)
             shift
             cat "$@" | "$0"
         ;;
         IncludeOptional)
             shift
             2>>/dev/null cat "$@" | "$0" || :
         ;;
         *)
             echo "$line"
         ;;
     esac
done
$

Could probably be done better / more efficiently, in Perl, or
Python ... but for the quick and dirty, that does it quite
efficiently and quickly enough.

We have, on the host being examined:
$ pwd -P
/etc/apache2
$ wc -l apache2.conf
221 apache2.conf
$ ./.unroll < apache2.conf | wc -l
6068
$ find * -type d -name RCS -prune -o -type f -exec \
> egrep -h '^[         ]*Include(|Optional)[   ]' \{\} \; |
> wc -l
163
$




More information about the BALUG-Talk mailing list