source: trunk/Build.PL @ 501

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

Added option of munging in custom lib paths on install.

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