Apache-Roaming

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

use lib 'lib';
eval { require Apache::Roaming::LiPrefs::Config };

my $cfg;
eval {require File::Spec; require Data::Dumper};
if (!$@  &&
    (!($cfg = eval { require ".status"})  or  $opt_config)) {
    $cfg = {} if !$cfg or ref($cfg) ne 'HASH';
    my $httpd_path = $cfg->{'httpd_path'};
    if (!$httpd_path) {
	foreach my $dir (File::Spec->path()) {
	    my $file = File::Spec->catfile($dir, "httpd");
	    if (-x $file) {
		$httpd_path = $file;
		last;
	    }
	}
    }
    $cfg->{'httpd_path'} = prompt("Path of the Apache server: ",
				  $httpd_path || '/usr/sbin/httpd');
    die "Cannot execute HTTPD server $cfg->{'httpd_path'}: No such file"
	unless -x $cfg->{'httpd_path'};

    my $httpd_V_output = `$cfg->{'httpd_path'} -V`;
    my $httpd_conf_path =
	($httpd_V_output =~ /\s+-D\s+SERVER_CONFIG_FILE="(.*?)"/) ?
	    $1 : "/etc/httpd/httpd.conf";
    $cfg->{'httpd_conf_path'} = prompt("Path of the httpd.conf file: ",
				       $httpd_conf_path);
    my $httpd_conf_contents;
    die "Failed to read httpd config file $cfg->{'httpd_conf_path'}: $!"
	unless open(FILE, "<$cfg->{'httpd_conf_path'}");

    my(@module_list, $server_root);
    while (defined(my $line = <FILE>)) {
	if ($line =~ /\s*ServerRoot\s+\"?(.*?)\"?\s*$/) {
	    $server_root = $1;
	}
	if ($line =~ /^\s*(AddModule|LoadModule)\s+/  ||
	    $line =~ /^\s*ClearModuleList\s*$/) {
	    push(@module_list, $line);
	}
    }
    close(FILE);
    @module_list = map {
	if ($_ =~ /^\s*LoadModule\s+(\S+)\s+(.*)/) {
	    my $module = $1;
	    my $path = $2;
	    if ($path !~ /^\//) {
		die "Cannot parse httpd config file $cfg->{'httpd_conf_path'}:"
		    . " Missing ServerRoot" unless $server_root;
		$_ = "LoadModule $module $server_root/$path\n";
	    }
	}
	$_;
    } @module_list;
    $cfg->{'dynamic_module_list'} = join("", @module_list);

    $cfg->{'httpd_user'} = prompt("HTTPD's UID for running tests: ",
				  $cfg->{'httpd_user'} || ('#' . $>));
    my $gid = $);
    $gid =~ s/\s.*//;
    $cfg->{'httpd_group'} = prompt("HTTPD's GID for running tests: ",
				   $cfg->{'httpd_group'} || ('#' . $gid));
    $cfg->{'httpd_port'} = prompt("Port to use for running tests: ",
				  $cfg->{'httpd_port'} || 8259);

    my $tdir = $cfg->{'t_dir'} = File::Spec->catdir(Cwd::getcwd(), "t");
    $cfg->{'httpd_conf'} = File::Spec->catfile($tdir, "httpd.cnf");
    $cfg->{'access_conf'} = File::Spec->catfile($tdir, "access.cnf");
    $cfg->{'srm_conf'} = File::Spec->catfile($tdir, "srm.cnf");
    $cfg->{'types_conf'} = File::Spec->catfile($tdir, "mime.types");
    $cfg->{'user_file'} = File::Spec->catfile($tdir, "htusers");
    my $log_dir = File::Spec->catdir($tdir, "logs");
    $cfg->{'log_dir'} = $log_dir;
    $cfg->{'access_log'} = File::Spec->catfile($log_dir, "access.log");
    $cfg->{'error_log'} = File::Spec->catfile($log_dir, "error.log");
    $cfg->{'lock_file'} = File::Spec->catfile($log_dir, "httpd.lck");
    $cfg->{'pid_file'} = File::Spec->catfile($log_dir, "httpd.pid");
    my $o_dir = $cfg->{'output_dir'} = File::Spec->catdir($tdir, "output");
    $cfg->{'roaming_dir'} = File::Spec->catdir($o_dir, "roaming");

    my $dump = Data::Dumper->new([$cfg], ['cfg']);
    $dump->Indent(1);
    if (!open(STATUS, ">.status")  ||
	!(print STATUS $dump->Dump())  ||
	!close(STATUS)) {
	die "Error while creating file .status: $!";
    }

    my $reply = prompt("Do you want to configure the Apache::Roaming::LiPrefs module?", "y");
    if ($reply =~ /y/i) {
	foreach my $ref
	    (['Enable Autoupdate', 'bool', 'initial', 'autoupdate.enabled',
	      'false'],
	     ["Enable what's related?", 'bool', 'initial',
	      'browser.related.enabled', 'true'],
	     ['Startup Page', 'string', 'initial', 'browser.startup.page',
	      'none',
	      sub {
		  my $in = shift;
		  $in = 'none' if !defined($in) or $in eq '0';
		  $in;
	      },
	      sub {
		  my $out = shift;
		  $out = '0' if !defined($out) or $out eq 'none';
	      }],
	     ['By default send HTML mail', 'bool', 'initial',
	      'mail.html_compose', 'false'],
	     ['Default domain', 'string', 'initial',
	      'mail.identity.defaultdomain'],
	     ['Leave mail on server', 'bool', 'initial',
	      'mail.leave_on_server', 'false'],
	     ['Remember mail password', 'bool', 'initial',
	      'mail.remember_password', 'false'],
	     ['Default NNTP server', 'string', 'initial',
	      'network.hosts.nntp_server'],
	     ['Default POP3 server', 'string', 'initial',
	      'network.hosts.pop_server'],
	     ['Default SMTP server', 'string', 'initial',
	      'network.hosts.smtp_server'],
	     ['Proxy autoconfiguration URL', 'string', 'initial',
	      'network.proxy.autoconfig_url'],



( run in 0.488 second using v1.01-cache-2.11-cpan-5735350b133 )