source: trunk/Build.PL @ 490

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

RSS feeds for contributors, locales and categories.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 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 to use Plucene for searching? (recommended, but see Changes file before saying yes to this)",
41  variable => "use_plucene",
42  default  => "n",
43  type     => "y_n"
44  },
45{ question => "What directory can I use to store indexes in for searching? "
46            . "***NOTE*** This directory must exist and be writeable by the "
47            . "user that your script will run as.  See README for more on this.",
48  variable => "indexing_directory",
49  default  => "/usr/lib/cgi-bin/openguides/indexes/"
50  },
51{ question => "Do you want to enable page deletion?",
52  variable => "enable_page_deletion",
53  default  => "n",
54  type     => "y_n"
55  },
56{ question => "Please specify a password for the site admin:",
57  variable => "admin_pass",
58  default  => "Change this!"
59  },
60{ question => "What's the URL of the site's stylesheet?",
61  variable => "stylesheet_url"
62  },
63{ question => "What's the site called? (should be unique)",
64  variable => "site_name",
65  default  => "My OpenGuides Site"
66  },
67{ question => "Do you want the navigation bar included on the home page?",
68  variable => "navbar_on_home_page",
69  default  => "y",
70  type     => "y_n"
71  },
72{ question => "What should the home page of the wiki be called?",
73  variable => "home_name",
74  default  => "Home"
75  },
76{ question => "How would you describe the site?",
77  variable => "site_desc",
78  default  => "A guide to [my city]"
79  },
80{ question => "What city is the site based in?",
81  variable => "default_city",
82  default  => "London"
83  },
84{ question => "What country is the site based in?",
85  variable => "default_country",
86  default  => "United Kingdom"
87  },
88{ question => "What language will the site be in? (Please give an ISO language code.)",
89  variable => "default_language",
90  default  => "en"
91  },
92{ question => "Contact email address for the site administrator?",
93  variable => "contact_email"
94  },
95{ question => "What's the name of the node to use for the text formatting rules link?",
96  variable => "formatting_rules_node",
97  default  => "Text Formatting Examples"
98  },
99);
100
101print <<EOF;
102
103Beginning install process... if you already have an OpenGuides
104configuration file and you don't want to have to type in all your config
105parameters over again, abort this process now, copy that file to this
106directory, and start again.
107
108EOF
109
110my $continue = Module::Build->y_n("Continue with install?", "y");
111exit 0 unless $continue;
112
113my $skip_config = Module::Build->y_n("Skip OpenGuides configuration?", "n");
114if ( $skip_config ) {
115    print <<EOF;
116===========================================================================
117Skipping OpenGuides configuration - any configuration options previously
118saved will be used instead.  You may tweak your configuration now by
119editing the 'wiki.conf' file produced by this script.
120===========================================================================
121EOF
122}
123
124my @answers;
125
126# It is an ancient Configurer, and he chooseth one of three.
127my $dbtype;
128my $dbtype_qu = "what type of database do you want the site to run on?  postgres/mysql/sqlite";
129if ( $skip_config ) {
130    $dbtype = $existing_config{dbtype} || "postgres";
131} else {
132    until ( $dbtype ) {
133        my $def = $existing_config{dbtype} || "postgres";
134        $dbtype = Module::Build->prompt("\n$dbtype_qu", $def);
135        $dbtype = lc($dbtype);
136        $dbtype =~ s/^\s*//;
137        $dbtype =~ s/\s*$//;
138        unless ( $dbtype eq "postgres" or $dbtype eq "mysql"
139                 or $dbtype eq "sqlite" ) {
140            undef $dbtype;
141        }
142    }
143}
144
145# Check they have the relevant DBD driver installed.
146my %drivers = ( postgres => "DBD::Pg",
147                mysql    => "DBD::mysql",
148                sqlite   => "DBD::SQLite",
149              );
150eval "require $drivers{$dbtype}";
151die "$drivers{$dbtype} is needed to run a $dbtype database" if $@;
152
153push @answers, { question => $dbtype_qu,
154                 variable => "dbtype",
155                 value    => $dbtype };
156
157foreach my $qset (@questions) {
158    my $qu  = $qset->{question};
159    my $type = $qset->{type} || "";
160    my $var = $qset->{variable};
161    my $def = defined $existing_config{$var} ? $existing_config{$var}
162                                             : $qset->{default};
163    my $val = $def;
164
165    if ( $dbtype eq "sqlite" and $var eq "dbname" ) {
166        $qu = "what's the full filename of the SQLite database this site runs on?";
167    }
168
169    if ( $dbtype eq "sqlite" and
170         ( $var eq "dbuser" or $var eq "dbpass" or $var eq "dbhost" )
171       ) {
172        print "$var not relevant for SQLite... skipping...\n";
173        push @answers, { question => $qu,
174                         variable => $var,
175                         value    => "not-used" };
176        next;
177    }
178
179    unless ( $skip_config ) {
180        if ( $type eq "y_n" ) {
181            # may be stored as true/false integer value
182            if ( $def =~ /^\d+$/ ) {
183                $def = $def ? "y" : "n";
184            }
185            $val = Module::Build->y_n("\n$qu ", $def);
186        } else {
187            $val = Module::Build->prompt("\n$qu ", $def);
188        }
189    }
190
191    # Make sure that script_url ends in a /
192    if ( $var eq "script_url" and $val !~ /\/$/ ) {
193        $val .= "/";
194    }
195
196    push @answers, { question => $qu,
197                     variable => $var,
198                     value    => $val };
199
200    if ( $var eq "install_directory" ) {
201        push @answers, {
202            question => "what directory should I install the templates in?",
203            variable => "template_path",
204            value    => $val . "/templates" };
205    }
206}
207
208# Create a user-friendly config file from answers to prompts.
209open FILE, ">wiki.conf" or die "Can't open wiki.conf for writing: $!";
210foreach my $ans (@answers) {
211    print FILE "# $ans->{question}\n";
212    print FILE "$ans->{variable} = $ans->{value}\n\n";
213}
214close FILE or die "Can't close wiki.conf: $!";
215
216#####
217##### When updating the prereqs PLEASE REMEMBER to update PREREQUISITES.
218#####
219
220# Create the build object.
221my $build = OpenGuides::Build->new(
222    dist_name => "OpenGuides",
223    dist_version_from => "wiki.cgi",
224    license => "perl",
225    requires => {
226        'Algorithm::Diff'                 => '0.13', # for sdiff
227        'CGI'                             => '2.92', # avoid escapeHTML bug
228        'CGI::Carp'                       => 0,
229        'CGI::Cookie'                     => 0,
230        'CGI::Wiki'                       => '0.54',
231        'CGI::Wiki::Formatter::UseMod'    => '0.09',
232        'CGI::Wiki::Plugin::Categoriser'  => 0,
233        'CGI::Wiki::Plugin::Diff'         => '0.07', # earlier buggy
234        'CGI::Wiki::Plugin::GeoCache'     => 0,
235        'CGI::Wiki::Plugin::Locator::UK'  => '0.09',
236        'CGI::Wiki::Plugin::RSS::ModWiki' => '0.06', # for fancy stuff
237        'CGI::Wiki::Plugin::RSS::Reader'  => '1.3',  # earlier versions don't support RSS 2.0
238        'Config::Tiny'                    => 0,
239        'Data::Dumper'                    => 0,
240        $drivers{$dbtype}                 => 0,
241        'File::Spec::Functions'           => 0,
242        'Geography::NationalGrid'         => 0,
243        'LWP::Simple'                     => 0,
244        'Parse::RecDescent'               => 0,
245        'Search::InvertedIndex'           => 0,
246        'Template'                        => 0,
247        'Test::MockObject'                => '0.07', # earlier doesn't use 'mock'
248        'Time::Piece'                     => 0,
249        'URI::Escape'                     => 0,
250        'XML::RSS'                        => 0,
251        },
252    build_requires => {
253        'Module::Build' => '0.18', # earlier doesn't install script files
254        },
255    dynamic_config => 1,
256    create_makefile_pl => "passthrough"
257);
258
259$build->add_to_cleanup( "t/indexes/" );
260$build->add_to_cleanup( "t/node.db" );
261
262# Tell OpenGuides::Build which additional scripts and templates to install.
263$build->{config}{__extra_scripts}     = 
264                      [ "wiki.conf", "preferences.cgi", "supersearch.cgi",
265                        "newpage.cgi" ];
266$build->{config}{__templates}         = [
267                      "backlink_results.tt",
268                      "banner.tt",
269                      "delete_confirm.tt",
270                      "delete_done.tt",
271                      "delete_password_wrong.tt",
272                      "differences.tt",
273                      "display_categories.tt",
274                      "display_metadata.tt",
275                      "edit_conflict.tt",
276                      "edit_form.tt",
277                      "error.tt",
278                      "footer.tt",
279                      "header.tt",
280                      "home_node.tt",
281                      "navbar.tt",
282                      "newpage.tt",
283                      "node.tt",
284                      "node_history.tt",
285                      "openguides_information_boxes.tt",
286                      "preferences.tt",
287                      "rdf_index.tt",
288                      "recent_changes.tt",
289                      "search_results.tt",
290                      "site_index.tt",
291                      "supersearch.tt",
292                      "userstats.tt",
293                      "wanted_pages.tt"
294    ];
295
296# Finally write the build script.
297$build->create_build_script;
Note: See TracBrowser for help on using the repository browser.