From 8d140e47d0eb9e66adaec3ec917fd3dbe8dbb640 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 30 Mar 2016 13:07:14 -0700 Subject: [PATCH] make-apache-conf.sh: convert implementation to support enhancements While the previous implementation worked just fine, it had a fixed list of variables it could expand and was limited in its processing capabilities. Convert the guts of the replacing code to use Perl so that any Girocco::Config variable is automatically supported and thereby also clear the way for future processing enhancements. Signed-off-by: Kyle J. McKay --- make-apache-conf.sh | 79 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 29 deletions(-) rewrite make-apache-conf.sh (72%) diff --git a/make-apache-conf.sh b/make-apache-conf.sh dissimilarity index 72% index d8a3da1..3af5caf 100755 --- a/make-apache-conf.sh +++ b/make-apache-conf.sh @@ -1,29 +1,50 @@ -#!/bin/sh - -# This script uses the current values of Girocco::Config to -# convert apache.conf.in into apache.conf. -# -# It is run automatically by "make" or "make apache.conf" but -# may be run separately if desired. - -set -e - -. ./shlib.sh - -config_options='admin basedir certsdir cgiroot httpdnsname reporoot webroot' - -cmd="sed < apache.conf.in > apache.conf.1.$$ -e '/^##/d'" -for option in $config_options; do - cmd="$cmd -e \"s#@@$option@@#\$cfg_$option#g\"" -done -eval "$cmd" -sed < apache.conf.1.$$ > apache.conf.2.$$ \ - -ne '1,/^# ---- BEGIN DUPLICATE LINES ----/p' -sed < apache.conf.1.$$ \ - -ne '/^# ---- BEGIN LINES TO DUPLICATE ----/,/# ---- END LINES TO DUPLICATE ----/p' | \ -sed >> apache.conf.2.$$ \ - -e '1d' -e '$d' -sed < apache.conf.1.$$ >> apache.conf.2.$$ \ - -ne '/^# ---- END DUPLICATE LINES ----/,$p' -rm -f apache.conf.1.$$ -mv -f apache.conf.2.$$ apache.conf +#!/bin/sh + +# This script uses the current values of Girocco::Config to +# convert apache.conf.in into apache.conf. +# +# It is run automatically by "make" or "make apache.conf" but +# may be run separately if desired. + +set -e + +. ./shlib.sh + +trap "rm -f 'apache.conf.$$'" EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + +__girocco_conf="$GIROCCO_CONF" +[ -n "$__girocco_conf" ] || __girocco_conf="Girocco::Config" +perl -I. -M"$__girocco_conf" -- - apache.conf.in > apache.conf.$$ <<'EOT' +#line 21 "make-apache-conf.sh" +use strict; +use warnings; + +my $frombegin = '# ---- BEGIN LINES TO DUPLICATE ----'; +my $fromend = '# ---- END LINES TO DUPLICATE ----'; +my $tobegin = '# ---- BEGIN DUPLICATE LINES ----'; +my $toend = '# ---- END DUPLICATE LINES ----'; + +open IN, '<', $ARGV[0] or die "could not open $ARGV[0] for reading: $!\n"; +my $input; +{ + local $/; + $input = ; +} +close IN; +$input =~ s/^##.*(?:\n|$)//gm; +{ + no warnings; + $input =~ s/\@\@([a-zA-Z][a-zA-Z0-9_]*)\@\@/eval + "\$Girocco::Config::$1 ne ''?\$Girocco::Config::$1:'\@\@'.\"$1\".'\@\@'"/gsex; +} +if ($input =~ /(?:^|\n)$frombegin[^\n]*\n(.*)(?<=\n)$fromend/s) { + my $dupelines = $1; + if ($input =~ /^((?:.+\n)?$tobegin[^\n]*\n).*((?<=\n)$toend.*)$/s) { + $input = $1 . $dupelines . $2; + } +} +printf "%s", $input; +EOT +mv -f apache.conf.$$ apache.conf -- 2.11.4.GIT