source: trunk/Build.PL @ 452

Last change on this file since 452 was 452, checked in by kake, 18 years ago

Require CGI.pm 2.92 to avoid escapeHTML bug.

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