make-apache-conf.sh: enhance and tidy up
commit58c3b6b9c5e2335abc80c33f9dd9ccb95a90a9f9
authorKyle J. McKay <mackyle@gmail.com>
Fri, 29 Jan 2021 12:34:10 +0000 (29 05:34 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Fri, 29 Jan 2021 12:34:10 +0000 (29 05:34 -0700)
tree3a4227fe4ff6f3840f573b5a3dfd1e939d1c7784
parentbf8567afc1b5449a1158a10bc60020309e662dd6
make-apache-conf.sh: enhance and tidy up

Improve the apache.conf.in processor in myriad tiny ways.

* Correct the line number in the #line directive to match the script
* Make the IfDefine substitutions understand 0 and non-0 literal numbers
* Make @@var_online_cpus@@ available for substitution
* Simplify the @@<varname>@@ replacement pattern
* Introduce a new @@if(<test>)@@...@@endif@@ conditional substitution

Up until now, conditional parts of the configuration have been handled
by [ab]using the Apache <IfDefine ...> mechanism and inserting a variable
name that's somewhat descriptive yet unlikely to actually exist in the
environment.

While this works just fine, it's a bit of a kludge and can be a bit
perplexing to immediately understand the semantics when looking at the
processed output.  However, it does have the advantage of being usable
to any nesting depth since Apache itself handles the nested parsing.

With the new @@if(<test>)@@...@@endif@@ substitution, if the test
fails (the test may optionally start with a '!' to negate it and then
it's either a Girocco::Config variable name or a 0 or non-0 literal number),
the contained lines are simply commented out in the processed output.
In either case, the test itself always passes through to the output but
as commented-out lines.

The @@if(<test>)@@...@@endif@@ substitution works somewhat like the
Apache <IfDefine ...>...</IfDefine> directive in that it's only recognized
if the "@@if(<test>)@@" part appears at the beginning of the line (optionally
preceeded by white space).  The matching "@@endif@@" part must also
appear at the beginning of a line (optionally preceeded by white space) to
be recognized.  Furthermore, the only thing that may appear on the same
line following the "@@(<test>)@@" or "@@endif@@" is optional white space
and an optional '#'-introduced comment.

While the new @@if(<test>)@@...@@endif@@ substitution does not depend on any
Apache-specific processing, it's not currently possible to nest multiple
levels.

Since the new @@if(<test>)@@...@@endif@@ gets processed before the old
but still supported <IfDefine @@<var>@@> mechanism, it can be used to
disable those lines.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
make-apache-conf.sh