File: assisted_install_helper.pl

package info (click to toggle)
libhtml-mason-perl 1%3A1.26-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,636 kB
  • ctags: 1,260
  • sloc: perl: 13,880; sh: 154; makefile: 47
file content (164 lines) | stat: -rwxr-xr-x 4,183 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use strict;

use lib 't/lib';

use Apache::test;
use Data::Dumper;
use ExtUtils::MakeMaker qw(prompt);
use File::Basename;
use File::Spec;

sub assisted_install_config
{
    return unless $APACHE{httpd};

    my %httpd_params = Apache::test->get_compilation_params( $APACHE{httpd} );

    my $conf_file = $APACHE{config_file} ? $APACHE{config_file} : $httpd_params{SERVER_CONFIG_FILE};
    my %config_params = eval { _get_config_file_params($conf_file) };
    warn " * Can't investigate current installation status:\n $@" and return if $@;

    foreach my $k ( qw( document_root user group ) )
    {
	# strip quotes if they're there.
	for ( $config_params{$k}) { s/^"//; s/"$//; }
    }

    my $default = $config_params{has_mason} ? 'no' : 'yes';

    my $conf_dir = dirname( $conf_file );
    $default = 'no' if -e File::Spec->catfile( $conf_dir, 'mason.conf' );

    print <<"EOF";

It is possible to have this program automatically set up a simple
Mason configuration.  This would involve altering the configuration
file at $conf_file.

EOF

    print "It appears that this configuration file does " . ($config_params{has_mason} ? '' : 'not ' ) . "have previous Mason configuration directives.\n\n";

    my $yn = prompt( 'Would you like help configuring Apache/mod_perl to use Mason?', $default );

    return unless $yn =~ /^y/i;

    my %install = ( user => $config_params{user},
		    group => $config_params{group},
		    apache_config_file => $conf_file,
		  );

    print <<'EOF';

Mason needs to know what your component root should be.  This is a
directory in which Mason can expect to find components.  Generally,
when starting out with Mason this will either be your server's
document root or a subdirectory below it.

If this directory does not exist it will be created.

EOF

    do
    {
	$install{comp_root} = prompt( 'Component root?', $config_params{document_root} );
    } until $install{comp_root};

    print <<'EOF';

Mason needs to know where it should store data files that it
generated.  This includes compiled components, cache files, and other
miscellania that Mason generates.  This directory will be made
readable and writable by the user the web server runs as.

EOF

    do
    {
	$install{data_dir} = prompt( 'Data directory?',
				     File::Spec->catdir( $httpd_params{HTTPD_ROOT}, 'mason' ) );
	if ($install{data_dir} && -e $install{data_dir})
	{
	    my $yn = prompt( "This directory ('$install{data_dir}') already exists, is that ok?", 'yes' );
	    delete $install{data_dir} unless $yn =~ /y/;
	    print "\n";
	}
    } until $install{data_dir};

    print <<'EOF';

It is often desirable to tell the web server to only recognize certain
extensions as Mason components.  This allows you to easily put HTML,
images, etc. and Mason components all together under the document root
without worrying that Mason will try to serve static content.

Enter a list of extensions separated by spaces.  Periods are not
needed.

If you want all files under the document root to be treated as Mason
components simply enter '!' here.

EOF

    my @ext;
    do
    {
	my $ext = prompt( 'What extensions should the web server recognize as Mason components', 'html' );
	@ext = map { s/^\.//; $_ } split /\s+/, $ext;

	unless (@ext == 1 && $ext[0] eq '!')
	{
	    $install{extensions} = \@ext;
	}
    } until @ext;

    local *INST;
    open INST, ">./apache_install.txt" or die "Can't write to ./apache_install.txt: $!";
    print INST Data::Dumper->Dump([\%install], ['install']);
    close INST or die "Can't close ./apache_install.txt: $!";
}

sub _get_config_file_params
{
    my $file = shift;

    local *CONF;

    open CONF, "<$file"	or die "Can't read $file: $!\n";

    my %conf;
    while (<CONF>)
    {
	next if /^\s*\#/; # skip comments

	# all regexes below attempt to make sure that they're not in a
	# comment

	if ( /[^\#]*HTML::Mason/ )
	{
	    $conf{has_mason} = 1;
	}

	if ( /[^\#]*DocumentRoot\s+(.*)/ )
	{
	    $conf{document_root} = $1;
	}

	if ( /[^\#]*User\s+(.*)/ )
	{
	    $conf{user} = $1;
	}

	if ( /[^\#]*Group\s+(.*)/ )
	{
	    $conf{group} = $1;
	}
    }

    close CONF or die "Can't close $file: $!";

    return %conf;
}


1;