gitweb/gitweb_config.perl: allow replace refs in gitweb
[girocco.git] / make-apache-conf.sh
blobd606fb97c28abe6018f3876bdfb17664c23aa7df
1 #!/bin/sh
3 # This script uses the current values of Girocco::Config to
4 # convert apache.conf.in into apache.conf.
6 # It is run automatically by "make" or "make apache.conf" but
7 # may be run separately if desired.
9 set -e
11 . ./shlib.sh
13 trap "rm -f 'apache.conf.$$'" EXIT
14 trap 'exit 130' INT
15 trap 'exit 143' TERM
17 # Include custom configuration, if any
18 [ ! -e config.sh ] || [ ! -f config.sh ] || [ ! -r config.sh ] || . ./config.sh
20 __girocco_conf="$GIROCCO_CONF"
21 [ -n "$__girocco_conf" ] || __girocco_conf="Girocco::Config"
22 perl -I"$PWD" -M"$__girocco_conf" -- - apache.conf.in >apache.conf.$$ <<'EOT'
23 #line 21 "make-apache-conf.sh"
24 use strict;
25 use warnings;
27 my $frombegin = '# ---- BEGIN LINES TO DUPLICATE ----';
28 my $fromend = '# ---- END LINES TO DUPLICATE ----';
29 my $tobegin = '# ---- BEGIN DUPLICATE LINES ----';
30 my $toend = '# ---- END DUPLICATE LINES ----';
32 open IN, '<', $ARGV[0] or die "could not open $ARGV[0] for reading: $!\n";
33 my $input;
35 local $/;
36 $input = <IN>;
38 close IN;
39 $input =~ s/^##.*(?:\n|$)//gm;
40 my $repl = sub {
41 no warnings;
42 if (eval '$Girocco::Config::'.$_[1]) {
43 $_[0] ? "Girocco_Config_$_[1]_Disabled" : "!Girocco_Config_$_[1]_Disabled";
44 } else {
45 $_[0] ? "!Girocco_Config_$_[1]_Enabled" : "Girocco_Config_$_[1]_Enabled";
48 $input =~ s/^(\s*<IfDefine\s+)(!?)\@\@([a-zA-Z][a-zA-Z0-9_]*)\@\@>/
49 $1 . &$repl($2, $3) . '>'/gmexi;
51 no warnings;
52 $input =~ s/\@\@([a-zA-Z][a-zA-Z0-9_]*)\@\@/eval
53 "\$Girocco::Config::$1 ne ''?\$Girocco::Config::$1:'\@\@'.\"$1\".'\@\@'"/gsex;
55 if ($input =~ /(?:^|\n)$frombegin[^\n]*\n(.*)(?<=\n)$fromend/s) {
56 my $dupelines = $1;
57 if ($input =~ /^((?:.+\n)?$tobegin[^\n]*\n).*((?<=\n)$toend.*)$/s) {
58 $input = $1 . $dupelines . $2;
61 printf "%s", $input;
62 EOT
63 mv -f apache.conf.$$ apache.conf