/
required.pl
249 lines (201 loc) · 7.54 KB
/
required.pl
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/perl -w
=head1 NAME
required.pl - installation script to probe for required software
=head1 VERSION
$LastChangedRevision$
=head1 DATE
$LastChangedDate$
=head1 DESCRIPTION
This script is called during "make" to probe for required software -
Perl, Apache, Postgres, and Expat currently. Output collected
in "required.db".
=head1 AUTHOR
Sam Tregar <stregar@about-inc.com>
=head1 SEE ALSO
L<Bric::Admin>
=cut
use strict;
# check required Perl version first, fail immediately if too old
BEGIN {
eval { require 5.006 };
if ($@) {
print "#" x 79, "\n\n", <<END, "\n", "#" x 79, "\n";
Bricolage requires Perl version 5.6.0 or later. 5.8.0 or later is strongly
recommended for its better Unicode support. Please upgrade your version of
Perl before re-running make. You can find the latest versions of Perl
at 'http://perl.com/'.
END
exit 1;
}
eval { require 5.008 };
if ($@) {
print "#" x 79, "\n\n", <<END, "\n", "#" x 79, "\n";
Found Bricolage 5.6.x, but Perl 5.8.0 or later is strongly recommended for its
better Unicode support. If you need good Unicode support, please upgrade your
version of of Perl before re-running make. You can find the latest versions of
Perl at 'http://perl.com/'.
END
}
}
use FindBin;
use lib "$FindBin::Bin/lib";
use Bric::Inst qw(:all);
use File::Spec::Functions;
use Data::Dumper;
use Config;
our %REQ;
our %RESULTS;
# check to see whether we should ask questions or not
our $QUIET;
$QUIET = 1 if $ARGV[0] and $ARGV[0] eq 'QUIET';
# collect data - configuration requirements data goes into %REQ, raw
# binary pass/fail goes into %RESULTS.
print "\n\n==> Probing Required Software <==\n\n";
# run tests
$RESULTS{PG} = find_pg();
$RESULTS{APACHE} = find_apache();
$RESULTS{EXPAT} = find_expat();
# print error message and fail if something not found
unless ($RESULTS{PG} and $RESULTS{APACHE} and
$RESULTS{EXPAT}) {
hard_fail("Required software not found:\n\n",
$RESULTS{PG} ? "" :
"\tPostgreSQL >= 7.3.0 (http://postgresql.org)\n",
$RESULTS{APACHE} ? "" :
"\tApache >= 1.3.12 (http://apache.org)\n",
$RESULTS{EXPAT} ? "" :
"\texpat >= 1.95.0 (http://expat.sourceforge.net)\n",
"\nSee INSTALL for details.\n"
);
}
# success, write out %REQ hash into required.db
open(OUT, ">required.db") or die "Unable to open required.db : $!";
print OUT Data::Dumper->Dump([\%REQ],['REQ']);
close OUT;
# all done
print "\n\n==> Finished Probing Required Software <==\n\n";
exit 0;
# look for postgresql
sub find_pg {
print "Looking for PostgreSQL with version >= 7.3.0...\n";
# find PostgreSQL by looking for pg_config.
my @paths = (path(), split(", ", get_default("PG_CONFIG_PATH")));
foreach my $path (@paths) {
if (-e catfile($path, "pg_config")) {
$REQ{PG_CONFIG} = catfile($path, "pg_config");
last;
}
}
# confirm or deny
if ($REQ{PG_CONFIG}) {
print "Found PostgreSQL's pg_config at '$REQ{PG_CONFIG}'.\n";
unless (ask_yesno("Is this correct?", 1, $QUIET)) {
ask_confirm("Enter path to pg_config", \$REQ{PG_CONFIG});
}
} else {
print "Failed to find pg_config.\n";
if (ask_yesno("Do you want to provide a path to pg_config?", 0, $QUIET)) {
$REQ{PG_CONFIG} = 'NONE';
ask_confirm("Enter path to pg_config", \$REQ{PG_CONFIG});
} else {
return soft_fail("Failed to find pg_config. Looked in:",
map { "\n\t$_" } @paths);
}
}
# check version
my $version = `$REQ{PG_CONFIG} --version`;
return soft_fail("Failed to find PostgreSQL version with ",
"`$REQ{PG_CONFIG} --version`.") unless $version;
chomp $version;
my ($x, $y, $z) = $version =~ /(\d+)\.(\d+)(?:\.(\d+))?/;
return soft_fail("Failed to parse PostgreSQL version from string ",
"\"$version\".")
unless defined $x and defined $y;
$z ||= 0;
return soft_fail("Found old version of Postgres: $x.$y.$z - ",
"7.3.0 or greater required.")
unless (($x > 7) or ($x == 7 and $y >= 3));
print "Found acceptable version of Postgres: $x.$y.$z.\n";
$REQ{PG_VERSION} = [$x,$y,$z];
return 1;
}
# look for apache
sub find_apache {
print "Looking for Apache with version >= 1.3.12...\n";
# find Apache by looking for executables called httpd, httpsd,
# apache-perl or apache, in that order. First search user's
# path then some standard locations.
my @paths = (path(), split(", ", get_default("APACHE_PATH")));
my @exe = (split(", ", get_default("APACHE_EXE")));
FIND:
foreach my $exe (@exe) {
foreach my $path (@paths) {
if (-e catfile($path, $exe)) {
$REQ{APACHE_EXE} = catfile($path, $exe);
last FIND;
}
}
}
# confirm or deny
if ($REQ{APACHE_EXE}) {
print "Found Apache server binary at '$REQ{APACHE_EXE}'.\n";
unless ($QUIET or ask_yesno("Is this correct?", 1)) {
ask_confirm("Enter path to Apache server binary",
\$REQ{APACHE_EXE});
}
} else {
print "Failed to find Apache server binary.\n";
if (ask_yesno("Do you want to provide a path to the Apache server " .
"binary?", 0, $QUIET)) {
$REQ{APACHE_EXE} = 'NONE';
ask_confirm("Enter path to Apache server binary",
\$REQ{APACHE_EXE});
} else {
return soft_fail("Failed to find Apache executable. Looked for ",
join(', ', @exe),
" in:",
map { "\n\t$_" } @paths);
}
}
print "Found Apache executable at $REQ{APACHE_EXE}.\n";
# check version
my $version = `$REQ{APACHE_EXE} -v`;
return soft_fail("Failed to find Apache version with ",
"`$REQ{APACHE_EXE} -v`.") unless $version;
chomp $version;
my ($x, $y, $z) = $version =~ /(\d+)\.(\d+).(\d+)/;
return soft_fail("Failed to parse Apache version from string ",
"\"$version\".")
unless defined $x and defined $y and defined $z;
return soft_fail("Found Apache 2. Bricolage only supports Apache 1.3.\n")
if $x > 1;
return soft_fail("Found old version of Apache: $x.$y.$z - ",
"1.3.12 or greater required.")
unless (($x == 1 and $y > 3) or ($x == 1 and $y == 3 and $z >= 12));
print "Found acceptable version of Apache: $x.$y.$z.\n";
$REQ{APACHE_VERSION} = [$x,$y,$z];
return 1;
}
# look for Expat
sub find_expat {
print "Looking for expat...\n";
# find expat libary libexpat.so by looking in library paths that
# Perl knows about
my @paths = grep { defined and length } ( split(' ', $Config{libsdirs}),
split(' ', $Config{loclibpth}));
push @paths, split(", ", get_default("EXPAT_PATH"));
my @files = split(", ", get_default("EXPAT_FILE"));
LOOK: foreach my $path (@paths) {
foreach my $file(@files) {
if (-e catfile($path, $file)) {
$REQ{EXPAT} = catfile($path, "libexpat.so");
last LOOK;
}
}
}
return soft_fail("Failed to find libexpat.so. Looked in:",
map { "\n\t$_" } @paths) unless $REQ{EXPAT};
print "Found expat at $REQ{EXPAT}.\n";
# I should check that expat is >= 1.95.0. Um, how do I do that?
return 1;
}