root/tags/rel0_61/Build.PL

Revision 1093, 13.9 kB (checked in by dom, 17 months ago)

Send email notifications when moderated nodes are edited (fixes #138)

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