| 1 | use strict; |
|---|
| 2 | use lib "lib"; |
|---|
| 3 | use OpenGuides::Build; |
|---|
| 4 | use Data::Dumper; |
|---|
| 5 | |
|---|
| 6 | eval "use Config::Tiny"; |
|---|
| 7 | die "Config::Tiny is required to configure this application.\n" if $@; |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | my $read_config = Config::Tiny->read('wiki.conf'); |
|---|
| 13 | my %existing_config = $read_config ? %{ $read_config->{_} } : (); |
|---|
| 14 | |
|---|
| 15 | my @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 | |
|---|
| 110 | print <<EOF; |
|---|
| 111 | |
|---|
| 112 | Beginning install process... if you already have an OpenGuides |
|---|
| 113 | configuration file and you don't want to have to type in all your config |
|---|
| 114 | parameters over again, abort this process now, copy that file to this |
|---|
| 115 | directory, and start again. |
|---|
| 116 | |
|---|
| 117 | EOF |
|---|
| 118 | |
|---|
| 119 | my $continue = Module::Build->y_n("Continue with install?", "y"); |
|---|
| 120 | exit 0 unless $continue; |
|---|
| 121 | |
|---|
| 122 | my $skip_config = Module::Build->y_n("Skip OpenGuides configuration?", "n"); |
|---|
| 123 | if ( $skip_config ) { |
|---|
| 124 | print <<EOF; |
|---|
| 125 | =========================================================================== |
|---|
| 126 | Skipping OpenGuides configuration - any configuration options previously |
|---|
| 127 | saved will be used instead. You may tweak your configuration now by |
|---|
| 128 | editing the 'wiki.conf' file produced by this script. |
|---|
| 129 | =========================================================================== |
|---|
| 130 | EOF |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | my @answers; |
|---|
| 134 | |
|---|
| 135 | # It is an ancient Configurer, and he chooseth one of three. |
|---|
| 136 | my $dbtype; |
|---|
| 137 | my $dbtype_qu = "what type of database do you want the site to run on? postgres/mysql/sqlite"; |
|---|
| 138 | if ( $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. |
|---|
| 155 | my %drivers = ( postgres => "DBD::Pg", |
|---|
| 156 | mysql => "DBD::mysql", |
|---|
| 157 | sqlite => "DBD::SQLite", |
|---|
| 158 | ); |
|---|
| 159 | eval "require $drivers{$dbtype}"; |
|---|
| 160 | die "$drivers{$dbtype} is needed to run a $dbtype database" if $@; |
|---|
| 161 | |
|---|
| 162 | push @answers, { question => $dbtype_qu, |
|---|
| 163 | variable => "dbtype", |
|---|
| 164 | value => $dbtype }; |
|---|
| 165 | |
|---|
| 166 | foreach 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. |
|---|
| 222 | my $geo_handler; |
|---|
| 223 | my $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 | |
|---|
| 229 | if ( $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; |
|---|
| 247 | push @answers, { |
|---|
| 248 | question => $geo_handler_qu, |
|---|
| 249 | variable => "geo_handler", |
|---|
| 250 | value => $geo_handler, |
|---|
| 251 | }; |
|---|
| 252 | |
|---|
| 253 | if ( $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. |
|---|
| 272 | open FILE, ">wiki.conf" or die "Can't open wiki.conf for writing: $!"; |
|---|
| 273 | foreach my $ans (@answers) { |
|---|
| 274 | print FILE "# $ans->{question}\n"; |
|---|
| 275 | print FILE "$ans->{variable} = $ans->{value}\n\n"; |
|---|
| 276 | } |
|---|
| 277 | close 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. |
|---|
| 284 | my $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, |
|---|
| 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 | 'Geography::NationalGrid' => 0, |
|---|
| 305 | 'LWP::Simple' => 0, |
|---|
| 306 | 'Parse::RecDescent' => 0, |
|---|
| 307 | 'Search::InvertedIndex' => 0, |
|---|
| 308 | 'Template' => 0, |
|---|
| 309 | 'Test::MockObject' => '0.07', # earlier doesn't use 'mock' |
|---|
| 310 | 'Time::Piece' => 0, |
|---|
| 311 | 'URI::Escape' => 0, |
|---|
| 312 | 'XML::RSS' => 0, |
|---|
| 313 | }, |
|---|
| 314 | build_requires => { |
|---|
| 315 | 'Module::Build' => '0.18', # earlier doesn't install script files |
|---|
| 316 | }, |
|---|
| 317 | recommends => { |
|---|
| 318 | 'DBD::SQLite' => 0, # for testing |
|---|
| 319 | 'Test::HTML::Content' => 0, # for testing, oddly enough |
|---|
| 320 | }, |
|---|
| 321 | dynamic_config => 1, |
|---|
| 322 | create_makefile_pl => "passthrough" |
|---|
| 323 | ); |
|---|
| 324 | |
|---|
| 325 | $build->add_to_cleanup( "t/indexes/" ); |
|---|
| 326 | $build->add_to_cleanup( "t/node.db" ); |
|---|
| 327 | |
|---|
| 328 | # Tell OpenGuides::Build which additional scripts and templates to install. |
|---|
| 329 | $build->{config}{__extra_scripts} = |
|---|
| 330 | [ "wiki.conf", "preferences.cgi", "supersearch.cgi", |
|---|
| 331 | "newpage.cgi" ]; |
|---|
| 332 | $build->{config}{__templates} = [ |
|---|
| 333 | "backlink_results.tt", |
|---|
| 334 | "banner.tt", |
|---|
| 335 | "delete_confirm.tt", |
|---|
| 336 | "delete_done.tt", |
|---|
| 337 | "delete_password_wrong.tt", |
|---|
| 338 | "differences.tt", |
|---|
| 339 | "display_metadata.tt", |
|---|
| 340 | "edit_conflict.tt", |
|---|
| 341 | "edit_form.tt", |
|---|
| 342 | "error.tt", |
|---|
| 343 | "footer.tt", |
|---|
| 344 | "header.tt", |
|---|
| 345 | "home_node.tt", |
|---|
| 346 | "navbar.tt", |
|---|
| 347 | "newpage.tt", |
|---|
| 348 | "node.tt", |
|---|
| 349 | "node_history.tt", |
|---|
| 350 | "openguides_information_boxes.tt", |
|---|
| 351 | "preferences.tt", |
|---|
| 352 | "rdf_index.tt", |
|---|
| 353 | "recent_changes.tt", |
|---|
| 354 | "search_results.tt", |
|---|
| 355 | "site_index.tt", |
|---|
| 356 | "supersearch.tt", |
|---|
| 357 | "userstats.tt", |
|---|
| 358 | "wanted_pages.tt" |
|---|
| 359 | ]; |
|---|
| 360 | |
|---|
| 361 | # Finally write the build script. |
|---|
| 362 | $build->create_build_script; |
|---|