indextext.html: update notice about ssh host key change
[girocco/readme.git] / make-apache-conf.sh
blob5c9de5f7b4c85b017080dd089a70ddb6a2db1903
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" -MGirocco::Validator -- - apache.conf.in >apache.conf.$$ <<'EOT'
23 #line 24 "make-apache-conf.sh"
24 use strict;
25 use warnings;
27 BEGIN { # hack to make var_online_cpus and var_getconfpath available now
28 $INC{'Girocco/Config.pm'} = 1;
29 require Girocco::Util;
30 my $online_cpus = Girocco::Util::online_cpus();
31 defined($online_cpus) && $online_cpus >= 1 or $online_cpus = 1;
32 eval '$Girocco::Config::var_online_cpus = $online_cpus;';
33 require Girocco::Dumper;
34 my $getconfpath = Girocco::Dumper::GetConfPath();
35 defined($getconfpath) && $getconfpath ne "" or $getconfpath = "/usr/bin:/bin";
36 eval '$Girocco::Config::var_getconfpath = $getconfpath;';
39 my $frombegin = '# ---- BEGIN LINES TO DUPLICATE ----';
40 my $fromend = '# ---- END LINES TO DUPLICATE ----';
41 my $tobegin = '# ---- BEGIN DUPLICATE LINES ----';
42 my $toend = '# ---- END DUPLICATE LINES ----';
44 open IN, '<', $ARGV[0] or die "could not open $ARGV[0] for reading: $!\n";
45 my $input;
47 local $/;
48 $input = <IN>;
50 close IN;
51 $input =~ s/^##.*(?:\n|$)//gm;
52 my $replifat = sub {
53 my ($first, $not, $var, $lines, $last) = @_;
54 no warnings;
55 my $test = $var =~ /^\d+$/ ? 0+$var : eval('$Girocco::Config::'.$var);
56 $not and $test = !$test;
57 !$test and $lines =~ s/^/#/gm;
58 return '#'.$first.$lines.'#'.$last;
60 my $replifdef = sub {
61 my ($not, $var) = @_;
62 no warnings;
63 my $test = $var =~ /^\d+$/ ? 0+$var : eval('$Girocco::Config::'.$var);
64 if ($test) {
65 $not ? "Girocco_Config_${var}_Disabled" : "!Girocco_Config_${var}_Disabled";
66 } else {
67 $not ? "!Girocco_Config_${var}_Enabled" : "Girocco_Config_${var}_Enabled";
70 my $cmteol = qr/[ \t]*(?:[#][^\n]*)?\n/;
71 1 while $input =~ s/^([ \t]*\@\@if\((!?)([a-zA-Z][a-zA-Z0-9_]*|\d+)\)\@\@(?>$cmteol)?)(.*?)
72 ((?<=\n)[ \t]*\@\@endif(?:\(\2\3\))?\@\@(?>$cmteol)?)/&$replifat($1, $2, $3, $4, $5)/gsmex;
73 $input =~ s/^(\s*<IfDefine\s+)(!?)\@\@([a-zA-Z][a-zA-Z0-9_]*|\d+)\@\@>/
74 $1 . &$replifdef($2, $3) . '>'/gmexi;
76 no warnings;
77 $input =~ s/(\@\@([a-zA-Z][a-zA-Z0-9_]*)\@\@)/eval
78 "\$Girocco::Config::$2 ne ''?\$Girocco::Config::$2:\$1"/gsex;
80 if ($input =~ /(?:^|\n)$frombegin[^\n]*\n(.*)(?<=\n)$fromend/s) {
81 my $dupelines = $1;
82 if ($input =~ /^((?:.+\n)?$tobegin[^\n]*\n).*((?<=\n)$toend.*)$/s) {
83 $input = $1 . $dupelines . $2;
86 printf "%s", $input;
87 EOT
88 mv -f apache.conf.$$ apache.conf