Changeset 1158
- Timestamp:
- 05/01/08 20:53:01 (2 months ago)
- Files:
-
- branches/new-install-process/Build.PL (modified) (6 diffs)
- branches/new-install-process/MANIFEST (modified) (3 diffs)
- branches/new-install-process/bin (added)
- branches/new-install-process/bin/openguides-install (added)
- branches/new-install-process/bin/openguides-newpage-script (added)
- branches/new-install-process/bin/openguides-preferences-script (added)
- branches/new-install-process/bin/openguides-search-script (added)
- branches/new-install-process/bin/openguides-wiki-script (added)
- branches/new-install-process/lib/OpenGuides/Config.pm (modified) (4 diffs)
- branches/new-install-process/newpage.cgi (deleted)
- branches/new-install-process/preferences.cgi (deleted)
- branches/new-install-process/search.cgi (deleted)
- branches/new-install-process/wiki.cgi (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/new-install-process/Build.PL
r1156 r1158 1 use File::Copy; 2 use File::Spec; 3 use Module::Build; 1 4 use strict; 2 use lib "lib";3 use Data::Dumper;4 use Getopt::Long;5 5 6 eval { 7 require Config::Tiny; 8 # OpenGuides::Build and OpenGuides::Config both use Config::Tiny. 9 require OpenGuides::Build; 10 require OpenGuides::Config; 11 }; 6 # This magically subclasses Module::Build. We override the install action 7 # to install the template files for us. 8 my $class = Module::Build->subclass( 9 code => q{ 10 sub ACTION_install { 11 my $self = shift; 12 my $ret = $self->SUPER::ACTION_install(@_); 12 13 13 die "Problem loading OpenGuides module or a missing module\n\n$@.\n" if $@; 14 # Slightly hacky. We require one of the modules that we just installed. 15 # then, we pull its path out of %INC, strip off the filename, and 16 # install the templates there. Well, they have to go _somewhere_, and 17 # perl doesn't have a good place for this stuff otherwise. 14 18 15 my $force; 19 require OpenGuides or die; 20 my (undef, $path, undef) = File::Spec->splitpath($INC{'OpenGuides.pm'}); 16 21 17 GetOptions('force' => \$force); 22 mkdir( File::Spec->catfile( $path, "OpenGuides" ) ); 23 die "Can't make template install folder: $!\n" unless (-d File::Spec->catfile( $path, "OpenGuides" ) ); 18 24 19 unless ($force) { 20 print <<EOF;25 mkdir( File::Spec->catfile( $path, "OpenGuides", "templates" ) ); 26 die "Can't make template install folder: $!\n" unless (-d File::Spec->catfile( $path, "OpenGuides", "templates" ) ); 21 27 22 Beginning install process... if you already have an OpenGuides 23 configuration file and you don't want to have to type in all your config 24 parameters over again, abort this process now, copy that file to this 25 directory, and start again. 28 print "Installing templates to $path/OpenGuides/templates\n"; 29 opendir TEMPLATES, "templates" or die "Can't open template source folder: $!\n"; 30 for (grep { /\.(tt)$/ } readdir(TEMPLATES)) { 31 print " installing template $_\n"; 32 File::Copy::copy( 33 File::Spec->catfile('templates', $_), 34 File::Spec->catfile( $path, "OpenGuides", "templates", $_ ) 35 ) or die "Error copying $_: $!\n";; 36 } 37 closedir(TEMPLATES); 26 38 27 EOF 28 29 my $continue = Module::Build->y_n("Continue with install?", "y"); 30 exit 0 unless $continue; 31 } 32 33 my $existing_config_file = 'wiki.conf'; 34 my $existing_config; 35 36 if (-f $existing_config_file) { 37 $existing_config = OpenGuides::Config->new(file => $existing_config_file); 38 } else { 39 print <<EOF; 40 No existing configuration file found; assuming this is a new install. 41 See the message above if this isn't correct. 42 43 EOF 44 $existing_config = OpenGuides::Config->new(); 45 } 46 47 my %yn_vars = map { $_ => 1 } 48 qw(use_plucene enable_page_deletion navbar_on_home_page backlinks_in_title 49 moderation_requires_password enable_node_image enable_common_categories 50 enable_common_locales recent_changes_on_home_page 51 random_page_omits_locales random_page_omits_categories 52 content_above_navbar_in_html show_gmap_in_node_display force_wgs84 53 send_moderation_notifications); 54 55 my $skip_config = $force ? 'y' : Module::Build->y_n("Skip OpenGuides configuration?", "n"); 56 if ( $skip_config ) { 57 print <<EOF; 58 =========================================================================== 59 Skipping OpenGuides configuration - any configuration options previously 60 saved will be used instead. You may tweak your configuration now by 61 editing the 'wiki.conf' file produced by this script. 62 =========================================================================== 63 EOF 64 } 65 66 my @answers; 67 68 # It is an ancient Configurer, and he chooseth one of three. 69 my $dbtype; 70 my $dbtype_qu = $existing_config->dbtype__qu; 71 if ( $skip_config ) { 72 $dbtype = $existing_config->dbtype; 73 } else { 74 until ( $dbtype ) { 75 my $def = $existing_config->dbtype; 76 $dbtype = Module::Build->prompt("\n$dbtype_qu", $def); 77 $dbtype = lc($dbtype); 78 $dbtype =~ s/^\s*//; 79 $dbtype =~ s/\s*$//; 80 unless ( $dbtype eq "postgres" or $dbtype eq "mysql" 81 or $dbtype eq "sqlite" ) { 82 undef $dbtype; 83 } 39 return $ret; 84 40 } 85 } 86 87 # Check they have the relevant DBD driver installed. 88 my %drivers = ( postgres => "DBD::Pg", 89 mysql => "DBD::mysql", 90 sqlite => "DBD::SQLite", 91 ); 92 eval "require $drivers{$dbtype}"; 93 warn "$drivers{$dbtype} is needed to run a $dbtype database" if $@; 94 95 push @answers, { question => $dbtype_qu, 96 variable => "dbtype", 97 value => $dbtype }; 98 99 my $install_directory; # used to suggest template paths 100 my $use_plucene = 1; # keep track of this so we know what to put in prereqs 101 my $centre_lat = ''; # contains centre lat derived from Google Maps URL 102 foreach my $var ( qw( 103 dbname dbuser dbpass dbhost dbport script_name 104 install_directory template_path custom_template_path script_url 105 custom_lib_path use_plucene indexing_directory enable_page_deletion 106 admin_pass stylesheet_url site_name navbar_on_home_page 107 recent_changes_on_home_page random_page_omits_locales 108 random_page_omits_categories content_above_navbar_in_html home_name 109 site_desc default_city default_country contact_email default_language 110 formatting_rules_node backlinks_in_title gmaps_api_key centre_long 111 centre_lat show_gmap_in_node_display default_gmaps_zoom 112 default_gmaps_search_zoom force_wgs84 google_analytics_key 113 licence_name licence_url licence_info_url moderation_requires_password 114 enable_node_image enable_common_categories enable_common_locales 115 spam_detector_module host_checker_module static_path static_url 116 send_moderation_notifications 117 ) ) { 118 my $q_method = $var . "__qu"; 119 my $qu = $existing_config->$q_method; 120 my $type = $yn_vars{$var} ? "y_n" : ""; 121 my $def = $existing_config->$var; 122 my $val = $def; 123 124 # Override dbname question for SQLite only. 125 if ( $dbtype eq "sqlite" and $var eq "dbname" ) { 126 $qu = "what's the full filename of the SQLite database this site runs on?"; 127 } 128 129 if ( $dbtype eq "sqlite" and 130 ( $var eq "dbuser" or $var eq "dbpass" or $var eq "dbhost" or 131 $var eq "dbport") 132 ) { 133 print "$var not relevant for SQLite... skipping...\n" 134 unless $skip_config; 135 push @answers, { question => $qu, 136 variable => $var, 137 value => "not-used" }; 138 next; 139 } 140 141 # We don't ask this for new installs as Search::InvertedIndex is 142 # deprecated 143 if ( $var eq "use_plucene" and $existing_config->$var == 1) { 144 print "Skipping question about plucene\n" 145 unless $skip_config; 146 push @answers, { question => $qu, 147 variable => $var, 148 value => 1 }; 149 next; 150 } 151 152 # Make sensible suggestions for template paths if we don't already 153 # have them stored. Not really a default, but a useful hint/shortcut. 154 if ( $var eq "template_path" && !defined $existing_config->$var ) { 155 $def = $install_directory; 156 $def .= "/" unless $def =~ m|/$|; 157 $def .= "templates"; 158 } 159 if ( $var eq "custom_template_path" && !defined $existing_config->$var ) { 160 $def = $install_directory; 161 $def .= "/" unless $def =~ m|/$|; 162 $def .= "custom-templates"; 163 } 164 165 # If a Google Maps URL was provided last time we know the centre_lat 166 if ( $var eq 'centre_lat' && $centre_lat ) { 167 $val = $centre_lat; 168 next; 169 } 170 171 # Here is where we actually ask the questions. 172 unless ( $skip_config ) { 173 if ( $type eq "y_n" ) { 174 # may be stored as true/false integer value 175 if ( $def =~ /^\d+$/ ) { 176 $def = $def ? "y" : "n"; 177 } 178 $val = Module::Build->y_n("\n$qu ", $def); 179 } else { 180 $val = Module::Build->prompt("\n$qu ", $def); 181 } 182 } 183 184 # Allow user to use a Google Maps URL rather than enter lat/long by hand. 185 # We assume centre_long is being asked for first; ensure so in big list above. 186 if ( $var eq 'centre_long' ) { 187 if ( $val =~ /ll=([-\d.]+),([-\d.]+)/ ) { 188 print "Got a Google Maps URL with centre long,lat: [$1, $2]\n"; 189 $val = $1; 190 $centre_lat = $2; 191 } 192 } 193 194 # Store install_directory so we can use it to suggest template paths. 195 $install_directory = $val if $var eq "install_directory"; 196 197 # Keep track of chosen search method so we know what to put in prereqs. 198 # From Module::Build docs: ->y_n returns a Perl boolean true or false. 199 $use_plucene = 1 if $var eq "use_plucene" and $val; 200 201 # Make sure that script_url ends in a / 202 if ( $var eq "script_url" and $val !~ /\/$/ ) { 203 $val .= "/"; 204 } 205 206 push @answers, { question => $qu, 207 variable => $var, 208 value => $val }; 209 } 210 211 # Now deal with the geo stuff. 212 my $geo_handler; 213 my $geo_handler_qu = "Distance calculation methods available are:" 214 . "\n 1) British National Grid" 215 . "\n 2) Irish National Grid" 216 . "\n 3) UTM ellipsoid" 217 . "\nWhich would you like to use?"; 218 219 if ( $skip_config ) { 220 # We default to GB National Grid for historical reasons. 221 $geo_handler = $existing_config->geo_handler; 222 } else { 223 my $choice; 224 until ( $choice ) { 225 my $def = $existing_config->geo_handler; 226 $choice = Module::Build->prompt("\n".$geo_handler_qu, $def); 227 $choice =~ s/^\s*//; 228 $choice =~ s/\s*$//; 229 unless ( $choice eq "1" or $choice eq "2" or $choice eq "3" ) { 230 undef $choice; 231 } 232 } 233 $geo_handler = $choice; 234 } 235 236 $geo_handler_qu =~ s/\n//gs; 237 push @answers, { 238 question => $geo_handler_qu, 239 variable => "geo_handler", 240 value => $geo_handler, 241 }; 242 243 if ( $geo_handler eq "3" ) { 244 my $qu = $existing_config->ellipsoid__qu; 245 my $ellipsoid; 246 if ( $skip_config ) { 247 $ellipsoid = $existing_config->ellipsoid; 248 } else { 249 my $def = $existing_config->ellipsoid; 250 $ellipsoid = Module::Build->prompt("\n".$qu, $def); 251 $ellipsoid =~ s/^\s*//; 252 $ellipsoid =~ s/\s*$//; 253 } 254 push @answers, { 255 question => $qu, 256 variable => "ellipsoid", 257 value => $ellipsoid, 258 }; 259 } 260 261 # Create a user-friendly config file from answers to prompts. 262 open FILE, ">wiki.conf" or die "Can't open wiki.conf for writing: $!"; 263 foreach my $ans (@answers) { 264 print FILE "# $ans->{question}\n"; 265 print FILE "$ans->{variable} = $ans->{value}\n\n"; 266 } 267 close FILE or die "Can't close wiki.conf: $!"; 41 }, 42 ); 268 43 269 44 ##### … … 271 46 ##### 272 47 273 # We currently only support Plucene for new installs, but may support274 # others in future275 my $search_module = $use_plucene ? "Plucene" : "Search::InvertedIndex";276 277 48 # Create the build object. 278 my $build = OpenGuides::Build->new(49 my $build = $class->new( 279 50 sign => 1, 280 51 dist_name => "OpenGuides", 281 52 module_name => "OpenGuides", 282 dist_version_from => " wiki.cgi",53 dist_version_from => "lib/OpenGuides.pm", 283 54 license => "perl", 284 55 requires => { … … 298 69 'Config::Tiny' => 0, 299 70 'Data::Dumper' => 0, 300 $drivers{$dbtype} => 0,301 71 'File::Spec::Functions' => 0, 302 72 'File::Temp' => 0, 303 'Geo::Coordinates::UTM' => 0,73 'Geo::Coordinates::UTM' => 0, 304 74 'Geography::NationalGrid' => 0, 305 75 'HTML::Entities' => 0, … … 307 77 'MIME::Lite' => 0, 308 78 'Parse::RecDescent' => 0, 309 $search_module => 0,310 79 'POSIX' => 0, 311 80 'Template' => '2.15', # for hash.delete and string.remove vmethods … … 323 92 'Geo::HelmertTransform' => 0, # for correct WGS84 lat/long 324 93 # when using grid systems 94 'Plucene' => 0, 325 95 326 96 }, 327 dynamic_config => 1, 328 create_makefile_pl => "passthrough" 97 create_makefile_pl => "passthrough", 98 script_files => [ 99 "bin/openguides-install", 100 "bin/openguides-newpage-script", 101 "bin/openguides-preferences-script", 102 "bin/openguides-search-script", 103 "bin/openguides-wiki-script", 104 ], 329 105 ); 330 106 … … 333 109 $build->add_to_cleanup( "t/templates/tmp/" ); 334 110 335 # Tell OpenGuides::Build which additional scripts and templates to install.336 $build->config_data( __extra_scripts =>337 [ "wiki.conf", "preferences.cgi", "search.cgi",338 "newpage.cgi" ] );339 $build->config_data( __templates => [340 "admin_home.tt",341 "admin_revert_user.tt",342 "backlink_results.tt",343 "banner.tt",344 "blacklisted_host.tt",345 "delete_confirm.tt",346 "delete_done.tt",347 "delete_password_wrong.tt",348 "differences.tt",349 "display_metadata.tt",350 "edit_form.tt",351 "edit_form_actions.tt",352 "error.tt",353 "footer.tt",354 "header.tt",355 "home_node.tt",356 "map_index.tt",357 "missing_metadata.tt",358 "moderate_confirm.tt",359 "moderate_password_wrong.tt",360 "navbar.tt",361 "navbar_categories.tt",362 "navbar_locales.tt",363 "navbar_help.tt",364 "navbar_home_link.tt",365 "navbar_options.tt",366 "navbar_revision_info.tt",367 "navbar_search.tt",368 "navbar_this_page.tt",369 "navbar_tools.tt",370 "needing_moderation.tt",371 "newpage.tt",372 "node.tt",373 "node_history.tt",374 "node_image_fields.tt",375 "node_photo_notes.tt",376 "node_rdf.tt",377 "openguides_information_boxes.tt",378 "preferences.tt",379 "random_page_failure.tt",380 "rdf_index.tt",381 "recent_changes.tt",382 "search_results.tt",383 "site_index.tt",384 "search.tt",385 "spam_detected.tt",386 "userstats.tt",387 "wanted_pages.tt"388 ] );389 390 $build->config_data( __static_files => [391 # XXX to be supplied when we have some392 ] );393 394 111 # Finally write the build script. 395 112 $build->create_build_script; branches/new-install-process/MANIFEST
r1117 r1158 13 13 TROUBLESHOOTING 14 14 UPGRADING 15 bin/openguides-install 16 bin/openguides-newpage-script 17 bin/openguides-preferences-script 18 bin/openguides-search-script 19 bin/openguides-wiki-script 15 20 examples/reindex.pl 16 lib/OpenGuides/Build.pm17 21 lib/OpenGuides/CGI.pm 18 22 lib/OpenGuides/Config.pm … … 24 28 lib/OpenGuides/Utils.pm 25 29 lib/OpenGuides.pm 26 newpage.cgi27 preferences.cgi28 search.cgi29 30 templates/admin_home.tt 30 31 templates/admin_revert_user.tt … … 146 147 t/79_host_blacklist.t 147 148 t/templates/15_test.tt 148 wiki.cgibranches/new-install-process/lib/OpenGuides/Config.pm
r1117 r1158 74 74 # Don't forget to add to INSTALL when changing these. 75 75 my %defaults = ( 76 dbtype => " postgres",76 dbtype => "sqlite", 77 77 script_name => "wiki.cgi", 78 78 install_directory => "/usr/lib/cgi-bin/openguides/", … … 157 157 custom_template_path => "Where should I look for custom templates?", 158 158 script_url => "What URL does the install directory map to?", 159 custom_lib_path => "Do you want me to munge a custom lib path into the scripts? If so, enter it here. Separate path entries with whitespace.",159 custom_lib_path => "Do you want me to munge a custom lib path into the scripts?", 160 160 use_plucene => "Do you want to use Plucene for searching? (recommended, but see Changes file before saying yes to this if you are upgrading)", 161 161 indexing_directory => "What directory can I use to store indexes in for searching? ***NOTE*** This directory must exist and be writeable by the user that your script will run as. See README for more on this.", … … 176 176 home_name => "What should the home page of the wiki be called?", 177 177 site_desc => "How would you describe the site?", 178 default_city => "What city is the site based in?",178 default_city => "What city (or village, or town, or county, etc) is the site based in?", 179 179 default_country => "What country is the site based in?", 180 180 contact_email => "Contact email address for the site administrator?", … … 185 185 backlinks_in_title => "Make node titles link to node backlinks (C2 style)?", 186 186 ellipsoid => "Which ellipsoid do you want to use? (eg 'Airy', 'WGS-84')", 187 gmaps_api_key => "Do you have a Google Maps API key to use with this guide? If you enter it here the Google Maps functionality will be automatically enabled.",188 centre_long => "What is the longitude of the centre point of a map to draw for your guide? (This question can be ignored if you aren't using Google Maps).You may paste in a Google Maps URL here (hint: copy URL from 'Link to this page')",189 centre_lat => "What is the latitude of the centre point of a map to draw for your guide? (This question can be ignored if you aren't using Google Maps)",190 default_gmaps_zoom => "What default zoom level shall we use for Google Maps? (This question can be ignored if you aren't using Google Maps)",191 default_gmaps_search_zoom => "What default zoom level shall we use for Google Maps in the search results? (This question can be ignored if you aren't using Google Maps)",192 show_gmap_in_node_display => "Would you like to display a Google Map on every node that has geodata? (This question can be ignored if you aren't using Google Maps)",187 gmaps_api_key => "Do you have a Google Maps API key to use with this guide?", 188 centre_long => "What is the longitude of the centre point of a map to draw for your guide? You may paste in a Google Maps URL here (hint: copy URL from 'Link to this page')", 189 centre_lat => "What is the latitude of the centre point of a map to draw for your guide?", 190 default_gmaps_zoom => "What default zoom level shall we use for Google Maps?", 191 default_gmaps_search_zoom => "What default zoom level shall we use for Google Maps in the search results?", 192 show_gmap_in_node_display => "Would you like to display a Google Map on every node that has geodata?", 193 193 force_wgs84 => "Forcibly treat stored lat/long data as if they used the WGS84 ellipsoid?", 194 google_analytics_key => "Do you have a Google Analytics key to use with this guide? If you enter it here, then Google Analytics functionality will be automatically enabled.",194 google_analytics_key => "Do you have a Google Analytics key to use with this guide?", 195 195 licence_name => "What licence will you use for the guide?", 196 196 licence_url => "What is the URL to your licence?", 197 197 licence_info_url => "What is the URL to your local page about your licensing policy?", 198 spam_detector_module => " What module would you like to use for spam detection? (optional)",199 host_checker_module => " What module would you like to use to run an IP blacklist? (optional)",198 spam_detector_module => "Do you have a module to use for spam detection?", 199 host_checker_module => "Do you have a module for running an IP blacklist?", 200 200 static_path => "What directory should we install static content (CSS, images, javascript) to?", 201 201 static_url => "What is the URL corresponding to the static content?",
