root/tags/rel0_58/Build.PL

Revision 918, 12.6 kB (checked in by dom, 2 years ago)

don't duplicate stuff

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