source: trunk/Build.PL @ 584

Last change on this file since 584 was 584, checked in by kake, 17 years ago

Fix bug with diff display on nodes containing macros.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 KB
Line 
1use strict;
2use lib "lib";
3use OpenGuides::Build;
4use Data::Dumper;
5
6eval "use Config::Tiny";
7die "Config::Tiny is required to configure this application.\n" if $@;
8
9##### Find out where to install, etc.
10
11# See if we already have some config variables set.
12my $read_config = Config::Tiny->read('wiki.conf');
13my %existing_config = $read_config ? %{ $read_config->{_} } : ();
14
15my @questions = (
16{ question =>
17        "What's the name of the database that this site runs on?",
18  variable => "dbname"
19},
20{ question => "...the database user that can access that database?",
21  variable => "dbuser"
22  },
23{ question => "...the password that they use to access the database?",
24  variable => "dbpass"
25  },
26{ question => "...the machine that the database is hosted on? (blank if local)",
27  variable => "dbhost"
28  },
29{ question => "What do you want the script to be called?",
30  variable => "script_name",
31  default  => "wiki.cgi"
32  },
33{ question => "What directory should I install it in?",
34  variable => "install_directory",
35  default  => "/usr/lib/cgi-bin/openguides/"
36  },
37{ question => "What URL does the install directory map to?",
38  variable => "script_url",
39  },
40{ question => "Do you want me to munge a custom lib path into the scripts? "
41             . "If so, enter it here.  Separate path entries with whitespace:",
42  variable => "custom_lib_path",
43  },
44{ question => "Do you want to use Plucene for searching? (recommended, but see Changes file before saying yes to this if you are upgrading)",
45  variable => "use_plucene",
46  default  => "y",
47  type     => "y_n"
48  },
49{ question => "What directory can I use to store indexes in for searching? "
50            . "***NOTE*** This directory must exist and be writeable by the "
51            . "user that your script will run as.  See README for more on this.",
52  variable => "indexing_directory",
53  default  => "/usr/lib/cgi-bin/openguides/indexes/"
54  },
55{ question => "Do you want to enable page deletion?",
56  variable => "enable_page_deletion",
57  default  => "n",
58  type     => "y_n"
59  },
60{ question => "Please specify a password for the site admin:",
61  variable => "admin_pass",
62  default  => "Change this!"
63  },
64{ question => "What's the URL of the site's stylesheet?",
65  variable => "stylesheet_url"
66  },
67{ question => "What's the site called? (should be unique)",
68  variable => "site_name",
69  default  => "My OpenGuides Site"
70  },
71{ question => "Do you want the navigation bar included on the home page?",
72  variable => "navbar_on_home_page",
73  default  => "y",
74  type     => "y_n"
75  },
76{ question => "What should the home page of the wiki be called?",
77  variable => "home_name",
78  default  => "Home"
79  },
80{ question => "How would you describe the site?",
81  variable => "site_desc",
82  default  => "A guide to [my city]"
83  },
84{ question => "What city is the site based in?",
85  variable => "default_city",
86  default  => "London"
87  },
88{ question => "What country is the site based in?",
89  variable => "default_country",
90  default  => "United Kingdom"
91  },
92{ question => "Contact email address for the site administrator?",
93  variable => "contact_email"
94  },
95{ question => "What language will the site be in? (Please give an ISO language code.)",
96  variable => "default_language",
97  default  => "en"
98  },
99{ question => "What's the name of the node to use for the text formatting rules link?",
100  variable => "formatting_rules_node",
101  default  => "Text Formatting Examples"
102  },
103{ question => "Make node titles link to node backlinks (C2 style)?",
104  variable => "backlinks_in_title",
105  default  => "n",
106  type     => "y_n"
107  },
108);
109
110print <<EOF;
111
112Beginning install process... if you already have an OpenGuides
113configuration file and you don't want to have to type in all your config
114parameters over again, abort this process now, copy that file to this
115directory, and start again.
116
117EOF
118
119my $continue = Module::Build->y_n("Continue with install?", "y");
120exit 0 unless $continue;
121
122my $skip_config = Module::Build->y_n("Skip OpenGuides configuration?", "n");
123if ( $skip_config ) {
124    print <<EOF;
125===========================================================================
126Skipping OpenGuides configuration - any configuration options previously
127saved will be used instead.  You may tweak your configuration now by
128editing the 'wiki.conf' file produced by this script.
129===========================================================================
130EOF
131}
132
133my @answers;
134
135# It is an ancient Configurer, and he chooseth one of three.
136my $dbtype;
137my $dbtype_qu = "what type of database do you want the site to run on?  postgres/mysql/sqlite";
138if ( $skip_config ) {
139    $dbtype = $existing_config{dbtype} || "postgres";
140} else {
141    until ( $dbtype ) {
142        my $def = $existing_config{dbtype} || "postgres";
143        $dbtype = Module::Build->prompt("\n$dbtype_qu", $def);
144        $dbtype = lc($dbtype);
145        $dbtype =~ s/^\s*//;
146        $dbtype =~ s/\s*$//;
147        unless ( $dbtype eq "postgres" or $dbtype eq "mysql"
148                 or $dbtype eq "sqlite" ) {
149            undef $dbtype;
150        }
151    }
152}
153
154# Check they have the relevant DBD driver installed.
155my %drivers = ( postgres => "DBD::Pg",
156                mysql    => "DBD::mysql",
157                sqlite   => "DBD::SQLite",
158              );
159eval "require $drivers{$dbtype}";
160die "$drivers{$dbtype} is needed to run a $dbtype database" if $@;
161
162push @answers, { question => $dbtype_qu,
163                 variable => "dbtype",
164                 value    => $dbtype };
165
166foreach my $qset (@questions) {
167    my $qu  = $qset->{question};
168    my $type = $qset->{type} || "";
169    my $var = $qset->{variable};
170    my $def = defined $existing_config{$var} ? $existing_config{$var}
171                                             : $qset->{default};
172    my $val = $def;
173
174    if ( $dbtype eq "sqlite" and $var eq "dbname" ) {
175        $qu = "what's the full filename of the SQLite database this site runs on?";
176    }
177
178    if ( $dbtype eq "sqlite" and
179         ( $var eq "dbuser" or $var eq "dbpass" or $var eq "dbhost" )
180       ) {
181        print "$var not relevant for SQLite... skipping...\n";
182        push @answers, { question => $qu,
183                         variable => $var,
184                         value    => "not-used" };
185        next;
186    }
187
188    unless ( $skip_config ) {
189        if ( $type eq "y_n" ) {
190            # may be stored as true/false integer value
191            if ( $def =~ /^\d+$/ ) {
192                $def = $def ? "y" : "n";
193            }
194            $val = Module::Build->y_n("\n$qu ", $def);
195        } else {
196            $val = Module::Build->prompt("\n$qu ", $def);
197        }
198    }
199
200    # Make sure that script_url ends in a /
201    if ( $var eq "script_url" and $val !~ /\/$/ ) {
202        $val .= "/";
203    }
204
205    push @answers, { question => $qu,
206                     variable => $var,
207                     value    => $val };
208
209    if ( $var eq "install_directory" ) {
210        push @answers, {
211            question => "what directory should I install the templates in?",
212            variable => "template_path",
213            value    => $val . "/templates" };
214        push @answers, {
215            question => "where should I look for custom templates?",
216            variable => "custom_template_path",
217            value    => $val . "/custom-templates" };
218    }
219}
220
221# Now deal with the geo stuff.
222my $geo_handler;
223my $geo_handler_qu = "Distance calculation methods available are:"
224                   . "\n  1) British National Grid"
225                   . "\n  2) Irish National Grid"
226                   . "\n  3) UTM ellipsoid"
227                   . "\nWhich would you like to use?";
228
229if ( $skip_config ) {
230    # We default to GB National Grid for historical reasons.
231    $geo_handler = $existing_config{geo_handler} || 1;
232} else {
233    my $choice;
234    until ( $choice ) {
235        my $def = $existing_config{geo_handler} || 1;
236        $choice = Module::Build->prompt("\n".$geo_handler_qu, $def);
237        $choice =~ s/^\s*//;
238        $choice =~ s/\s*$//;
239        unless ( $choice eq "1" or $choice eq "2" or $choice eq "3" ) {
240            undef $choice;
241        }
242    }
243    $geo_handler = $choice;
244}
245
246$geo_handler_qu =~ s/\n//gs;
247push @answers, {
248                 question => $geo_handler_qu,
249                 variable => "geo_handler",
250                 value    => $geo_handler,
251               };
252
253if ( $geo_handler eq "3" ) {
254    my $qu = "Which ellipsoid do you want to use? (eg 'Airy', 'WGS-84')";
255    my $ellipsoid;
256    if ( $skip_config ) {
257        $ellipsoid = $existing_config{ellipsoid} || "International";
258    } else {
259        my $def = $existing_config{ellipsoid} || "International";
260        $ellipsoid = Module::Build->prompt("\n".$qu, $def);
261        $ellipsoid =~ s/^\s*//;
262        $ellipsoid =~ s/\s*$//;
263    }
264    push @answers, {
265                     question => $qu,
266                     variable => "ellipsoid",
267                     value    => $ellipsoid,
268                   };
269}
270
271# Create a user-friendly config file from answers to prompts.
272open FILE, ">wiki.conf" or die "Can't open wiki.conf for writing: $!";
273foreach my $ans (@answers) {
274    print FILE "# $ans->{question}\n";
275    print FILE "$ans->{variable} = $ans->{value}\n\n";
276}
277close FILE or die "Can't close wiki.conf: $!";
278
279#####
280##### When updating the prereqs PLEASE REMEMBER to update PREREQUISITES.
281#####
282
283# Create the build object.
284my $build = OpenGuides::Build->new(
285    dist_name => "OpenGuides",
286    dist_version_from => "wiki.cgi",
287    license => "perl",
288    requires => {
289        'Algorithm::Diff'                 => '0.13', # for sdiff
290        'CGI'                             => '2.92', # avoid escapeHTML bug
291        'CGI::Carp'                       => 0,
292        'CGI::Cookie'                     => 0,
293        'CGI::Wiki'                       => '0.54',
294        'CGI::Wiki::Formatter::UseMod'    => '0.16', # macros
295        'CGI::Wiki::Plugin::Categoriser'  => 0,
296        'CGI::Wiki::Plugin::Diff'         => '0.07', # earlier buggy
297        'CGI::Wiki::Plugin::Locator::Grid'=> '0.02', # cope with sqlite 3
298        'CGI::Wiki::Plugin::RSS::ModWiki' => '0.06', # for fancy stuff
299        'CGI::Wiki::Plugin::RSS::Reader'  => '1.3',  # earlier versions don't support RSS 2.0
300        'Config::Tiny'                    => 0,
301        'Data::Dumper'                    => 0,
302        $drivers{$dbtype}                 => 0,
303        'File::Spec::Functions'           => 0,
304        'File::Temp'                      => 0,
305        'Geography::NationalGrid'         => 0,
306        'LWP::Simple'                     => 0,
307        'Parse::RecDescent'               => 0,
308        'Search::InvertedIndex'           => 0,
309        'Template'                        => 0,
310        'Test::MockObject'                => '0.07', # earlier doesn't use 'mock'
311        'Time::Piece'                     => 0,
312        'URI::Escape'                     => 0,
313        'XML::RSS'                        => 0,
314        },
315    build_requires => {
316        'Module::Build' => '0.18', # earlier doesn't install script files
317        },
318    recommends => {
319        'DBD::SQLite'         => 0, # for testing
320        'Test::HTML::Content' => 0, # for testing, oddly enough
321    },
322    dynamic_config => 1,
323    create_makefile_pl => "passthrough"
324);
325
326$build->add_to_cleanup( "t/indexes/" );
327$build->add_to_cleanup( "t/node.db" );
328
329# Tell OpenGuides::Build which additional scripts and templates to install.
330$build->{config}{__extra_scripts}     = 
331                      [ "wiki.conf", "preferences.cgi", "supersearch.cgi",
332                        "newpage.cgi" ];
333$build->{config}{__templates}         = [
334                      "backlink_results.tt",
335                      "banner.tt",
336                      "delete_confirm.tt",
337                      "delete_done.tt",
338                      "delete_password_wrong.tt",
339                      "differences.tt",
340                      "display_metadata.tt",
341                      "edit_conflict.tt",
342                      "edit_form.tt",
343                      "error.tt",
344                      "footer.tt",
345                      "header.tt",
346                      "home_node.tt",
347                      "navbar.tt",
348                      "newpage.tt",
349                      "node.tt",
350                      "node_history.tt",
351                      "openguides_information_boxes.tt",
352                      "preferences.tt",
353                      "rdf_index.tt",
354                      "recent_changes.tt",
355                      "search_results.tt",
356                      "site_index.tt",
357                      "supersearch.tt",
358                      "userstats.tt",
359                      "wanted_pages.tt"
360    ];
361
362# Finally write the build script.
363$build->create_build_script;
Note: See TracBrowser for help on using the repository browser.