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