| 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 = OpenGuides::Config->new( file => "wiki.conf" ); |
|---|
| 23 | |
|---|
| 24 | my %yn_vars = map { $_ => 1 } |
|---|
| 25 | qw(use_plucene enable_page_deletion navbar_on_home_page backlinks_in_title); |
|---|
| 26 | |
|---|
| 27 | my $skip_config = Module::Build->y_n("Skip OpenGuides configuration?", "n"); |
|---|
| 28 | if ( $skip_config ) { |
|---|
| 29 | print <<EOF; |
|---|
| 30 | =========================================================================== |
|---|
| 31 | Skipping OpenGuides configuration - any configuration options previously |
|---|
| 32 | saved will be used instead. You may tweak your configuration now by |
|---|
| 33 | editing the 'wiki.conf' file produced by this script. |
|---|
| 34 | =========================================================================== |
|---|
| 35 | EOF |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | my @answers; |
|---|
| 39 | |
|---|
| 40 | # It is an ancient Configurer, and he chooseth one of three. |
|---|
| 41 | my $dbtype; |
|---|
| 42 | my $dbtype_qu = $existing_config->dbtype__qu; |
|---|
| 43 | if ( $skip_config ) { |
|---|
| 44 | $dbtype = $existing_config->dbtype; |
|---|
| 45 | } else { |
|---|
| 46 | until ( $dbtype ) { |
|---|
| 47 | my $def = $existing_config->dbtype; |
|---|
| 48 | $dbtype = Module::Build->prompt("\n$dbtype_qu", $def); |
|---|
| 49 | $dbtype = lc($dbtype); |
|---|
| 50 | $dbtype =~ s/^\s*//; |
|---|
| 51 | $dbtype =~ s/\s*$//; |
|---|
| 52 | unless ( $dbtype eq "postgres" or $dbtype eq "mysql" |
|---|
| 53 | or $dbtype eq "sqlite" ) { |
|---|
| 54 | undef $dbtype; |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | # Check they have the relevant DBD driver installed. |
|---|
| 60 | my %drivers = ( postgres => "DBD::Pg", |
|---|
| 61 | mysql => "DBD::mysql", |
|---|
| 62 | sqlite => "DBD::SQLite", |
|---|
| 63 | ); |
|---|
| 64 | eval "require $drivers{$dbtype}"; |
|---|
| 65 | warn "$drivers{$dbtype} is needed to run a $dbtype database" if $@; |
|---|
| 66 | |
|---|
| 67 | push @answers, { question => $dbtype_qu, |
|---|
| 68 | variable => "dbtype", |
|---|
| 69 | value => $dbtype }; |
|---|
| 70 | |
|---|
| 71 | my $install_directory; # used to suggest template paths |
|---|
| 72 | my $use_plucene; # keep track of this so we know what to put in prereqs |
|---|
| 73 | foreach my $var ( qw( |
|---|
| 74 | dbname dbuser dbpass dbhost script_name |
|---|
| 75 | install_directory template_path custom_template_path script_url |
|---|
| 76 | custom_lib_path use_plucene indexing_directory enable_page_deletion |
|---|
| 77 | admin_pass stylesheet_url site_name navbar_on_home_page home_name |
|---|
| 78 | site_desc default_city default_country contact_email default_language |
|---|
| 79 | formatting_rules_node backlinks_in_title gmaps_api_key centre_long |
|---|
| 80 | centre_lat default_gmaps_zoom default_gmaps_search_zoom force_wgs84 |
|---|
| 81 | licence_name licence_url licence_info_url |
|---|
| 82 | ) ) { |
|---|
| 83 | my $q_method = $var . "__qu"; |
|---|
| 84 | my $qu = $existing_config->$q_method; |
|---|
| 85 | my $type = $yn_vars{$var} ? "y_n" : ""; |
|---|
| 86 | my $def = $existing_config->$var; |
|---|
| 87 | my $val = $def; |
|---|
| 88 | |
|---|
| 89 | # Override dbname question for SQLite only. |
|---|
| 90 | if ( $dbtype eq "sqlite" and $var eq "dbname" ) { |
|---|
| 91 | $qu = "what's the full filename of the SQLite database this site runs on?"; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | if ( $dbtype eq "sqlite" and |
|---|
| 95 | ( $var eq "dbuser" or $var eq "dbpass" or $var eq "dbhost" ) |
|---|
| 96 | ) { |
|---|
| 97 | print "$var not relevant for SQLite... skipping...\n"; |
|---|
| 98 | push @answers, { question => $qu, |
|---|
| 99 | variable => $var, |
|---|
| 100 | value => "not-used" }; |
|---|
| 101 | next; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | # Make sensible suggestions for template paths if we don't already |
|---|
| 105 | # have them stored. Not really a default, but a useful hint/shortcut. |
|---|
| 106 | if ( $var eq "template_path" && !defined $existing_config->$var ) { |
|---|
| 107 | $def = $install_directory; |
|---|
| 108 | $def .= "/" unless $def =~ m|/$|; |
|---|
| 109 | $def .= "templates"; |
|---|
| 110 | } |
|---|
| 111 | if ( $var eq "custom_template_path" && !defined $existing_config->$var ) { |
|---|
| 112 | $def = $install_directory; |
|---|
| 113 | $def .= "/" unless $def =~ m|/$|; |
|---|
| 114 | $def .= "custom-templates"; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | # Here is where we actually ask the questions. |
|---|
| 118 | unless ( $skip_config ) { |
|---|
| 119 | if ( $type eq "y_n" ) { |
|---|
| 120 | # may be stored as true/false integer value |
|---|
| 121 | if ( $def =~ /^\d+$/ ) { |
|---|
| 122 | $def = $def ? "y" : "n"; |
|---|
| 123 | } |
|---|
| 124 | $val = Module::Build->y_n("\n$qu ", $def); |
|---|
| 125 | } else { |
|---|
| 126 | $val = Module::Build->prompt("\n$qu ", $def); |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | # Store install_directory so we can use it to suggest template paths. |
|---|
| 131 | $install_directory = $val if $var eq "install_directory"; |
|---|
| 132 | |
|---|
| 133 | # Keep track of chosen search method so we know what to put in prereqs. |
|---|
| 134 | # From Module::Build docs: ->y_n returns a Perl boolean true or false. |
|---|
| 135 | $use_plucene = 1 if $var eq "use_plucene" and $val; |
|---|
| 136 | |
|---|
| 137 | # Make sure that script_url ends in a / |
|---|
| 138 | if ( $var eq "script_url" and $val !~ /\/$/ ) { |
|---|
| 139 | $val .= "/"; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | push @answers, { question => $qu, |
|---|
| 143 | variable => $var, |
|---|
| 144 | value => $val }; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | # Now deal with the geo stuff. |
|---|
| 148 | my $geo_handler; |
|---|
| 149 | my $geo_handler_qu = "Distance calculation methods available are:" |
|---|
| 150 | . "\n 1) British National Grid" |
|---|
| 151 | . "\n 2) Irish National Grid" |
|---|
| 152 | . "\n 3) UTM ellipsoid" |
|---|
| 153 | . "\nWhich would you like to use?"; |
|---|
| 154 | |
|---|
| 155 | if ( $skip_config ) { |
|---|
| 156 | # We default to GB National Grid for historical reasons. |
|---|
| 157 | $geo_handler = $existing_config->geo_handler; |
|---|
| 158 | } else { |
|---|
| 159 | my $choice; |
|---|
| 160 | until ( $choice ) { |
|---|
| 161 | my $def = $existing_config->geo_handler; |
|---|
| 162 | $choice = Module::Build->prompt("\n".$geo_handler_qu, $def); |
|---|
| 163 | $choice =~ s/^\s*//; |
|---|
| 164 | $choice =~ s/\s*$//; |
|---|
| 165 | unless ( $choice eq "1" or $choice eq "2" or $choice eq "3" ) { |
|---|
| 166 | undef $choice; |
|---|
| 167 | } |
|---|
| 168 | } |
|---|
| 169 | $geo_handler = $choice; |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | $geo_handler_qu =~ s/\n//gs; |
|---|
| 173 | push @answers, { |
|---|
| 174 | question => $geo_handler_qu, |
|---|
| 175 | variable => "geo_handler", |
|---|
| 176 | value => $geo_handler, |
|---|
| 177 | }; |
|---|
| 178 | |
|---|
| 179 | if ( $geo_handler eq "3" ) { |
|---|
| 180 | my $qu = $existing_config->ellipsoid__qu; |
|---|
| 181 | my $ellipsoid; |
|---|
| 182 | if ( $skip_config ) { |
|---|
| 183 | $ellipsoid = $existing_config->ellipsoid; |
|---|
| 184 | } else { |
|---|
| 185 | my $def = $existing_config->ellipsoid; |
|---|
| 186 | $ellipsoid = Module::Build->prompt("\n".$qu, $def); |
|---|
| 187 | $ellipsoid =~ s/^\s*//; |
|---|
| 188 | $ellipsoid =~ s/\s*$//; |
|---|
| 189 | } |
|---|
| 190 | push @answers, { |
|---|
| 191 | question => $qu, |
|---|
| 192 | variable => "ellipsoid", |
|---|
| 193 | value => $ellipsoid, |
|---|
| 194 | }; |
|---|
| 195 | } |
|---|
| 196 | |
|---|
| 197 | # Create a user-friendly config file from answers to prompts. |
|---|
| 198 | open FILE, ">wiki.conf" or die "Can't open wiki.conf for writing: $!"; |
|---|
| 199 | foreach my $ans (@answers) { |
|---|
| 200 | print FILE "# $ans->{question}\n"; |
|---|
| 201 | print FILE "$ans->{variable} = $ans->{value}\n\n"; |
|---|
| 202 | } |
|---|
| 203 | close FILE or die "Can't close wiki.conf: $!"; |
|---|
| 204 | |
|---|
| 205 | ##### |
|---|
| 206 | ##### When updating the prereqs PLEASE REMEMBER to update PREREQUISITES. |
|---|
| 207 | ##### |
|---|
| 208 | |
|---|
| 209 | my $search_module = $use_plucene ? "Plucene" : "Search::InvertedIndex"; |
|---|
| 210 | |
|---|
| 211 | # Create the build object. |
|---|
| 212 | my $build = OpenGuides::Build->new( |
|---|
| 213 | sign => 1, |
|---|
| 214 | dist_name => "OpenGuides", |
|---|
| 215 | dist_version_from => "wiki.cgi", |
|---|
| 216 | license => "perl", |
|---|
| 217 | requires => { |
|---|
| 218 | 'Algorithm::Diff' => '0.13', # for sdiff |
|---|
| 219 | 'CGI' => '2.92', # avoid escapeHTML bug |
|---|
| 220 | 'CGI::Carp' => 0, |
|---|
| 221 | 'CGI::Cookie' => 0, |
|---|
| 222 | 'Wiki::Toolkit' => 0, |
|---|
| 223 | 'Wiki::Toolkit::Feed::Atom' => 0, |
|---|
| 224 | 'Wiki::Toolkit::Feed::RSS' => 0, |
|---|
| 225 | 'Wiki::Toolkit::Formatter::UseMod' => 0, |
|---|
| 226 | 'Wiki::Toolkit::Plugin::Categoriser' => 0, |
|---|
| 227 | 'Wiki::Toolkit::Plugin::Diff' => 0, |
|---|
| 228 | 'Wiki::Toolkit::Plugin::Locator::Grid'=> 0, |
|---|
| 229 | 'Wiki::Toolkit::Plugin::RSS::Reader' => 0, |
|---|
| 230 | 'Class::Accessor' => 0, |
|---|
| 231 | 'Config::Tiny' => 0, |
|---|
| 232 | 'Data::Dumper' => 0, |
|---|
| 233 | $drivers{$dbtype} => 0, |
|---|
| 234 | 'File::Spec::Functions' => 0, |
|---|
| 235 | 'File::Temp' => 0, |
|---|
| 236 | 'Geography::NationalGrid' => 0, |
|---|
| 237 | 'LWP::Simple' => 0, |
|---|
| 238 | 'Parse::RecDescent' => 0, |
|---|
| 239 | $search_module => 0, |
|---|
| 240 | 'POSIX' => 0, |
|---|
| 241 | 'Template' => 0, |
|---|
| 242 | 'Test::MockObject' => '0.07', # earlier doesn't use 'mock' |
|---|
| 243 | 'Time::Piece' => 0, |
|---|
| 244 | 'URI::Escape' => 0, |
|---|
| 245 | 'XML::RSS' => 0, |
|---|
| 246 | }, |
|---|
| 247 | build_requires => { |
|---|
| 248 | 'Module::Build' => '0.18', # earlier doesn't install script files |
|---|
| 249 | }, |
|---|
| 250 | recommends => { |
|---|
| 251 | 'DBD::SQLite' => 0, # for testing |
|---|
| 252 | 'Test::HTML::Content' => 0, # for testing, oddly enough |
|---|
| 253 | }, |
|---|
| 254 | dynamic_config => 1, |
|---|
| 255 | create_makefile_pl => "passthrough" |
|---|
| 256 | ); |
|---|
| 257 | |
|---|
| 258 | $build->add_to_cleanup( "t/indexes/" ); |
|---|
| 259 | $build->add_to_cleanup( "t/node.db" ); |
|---|
| 260 | |
|---|
| 261 | # Tell OpenGuides::Build which additional scripts and templates to install. |
|---|
| 262 | $build->{config}{__extra_scripts} = |
|---|
| 263 | [ "wiki.conf", "preferences.cgi", "search.cgi", |
|---|
| 264 | "newpage.cgi" ]; |
|---|
| 265 | $build->{config}{__templates} = [ |
|---|
| 266 | "backlink_results.tt", |
|---|
| 267 | "banner.tt", |
|---|
| 268 | "delete_confirm.tt", |
|---|
| 269 | "delete_done.tt", |
|---|
| 270 | "delete_password_wrong.tt", |
|---|
| 271 | "differences.tt", |
|---|
| 272 | "display_metadata.tt", |
|---|
| 273 | "edit_conflict.tt", |
|---|
| 274 | "edit_form.tt", |
|---|
| 275 | "error.tt", |
|---|
| 276 | "footer.tt", |
|---|
| 277 | "header.tt", |
|---|
| 278 | "home_node.tt", |
|---|
| 279 | "map_index.tt", |
|---|
| 280 | "navbar.tt", |
|---|
| 281 | "newpage.tt", |
|---|
| 282 | "node.tt", |
|---|
| 283 | "node_history.tt", |
|---|
| 284 | "openguides_information_boxes.tt", |
|---|
| 285 | "preferences.tt", |
|---|
| 286 | "rdf_index.tt", |
|---|
| 287 | "recent_changes.tt", |
|---|
| 288 | "search_results.tt", |
|---|
| 289 | "site_index.tt", |
|---|
| 290 | "search.tt", |
|---|
| 291 | "userstats.tt", |
|---|
| 292 | "wanted_pages.tt" |
|---|
| 293 | ]; |
|---|
| 294 | |
|---|
| 295 | # Finally write the build script. |
|---|
| 296 | $build->create_build_script; |
|---|