root/trunk/Build.PL

Revision 1216, 14.3 kB (checked in by dom, 1 week ago)

Correctly specify all build_requires (fixes #245)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 use strict;
2 use lib "lib";
3 use Data::Dumper;
4 use Getopt::Long;
5
6 eval {
7     require Config::Tiny;
8     # OpenGuides::Build and OpenGuides::Config both use Config::Tiny.
9     require OpenGuides::Build;
10     require OpenGuides::Config;
11 };
12
13 die "Problem loading OpenGuides module or a missing module\n\n$@.\n" if $@;
14
15 my $force;
16
17 GetOptions('force' => \$force);
18
19 unless ($force) {
20         print <<EOF;
21
22 Beginning install process... if you already have an OpenGuides
23 configuration file and you don't want to have to type in all your config
24 parameters over again, abort this process now, copy that file to this
25 directory, and start again.
26
27 EOF
28
29 my $continue = Module::Build->y_n("Continue with install?", "y");
30 exit 0 unless $continue;
31 }
32
33 my $existing_config_file = 'wiki.conf';
34 my $existing_config;
35
36 if (-f $existing_config_file) {
37     $existing_config = OpenGuides::Config->new(file => $existing_config_file);
38 } else {
39     print <<EOF;
40 No existing configuration file found; assuming this is a new install.
41 See the message above if this isn't correct.
42
43 EOF
44     $existing_config = OpenGuides::Config->new();
45 }
46
47 my %yn_vars = map { $_ => 1 }
48    qw(use_plucene enable_page_deletion navbar_on_home_page backlinks_in_title
49       moderation_requires_password enable_node_image enable_common_categories
50       enable_common_locales recent_changes_on_home_page
51       random_page_omits_locales random_page_omits_categories
52       content_above_navbar_in_html show_gmap_in_node_display force_wgs84
53       send_moderation_notifications);
54
55 my $skip_config = $force ? 'y' : Module::Build->y_n("Skip OpenGuides configuration?", "n");
56 if ( $skip_config ) {
57     print <<EOF;
58 ===========================================================================
59 Skipping OpenGuides configuration - any configuration options previously
60 saved will be used instead.  You may tweak your configuration now by
61 editing the 'wiki.conf' file produced by this script.
62 ===========================================================================
63 EOF
64 }
65
66 my @answers;
67
68 # It is an ancient Configurer, and he chooseth one of three.
69 my $dbtype;
70 my $dbtype_qu = $existing_config->dbtype__qu;
71 if ( $skip_config ) {
72     $dbtype = $existing_config->dbtype;
73 } else {
74     until ( $dbtype ) {
75         my $def = $existing_config->dbtype;
76         $dbtype = Module::Build->prompt("\n$dbtype_qu", $def);
77         $dbtype = lc($dbtype);
78         $dbtype =~ s/^\s*//;
79         $dbtype =~ s/\s*$//;
80         unless ( $dbtype eq "postgres" or $dbtype eq "mysql"
81                  or $dbtype eq "sqlite" ) {
82             undef $dbtype;
83         }
84     }
85 }
86
87 # Check they have the relevant DBD driver installed.
88 my %drivers = ( postgres => "DBD::Pg",
89                 mysql    => "DBD::mysql",
90                 sqlite   => "DBD::SQLite",
91               );
92 eval "require $drivers{$dbtype}";
93 warn "$drivers{$dbtype} is needed to run a $dbtype database" if $@;
94
95 push @answers, { question => $dbtype_qu,
96                  variable => "dbtype",
97                  value    => $dbtype };
98
99 my $install_directory; # used to suggest template paths
100 my $use_plucene = 1; # keep track of this so we know what to put in prereqs
101 my $centre_lat = ''; # contains centre lat derived from Google Maps URL
102 foreach my $var ( qw(
103    dbname dbuser dbpass dbhost dbport script_name
104    install_directory template_path custom_template_path script_url
105    custom_lib_path use_plucene indexing_directory enable_page_deletion
106    admin_pass stylesheet_url site_name navbar_on_home_page
107    recent_changes_on_home_page random_page_omits_locales
108    random_page_omits_categories content_above_navbar_in_html home_name
109    site_desc default_city default_country contact_email default_language
110    formatting_rules_node backlinks_in_title gmaps_api_key centre_long
111    centre_lat show_gmap_in_node_display default_gmaps_zoom
112    default_gmaps_search_zoom force_wgs84 google_analytics_key
113    licence_name licence_url licence_info_url moderation_requires_password
114    enable_node_image enable_common_categories enable_common_locales
115    spam_detector_module host_checker_module static_path static_url
116    send_moderation_notifications
117   ) ) {
118     my $q_method = $var . "__qu";
119     my $qu  = $existing_config->$q_method;
120     my $type = $yn_vars{$var} ? "y_n" : "";
121     my $def = $existing_config->$var;
122     my $val = $def;
123
124     # Override dbname question for SQLite only.
125     if ( $dbtype eq "sqlite" and $var eq "dbname" ) {
126         $qu = "what's the full filename of the SQLite database this site runs on?";
127     }
128
129     if ( $dbtype eq "sqlite" and
130          ( $var eq "dbuser" or $var eq "dbpass" or $var eq "dbhost" or
131            $var eq "dbport")
132        ) {
133         print "$var not relevant for SQLite... skipping...\n"
134             unless $skip_config;
135         push @answers, { question => $qu,
136                             variable => $var,
137                          value    => "not-used" };
138         next;
139     }
140
141     # We don't ask this for new installs as Search::InvertedIndex is
142     # deprecated
143     if ( $var eq "use_plucene" and $existing_config->$var == 1) {
144         print "Skipping question about plucene\n"
145             unless $skip_config;
146         push @answers, { question => $qu,
147                          variable => $var,
148                          value => 1 };
149         next;
150     }
151
152     # Make sensible suggestions for template paths if we don't already
153     # have them stored.  Not really a default, but a useful hint/shortcut.
154     if ( $var eq "template_path" && !defined $existing_config->$var ) {
155         $def = $install_directory;
156         $def .= "/" unless $def =~ m|/$|;
157         $def .= "templates";
158     }
159     if ( $var eq "custom_template_path" && !defined $existing_config->$var ) {
160         $def = $install_directory;
161         $def .= "/" unless $def =~ m|/$|;
162         $def .= "custom-templates";
163     }
164
165     # If a Google Maps URL was provided last time we know the centre_lat
166     if ( $var eq 'centre_lat' && $centre_lat ) {
167         $val = $centre_lat;
168         next;
169     }   
170
171     # Here is where we actually ask the questions.
172     unless ( $skip_config ) {
173         if ( $type eq "y_n" ) {
174             # may be stored as true/false integer value
175             if ( $def =~ /^\d+$/ ) {
176                 $def = $def ? "y" : "n";
177             }
178             $val = Module::Build->y_n("\n$qu ", $def);
179         } else {
180             $val = Module::Build->prompt("\n$qu ", $def);
181         }
182     }
183
184     # Allow user to use a Google Maps URL rather than enter lat/long by hand.
185     # We assume centre_long is being asked for first; ensure so in big list above.
186     if ( $var eq 'centre_long' ) {
187         if ( $val =~ /ll=([-\d.]+),([-\d.]+)/ ) {
188             print "Got a Google Maps URL with centre long,lat: [$1, $2]\n";
189             $val = $1;
190             $centre_lat = $2;
191         }
192     }
193
194     # Store install_directory so we can use it to suggest template paths.
195     $install_directory = $val if $var eq "install_directory";
196
197     # Keep track of chosen search method so we know what to put in prereqs.
198     # From Module::Build docs: ->y_n returns a Perl boolean true or false.
199     $use_plucene = 1 if $var eq "use_plucene" and $val;
200
201     # Make sure that script_url ends in a /
202     if ( $var eq "script_url" and $val !~ /\/$/ ) {
203         $val .= "/";
204     }
205
206     push @answers, { question => $qu,
207                      variable => $var,
208                      value    => $val };
209 }
210
211 # Now deal with the geo stuff.
212 my $geo_handler;
213 my $geo_handler_qu = "Distance calculation methods available are:"
214                    . "\n  1) British National Grid"
215                    . "\n  2) Irish National Grid"
216                    . "\n  3) UTM ellipsoid"
217                    . "\nWhich would you like to use?";
218
219 if ( $skip_config ) {
220     # We default to GB National Grid for historical reasons.
221     $geo_handler = $existing_config->geo_handler;
222 } else {
223     my $choice;
224     until ( $choice ) {
225         my $def = $existing_config->geo_handler;
226         $choice = Module::Build->prompt("\n".$geo_handler_qu, $def);
227         $choice =~ s/^\s*//;
228         $choice =~ s/\s*$//;
229         unless ( $choice eq "1" or $choice eq "2" or $choice eq "3" ) {
230             undef $choice;
231         }
232     }
233     $geo_handler = $choice;
234 }
235
236 $geo_handler_qu =~ s/\n//gs;
237 push @answers, {
238                  question => $geo_handler_qu,
239                  variable => "geo_handler",
240                  value    => $geo_handler,
241                };
242
243 if ( $geo_handler eq "3" ) {
244     my $qu = $existing_config->ellipsoid__qu;
245     my $ellipsoid;
246     if ( $skip_config ) {
247         $ellipsoid = $existing_config->ellipsoid;
248     } else {
249         my $def = $existing_config->ellipsoid;
250         $ellipsoid = Module::Build->prompt("\n".$qu, $def);
251         $ellipsoid =~ s/^\s*//;
252         $ellipsoid =~ s/\s*$//;
253     }
254     push @answers, {
255                      question => $qu,
256                      variable => "ellipsoid",
257                      value    => $ellipsoid,
258                    };
259 }
260
261 # Create a user-friendly config file from answers to prompts.
262 open FILE, ">wiki.conf" or die "Can't open wiki.conf for writing: $!";
263 foreach my $ans (@answers) {
264     print FILE "# $ans->{question}\n";
265     print FILE "$ans->{variable} = $ans->{value}\n\n";
266 }
267 close FILE or die "Can't close wiki.conf: $!";
268
269 #####
270 ##### When updating the prereqs PLEASE REMEMBER to update PREREQUISITES.
271 #####
272
273 # We currently only support Plucene for new installs, but may support
274 # others in future
275 my $search_module = $use_plucene ? "Plucene" : "Search::InvertedIndex";
276
277 # Create the build object.
278 my $build = OpenGuides::Build->new(
279     sign => 1,
280     dist_name => "OpenGuides",
281     module_name => "OpenGuides",
282     dist_version_from => "wiki.cgi",
283     license => "perl",
284     requires => {
285         'Algorithm::Diff'                     => '0.13'# for sdiff
286         'CGI'                                 => '2.92'# avoid escapeHTML bug
287         'CGI::Carp'                           => 0,
288         'CGI::Cookie'                         => 0,
289         'Wiki::Toolkit'                       => '0.74'# for dbport
290         'Wiki::Toolkit::Feed::Atom'           => 0,
291         'Wiki::Toolkit::Feed::RSS'            => 0,
292         'Wiki::Toolkit::Formatter::UseMod'    => 0,
293         'Wiki::Toolkit::Plugin::Categoriser'  => 0,
294         'Wiki::Toolkit::Plugin::Diff'         => 0,
295         'Wiki::Toolkit::Plugin::Locator::Grid'=> 0,
296         'Wiki::Toolkit::Plugin::RSS::Reader'  => 0,
297         'Class::Accessor'                     => 0,
298         'Config::Tiny'                        => 0,
299         'Data::Dumper'                        => 0,
300         $drivers{$dbtype}                     => 0,
301         'File::Spec::Functions'               => 0,
302         'File::Temp'                          => 0,
303                 'Geo::Coordinates::UTM'               => 0,
304         'Geography::NationalGrid'             => 0,
305         'HTML::Entities'                      => 0,
306         'LWP::Simple'                         => 0,
307         'MIME::Lite'                          => 0,
308         'Parse::RecDescent'                   => 0,
309         $search_module                        => 0,
310         'POSIX'                               => 0,
311         'Template'                            => '2.15', # for hash.delete and string.remove vmethods
312         'Time::Piece'                         => 0,
313         'URI::Escape'                         => 0,
314         'XML::RSS'                            => 0,
315         },
316     build_requires => {
317         'Module::Build' => '0.26', # API change for accessing config data
318         'Class::Accessor'                     => 0,
319         'Config::Tiny'                        => 0,
320         'Data::Dumper'                        => 0,
321         },
322     recommends => {
323         'DBD::SQLite'         => 0, # for testing
324         'Test::HTML::Content' => 0, # for testing, oddly enough
325         'Wiki::Toolkit::Plugin::Ping' => 0, # for pinging external services
326         'Geo::HelmertTransform'  => 0,      # for correct WGS84 lat/long
327                                             # when using grid systems
328
329     },
330     dynamic_config => 1,
331     create_makefile_pl => "passthrough"
332 );
333
334 $build->add_to_cleanup( "t/indexes/" );
335 $build->add_to_cleanup( "t/node.db" );
336 $build->add_to_cleanup( "t/templates/tmp/" );
337
338 # Tell OpenGuides::Build which additional scripts and templates to install.
339 $build->config_data( __extra_scripts =>
340                       [ "wiki.conf", "preferences.cgi", "search.cgi",
341                         "newpage.cgi" ] );
342 $build->config_data( __templates     => [
343                       "admin_home.tt",
344                       "admin_revert_user.tt",
345                       "backlink_results.tt",
346                       "banner.tt",
347                       "blacklisted_host.tt",
348                       "delete_confirm.tt",
349                       "delete_done.tt",
350                       "delete_password_wrong.tt",
351                       "differences.tt",
352                       "display_metadata.tt",
353                       "edit_form.tt",
354                       "edit_form_actions.tt",
355                       "error.tt",
356                       "footer.tt",
357                       "header.tt",
358                       "home_node.tt",
359                       "map_index.tt",
360                       "missing_metadata.tt",
361                       "moderate_confirm.tt",
362                       "moderate_password_wrong.tt",
363                       "navbar.tt",
364                       "navbar_categories.tt",
365                       "navbar_locales.tt",
366                       "navbar_help.tt",
367                       "navbar_home_link.tt",
368                       "navbar_options.tt",
369                       "navbar_revision_info.tt",
370                       "navbar_search.tt",
371                       "navbar_this_page.tt",
372                       "navbar_tools.tt",
373                       "needing_moderation.tt",
374                       "newpage.tt",
375                       "node.tt",
376                       "node_history.tt",
377                       "node_image_fields.tt",
378                       "node_photo_notes.tt",
379                       "node_rdf.tt",
380                       "openguides_information_boxes.tt",
381                       "preferences.tt",
382                       "random_page_failure.tt",
383                       "rdf_index.tt",
384                       "recent_changes.tt",
385                       "search_results.tt",
386                       "site_index.tt",
387                       "search.tt",
388                       "spam_detected.tt",
389                       "userstats.tt",
390                       "wanted_pages.tt"
391     ] );
392
393 $build->config_data( __static_files => [
394     # XXX to be supplied when we have some
395     ] );
396
397 # Finally write the build script.
398 $build->create_build_script;
Note: See TracBrowser for help on using the browser.