#!/usr/bin/perl -s

$HTTPD_CONF="/etc/httpd/conf/httpd.conf" if (! $HTTPD_CONF);
$CONF_FILE = "httpd.conf";
$RECOG_HOME = $ENV{RECOG_HOME} if (! $RECOG_HOME);

if (! $LISTEN_ADDR) {
	print STDERR "Warning: Listning address/port (LISTEN_ADDR) is missing\n";
}

open(F, $HTTPD_CONF);
open(O, ">$CONF_FILE");
while (<F>) {
	if (/^Listen /) {
		if ($LISTEN_ADDR) {
			print O "## $_";
			print O "Listen $LISTEN_ADDR\n";
		} else {
			print O "## *** EDIT HERE!! ***\n";
			chomp;
			print STDERR "$_ <<<You should edit this line by yourself\n\n";
			print O $_;
		}
	} elsif (/^Include .*\/\*.conf/ || /^Include .*\ssl\.conf$/) {
		print STDERR "Warning: the line possibly for SSL setup is commented out\n";
		chomp;
		print STDERR "$_ <<<The line is here\n\n";
		print O "## $_";
	} elsif (/^CustomLog/) {
		print O "## $_";
	} elsif (/^LoadModule ssl_module/) {
		print O "## $_";
	} else {
		print O $_;
	}
}
close(F);
print O  "Include $RECOG_HOME/WWW/conf/httpd-recog.conf\n";
close(O);

