hooks/post-receive: replace printf with echo
[girocco.git] / make-apache-conf.sh
blob6c72f4d5c0a37855a58ec79680194dadde9014b0
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 __girocco_conf="$GIROCCO_CONF"
18 [ -n "$__girocco_conf" ] || __girocco_conf="Girocco::Config"
19 perl -I. -M"$__girocco_conf" -- - apache.conf.in > apache.conf.$$ <<'EOT'
20 #line 21 "make-apache-conf.sh"
21 use strict;
22 use warnings;
24 my $frombegin = '# ---- BEGIN LINES TO DUPLICATE ----';
25 my $fromend = '# ---- END LINES TO DUPLICATE ----';
26 my $tobegin = '# ---- BEGIN DUPLICATE LINES ----';
27 my $toend = '# ---- END DUPLICATE LINES ----';
29 open IN, '<', $ARGV[0] or die "could not open $ARGV[0] for reading: $!\n";
30 my $input;
32 local $/;
33 $input = <IN>;
35 close IN;
36 $input =~ s/^##.*(?:\n|$)//gm;
37 my $repl = sub {
38 no warnings;
39 if (eval '$Girocco::Config::'.$_[1]) {
40 $_[0] ? "Girocco_Config_$_[1]_Disabled" : "!Girocco_Config_$_[1]_Disabled";
41 } else {
42 $_[0] ? "!Girocco_Config_$_[1]_Enabled" : "Girocco_Config_$_[1]_Enabled";
45 $input =~ s/^(\s*<IfDefine\s+)(!?)\@\@([a-zA-Z][a-zA-Z0-9_]*)\@\@>/
46 $1 . &$repl($2, $3) . '>'/gmexi;
48 no warnings;
49 $input =~ s/\@\@([a-zA-Z][a-zA-Z0-9_]*)\@\@/eval
50 "\$Girocco::Config::$1 ne ''?\$Girocco::Config::$1:'\@\@'.\"$1\".'\@\@'"/gsex;
52 if ($input =~ /(?:^|\n)$frombegin[^\n]*\n(.*)(?<=\n)$fromend/s) {
53 my $dupelines = $1;
54 if ($input =~ /^((?:.+\n)?$tobegin[^\n]*\n).*((?<=\n)$toend.*)$/s) {
55 $input = $1 . $dupelines . $2;
58 printf "%s", $input;
59 EOT
60 mv -f apache.conf.$$ apache.conf