| 1 | use strict; |
|---|
| 2 | use lib "lib"; |
|---|
| 3 | use Data::Dumper; |
|---|
| 4 | |
|---|
| 5 | eval { |
|---|
| 6 | require Config::Tiny; |
|---|
| 7 | |
|---|
| 8 | require OpenGuides::Build; |
|---|
| 9 | require OpenGuides::Config; |
|---|
| 10 | }; |
|---|
| 11 | |
|---|
| 12 | die "Problem loading OpenGuides module or a missing module\n\n$@.\n" if $@; |
|---|
| 13 | |
|---|
| 14 | print <<EOF; |
|---|
| 15 | |
|---|
| 16 | Beginning install process... if you already have an OpenGuides |
|---|
| 17 | configuration file and you don't want to have to type in all your config |
|---|
| 18 | parameters over again, abort this process now, copy that file to this |
|---|
| 19 | directory, and start again. |
|---|
| 20 | |
|---|
| 21 | EOF |
|---|
| 22 | |
|---|
| 23 | my $continue = Module::Build->y_n("Continue with install?", "y"); |
|---|
| 24 | exit 0 unless $continue; |
|---|
| 25 | |
|---|
| 26 | my $existing_config_file = 'wiki.conf'; |
|---|
| 27 | my $existing_config; |
|---|
| 28 | |
|---|
| 29 | if (-f $existing_config_file) { |
|---|
| 30 | $existing_config = OpenGuides::Config->new(file => $existing_config_file); |
|---|
| 31 | } else { |
|---|
| 32 | print <<EOF; |
|---|
| 33 | No existing configuration file found; assuming this is a new install. |
|---|
| 34 | See the message above if this isn't correct. |
|---|
| 35 | |
|---|
| 36 | EOF |
|---|
| 37 | $existing_config = OpenGuides::Config->new(); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | my %yn_vars = map { $_ => 1 } |
|---|
| 41 | qw(use_plucene enable_page_deletion navbar_on_home_page backlinks_in_title |
|---|
| 42 | moderation_requires_password enable_node_image enable_common_categories |
|---|
| 43 | enable_common_locales recent_changes_on_home_page |
|---|
| 44 | random_page_omits_locales random_page_omits_categories |
|---|
| 45 | content_above_navbar_in_html show_gmap_in_node_display |
|---|
| 46 | send_moderation_notifications); |
|---|
| 47 | |
|---|
| 48 | my $skip_config = Module::Build->y_n("Skip OpenGuides configuration?", "n"); |
|---|
| 49 | if ( $skip_config ) { |
|---|
| 50 | print <<EOF; |
|---|
| 51 | =========================================================================== |
|---|
| 52 | Skipping OpenGuides configuration - any configuration options previously |
|---|
| 53 | saved will be used instead. You may tweak your configuration now by |
|---|
| 54 | editing the 'wiki.conf' file produced by this script. |
|---|
| 55 | =========================================================================== |
|---|
| 56 | EOF |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | my @answers; |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | my $dbtype; |
|---|
| 63 | my $dbtype_qu = $existing_config->dbtype__qu; |
|---|
| 64 | if ( $skip_config ) { |
|---|
| 65 | $dbtype = $existing_config->dbtype; |
|---|
| 66 | } else { |
|---|
| 67 | until ( $dbtype ) { |
|---|
| 68 | my $def = $existing_config->dbtype; |
|---|
| 69 | $dbtype = Module::Build->prompt("\n$dbtype_qu", $def); |
|---|
| 70 | $dbtype = lc($dbtype); |
|---|
| 71 | $dbtype =~ s/^\s*//; |
|---|
| 72 | $dbtype =~ s/\s*$//; |
|---|
| 73 | unless ( $dbtype eq "postgres" or $dbtype eq "mysql" |
|---|
| 74 | or $dbtype eq "sqlite" ) { |
|---|
| 75 | undef $dbtype; |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | my %drivers = ( postgres => "DBD::Pg", |
|---|
| 82 | mysql => "DBD::mysql", |
|---|
| 83 | sqlite => "DBD::SQLite", |
|---|
| 84 | ); |
|---|
| 85 | eval "require $drivers{$dbtype}"; |
|---|
| 86 | warn "$drivers{$dbtype} is needed to run a $dbtype database" if $@; |
|---|
| 87 | |
|---|
| 88 | push @answers, { question => $dbtype_qu, |
|---|
| 89 | variable => "dbtype", |
|---|
| 90 | value => $dbtype }; |
|---|
| 91 | |
|---|
| 92 | my $install_directory; |
|---|
| 93 | my $use_plucene = 1; |
|---|
| 94 | my $centre_lat = ''; |
|---|
| 95 | foreach my $var ( qw( |
|---|
| 96 | dbname dbuser dbpass dbhost dbport script_name |
|---|
| 97 | install_directory template_path custom_template_path script_url |
|---|
| 98 | custom_lib_path use_plucene indexing_directory enable_page_deletion |
|---|
| 99 | admin_pass stylesheet_url site_name navbar_on_home_page |
|---|
| 100 | recent_changes_on_home_page random_page_omits_locales |
|---|
| 101 | random_page_omits_categories content_above_navbar_in_html home_name |
|---|
| 102 | site_desc default_city default_country contact_email default_language |
|---|
| 103 | formatting_rules_node backlinks_in_title gmaps_api_key centre_long |
|---|
| 104 | centre_lat show_gmap_in_node_display default_gmaps_zoom |
|---|
| 105 | default_gmaps_search_zoom force_wgs84 google_analytics_key |
|---|
| 106 | licence_name licence_url licence_info_url moderation_requires_password |
|---|
| 107 | enable_node_image enable_common_categories enable_common_locales |
|---|
| 108 | spam_detector_module static_path static_url send_moderation_notifications |
|---|
| 109 | ) ) { |
|---|
| 110 | my $q_method = $var . "__qu"; |
|---|
| 111 | my $qu = $existing_config->$q_method; |
|---|
| 112 | my $type = $yn_vars{$var} ? "y_n" : ""; |
|---|
| 113 | my $def = $existing_config->$var; |
|---|
| 114 | my $val = $def; |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | if ( $dbtype eq "sqlite" and $var eq "dbname" ) { |
|---|
| 118 | $qu = "what's the full filename of the SQLite database this site runs on?"; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | if ( $dbtype eq "sqlite" and |
|---|
| 122 | ( $var eq "dbuser" or $var eq "dbpass" or $var eq "dbhost" or |
|---|
| 123 | $var eq "dbport") |
|---|
| 124 | ) { |
|---|
| 125 | print "$var not relevant for SQLite... skipping...\n" |
|---|
| 126 | unless $skip_config; |
|---|
| 127 | push @answers, { question => $qu, |
|---|
| 128 | variable => $var, |
|---|
| 129 | value => "not-used" }; |
|---|
| 130 | next; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | if ( $var eq "use_plucene" and $existing_config->$var == 1) { |
|---|
| 136 | print "Skipping question about plucene\n" |
|---|
| 137 | unless $skip_config; |
|---|
| 138 | push @answers, { question => $qu, |
|---|
| 139 | variable => $var, |
|---|
| 140 | value => 1 }; |
|---|
| 141 | next; |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | if ( $var eq "template_path" && !defined $existing_config->$var ) { |
|---|
| 147 | $def = $install_directory; |
|---|
| 148 | $def .= "/" unless $def =~ m|/$|; |
|---|
| 149 | $def .= "templates"; |
|---|
| 150 | } |
|---|
| 151 | if ( $var eq "custom_template_path" && !defined $existing_config->$var ) { |
|---|
| 152 | $def = $install_directory; |
|---|
| 153 | $def .= "/" unless $def =~ m|/$|; |
|---|
| 154 | $def .= "custom-templates"; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | if ( $var eq 'centre_lat' && $centre_lat ) { |
|---|
| 159 | $val = $centre_lat; |
|---|
| 160 | next; |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | unless ( $skip_config ) { |
|---|
| 165 | if ( $type eq "y_n" ) { |
|---|
| 166 | |
|---|
| 167 | if ( $def =~ /^\d+$/ ) { |
|---|
| 168 | $def = $def ? "y" : "n"; |
|---|
| 169 | } |
|---|
| 170 | $val = Module::Build->y_n("\n$qu ", $def); |
|---|
| 171 | } else { |
|---|
| 172 | $val = Module::Build->prompt("\n$qu ", $def); |
|---|
| 173 | } |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | if ( $var eq 'centre_long' ) { |
|---|
| 179 | if ( $val =~ /ll=([-\d.]+),([-\d.]+)/ ) { |
|---|
| 180 | print "Got a Google Maps URL with centre long,lat: [$1, $2]\n"; |
|---|
| 181 | $val = $1; |
|---|
| 182 | $centre_lat = $2; |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | $install_directory = $val if $var eq "install_directory"; |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | $use_plucene = 1 if $var eq "use_plucene" and $val; |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | if ( $var eq "script_url" and $val !~ /\/$/ ) { |
|---|
| 195 | $val .= "/"; |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | push @answers, { question => $qu, |
|---|
| 199 | variable => $var, |
|---|
| 200 | value => $val }; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | my $geo_handler; |
|---|
| 205 | my $geo_handler_qu = "Distance calculation methods available are:" |
|---|
| 206 | . "\n 1) British National Grid" |
|---|
| 207 | . "\n 2) Irish National Grid" |
|---|
| 208 | . "\n 3) UTM ellipsoid" |
|---|
| 209 | . "\nWhich would you like to use?"; |
|---|
| 210 | |
|---|
| 211 | if ( $skip_config ) { |
|---|
| 212 | |
|---|
| 213 | $geo_handler = $existing_config->geo_handler; |
|---|
| 214 | } else { |
|---|
| 215 | my $choice; |
|---|
| 216 | until ( $choice ) { |
|---|
| 217 | my $def = $existing_config->geo_handler; |
|---|
| 218 | $choice = Module::Build->prompt("\n".$geo_handler_qu, $def); |
|---|
| 219 | $choice =~ s/^\s*//; |
|---|
| 220 | $choice =~ s/\s*$//; |
|---|
| 221 | unless ( $choice eq "1" or $choice eq "2" or $choice eq "3" ) { |
|---|
| 222 | undef $choice; |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | $geo_handler = $choice; |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | $geo_handler_qu =~ s/\n//gs; |
|---|
| 229 | push @answers, { |
|---|
| 230 | question => $geo_handler_qu, |
|---|
| 231 | variable => "geo_handler", |
|---|
| 232 | value => $geo_handler, |
|---|
| 233 | }; |
|---|
| 234 | |
|---|
| 235 | if ( $geo_handler eq "3" ) { |
|---|
| 236 | my $qu = $existing_config->ellipsoid__qu; |
|---|
| 237 | my $ellipsoid; |
|---|
| 238 | if ( $skip_config ) { |
|---|
| 239 | $ellipsoid = $existing_config->ellipsoid; |
|---|
| 240 | } else { |
|---|
| 241 | my $def = $existing_config->ellipsoid; |
|---|
| 242 | $ellipsoid = Module::Build->prompt("\n".$qu, $def); |
|---|
| 243 | $ellipsoid =~ s/^\s*//; |
|---|
| 244 | $ellipsoid =~ s/\s*$//; |
|---|
| 245 | } |
|---|
| 246 | push @answers, { |
|---|
| 247 | question => $qu, |
|---|
| 248 | variable => "ellipsoid", |
|---|
| 249 | value => $ellipsoid, |
|---|
| 250 | }; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | open FILE, ">wiki.conf" or die "Can't open wiki.conf for writing: $!"; |
|---|
| 255 | foreach my $ans (@answers) { |
|---|
| 256 | print FILE "# $ans->{question}\n"; |
|---|
| 257 | print FILE "$ans->{variable} = $ans->{value}\n\n"; |
|---|
| 258 | } |
|---|
| 259 | close FILE or die "Can't close wiki.conf: $!"; |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | my $search_module = $use_plucene ? "Plucene" : "Search::InvertedIndex"; |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | my $build = OpenGuides::Build->new( |
|---|
| 271 | sign => 1, |
|---|
| 272 | dist_name => "OpenGuides", |
|---|
| 273 | module_name => "OpenGuides", |
|---|
| 274 | dist_version_from => "wiki.cgi", |
|---|
| 275 | license => "perl", |
|---|
| 276 | requires => { |
|---|
| 277 | 'Algorithm::Diff' => '0.13', |
|---|
| 278 | 'CGI' => '2.92', |
|---|
| 279 | 'CGI::Carp' => 0, |
|---|
| 280 | 'CGI::Cookie' => 0, |
|---|
| 281 | 'Wiki::Toolkit' => '0.74', |
|---|
| 282 | 'Wiki::Toolkit::Feed::Atom' => 0, |
|---|
| 283 | 'Wiki::Toolkit::Feed::RSS' => 0, |
|---|
| 284 | 'Wiki::Toolkit::Formatter::UseMod' => 0, |
|---|
| 285 | 'Wiki::Toolkit::Plugin::Categoriser' => 0, |
|---|
| 286 | 'Wiki::Toolkit::Plugin::Diff' => 0, |
|---|
| 287 | 'Wiki::Toolkit::Plugin::Locator::Grid'=> 0, |
|---|
| 288 | 'Wiki::Toolkit::Plugin::RSS::Reader' => 0, |
|---|
| 289 | 'Class::Accessor' => 0, |
|---|
| 290 | 'Config::Tiny' => 0, |
|---|
| 291 | 'Data::Dumper' => 0, |
|---|
| 292 | $drivers{$dbtype} => 0, |
|---|
| 293 | 'File::Spec::Functions' => 0, |
|---|
| 294 | 'File::Temp' => 0, |
|---|
| 295 | 'Geography::NationalGrid' => 0, |
|---|
| 296 | 'HTML::Entities' => 0, |
|---|
| 297 | 'LWP::Simple' => 0, |
|---|
| 298 | 'MIME::Lite' => 0, |
|---|
| 299 | 'Parse::RecDescent' => 0, |
|---|
| 300 | $search_module => 0, |
|---|
| 301 | 'POSIX' => 0, |
|---|
| 302 | 'Template' => '2.15', |
|---|
| 303 | 'Time::Piece' => 0, |
|---|
| 304 | 'URI::Escape' => 0, |
|---|
| 305 | 'XML::RSS' => 0, |
|---|
| 306 | }, |
|---|
| 307 | build_requires => { |
|---|
| 308 | 'Module::Build' => '0.26', |
|---|
| 309 | }, |
|---|
| 310 | recommends => { |
|---|
| 311 | 'DBD::SQLite' => 0, |
|---|
| 312 | 'Test::HTML::Content' => 0, |
|---|
| 313 | 'Wiki::Toolkit::Plugin::Ping' => 0, |
|---|
| 314 | 'Geo::HelmertTransform' => 0, |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | }, |
|---|
| 318 | dynamic_config => 1, |
|---|
| 319 | create_makefile_pl => "passthrough" |
|---|
| 320 | ); |
|---|
| 321 | |
|---|
| 322 | $build->add_to_cleanup( "t/indexes/" ); |
|---|
| 323 | $build->add_to_cleanup( "t/node.db" ); |
|---|
| 324 | $build->add_to_cleanup( "t/templates/tmp/" ); |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | $build->config_data( __extra_scripts => |
|---|
| 328 | [ "wiki.conf", "preferences.cgi", "search.cgi", |
|---|
| 329 | "newpage.cgi" ] ); |
|---|
| 330 | $build->config_data( __templates => [ |
|---|
| 331 | "admin_home.tt", |
|---|
| 332 | "admin_revert_user.tt", |
|---|
| 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_form.tt", |
|---|
| 341 | "edit_form_actions.tt", |
|---|
| 342 | "error.tt", |
|---|
| 343 | "footer.tt", |
|---|
| 344 | "header.tt", |
|---|
| 345 | "home_node.tt", |
|---|
| 346 | "map_index.tt", |
|---|
| 347 | "missing_metadata.tt", |
|---|
| 348 | "moderate_confirm.tt", |
|---|
| 349 | "moderate_password_wrong.tt", |
|---|
| 350 | "navbar.tt", |
|---|
| 351 | "navbar_categories.tt", |
|---|
| 352 | "navbar_locales.tt", |
|---|
| 353 | "navbar_help.tt", |
|---|
| 354 | "navbar_home_link.tt", |
|---|
| 355 | "navbar_options.tt", |
|---|
| 356 | "navbar_revision_info.tt", |
|---|
| 357 | "navbar_search.tt", |
|---|
| 358 | "navbar_this_page.tt", |
|---|
| 359 | "navbar_tools.tt", |
|---|
| 360 | "needing_moderation.tt", |
|---|
| 361 | "newpage.tt", |
|---|
| 362 | "node.tt", |
|---|
| 363 | "node_history.tt", |
|---|
| 364 | "node_image_fields.tt", |
|---|
| 365 | "node_photo_notes.tt", |
|---|
| 366 | "node_rdf.tt", |
|---|
| 367 | "openguides_information_boxes.tt", |
|---|
| 368 | "preferences.tt", |
|---|
| 369 | "random_page_failure.tt", |
|---|
| 370 | "rdf_index.tt", |
|---|
| 371 | "recent_changes.tt", |
|---|
| 372 | "search_results.tt", |
|---|
| 373 | "site_index.tt", |
|---|
| 374 | "search.tt", |
|---|
| 375 | "spam_detected.tt", |
|---|
| 376 | "userstats.tt", |
|---|
| 377 | "wanted_pages.tt" |
|---|
| 378 | ] ); |
|---|
| 379 | |
|---|
| 380 | $build->config_data( __static_files => [ |
|---|
| 381 | |
|---|
| 382 | ] ); |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | $build->create_build_script; |
|---|