#!/usr/local/bin/perl -w use strict; use Config::Tiny; use Cwd; use OpenGuides; # This is here in case we add extra templates etc. my $openguides_version = '0.34'; die "Version mismatch - found OpenGuides version $OpenGuides::VERSION but this script is written for version $openguides_version\n" if $OpenGuides::VERSION ne $openguides_version; # Stolen from Bryar. sub write_file { my ($name, $content) = @_; open OUT, ">".$name or die "Couldn't write to $name - $!\n"; print OUT $content; close OUT; } # Find the config file. my $conf_file = "wiki.conf"; my $config; if ( -e $conf_file ) { $config = Config::Tiny->read( $conf_file ); } else { $config = Config::Tiny->new; } # Process command-line options. # Set defaults for any unspecified options. my %defaults = get_defaults(); foreach my $key ( keys %defaults ) { $config->{_}{$key} = $defaults{$key} unless defined $config->{_}{$key}; } # Get hold of the user-friendly versions of the config questions. # And find out what order to write wiki.conf out in. my %questions = get_questions(); my @ordered_options = get_ordered_options(); # Write out wiki.conf open FILE, ">wiki.conf" or die "Can't open wiki.conf for writing: $!"; foreach my $key ( @ordered_options ) { print FILE "# $questions{$key}\n"; print FILE "$key = $config->{_}{$key}\n\n"; } close FILE or die "Can't close wiki.conf: $!"; # Write the wiki.cgi script my $script_file = $config->{_}{install_directory} ."/". $config->{_}{script_name}; my $script_content = "#!/usr/local/bin/perl -w use strict; use OpenGuides; OpenGuides->run; "; write_file( $script_file, $script_content ); # Write the templates, saving old ones to *.bak # Set up the database if required. sub get_ordered_options { return qw( dbtype dbname dbpass dbuser dbhost script_name install_directory template_path script_url indexing_directory enable_page_deletion admin_pass stylesheet_url site_name navbar_on_home_page home_name site_desc default_city default_country default_language contact_email formatting_rules_node ); } sub get_defaults { # Set defaults for any unspecified options. Some of these will # have to be set by the user but we put in blanks so that they # know what they have to edit. return ( dbtype => "", dbname => "", dbpass => "", dbuser => "", dbhost => "", script_name => "wiki.cgi", install_directory => cwd, template_path => cwd . "/templates", script_url => "", indexing_directory => cwd . "/search_map", enable_page_deletion => 0, admin_pass => "change this", stylesheet_url => "", site_name => "The Open Guide to [mycity]", navbar_on_home_page => 1, home_name => "Home", site_desc => "", default_city => "", default_country => "", default_language => "en", contact_email => "", formatting_rules_node => "Text Formatting Examples", ); } sub get_questions { return ( dbtype => "What type of database does this site run on? (sqlite/mysql/postgres)", dbname => "What's the name of the database that this site runs on?", dbuser => "...the database user that can access that database?", dbpass => "...the password that they use to access the database?", dbhost => "...the machine that the database is hosted on? (blank if local)", script_name => "What do you want the script to be called?", install_directory => "What directory should I install it in?", template_path => "What directory should I install the templates in?", script_url => "What URL does the install directory map to?", 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.", enable_page_deletion => "Do you want to enable page deletion?", admin_pass => "Please specify a password for the site admin:", stylesheet_url => "What's the URL of the site's stylesheet?", site_name => "What's the site called? (should be unique)", navbar_on_home_page => "Do you want the navigation bar included on the home page?", home_name => "What should the home page of the wiki be called?", site_desc => "How would you describe the site?", default_city => "What city is the site based in?", default_country => "What country is the site based in?", default_language => "What language will the site be in? (Please give an ISO language code.)", contact_email => "Contact email address for the site administrator?", formatting_rules_node => "What's the name of the node to use for the text formatting rules link?", ); } =head1 NAME openguides-setup - Set up or upgrade the script and templates for an OpenGuides installation. =head1 USAGE openguides-setup --script_name index.cgi Run C in the directory where you want the wiki script to live. If a C file exists in this directory then options will be read from it. Options given on the command line will override options in C. If an option is not specified in C or on the command line, it will be set to a default value; however if it is specified but set to a blank value then it will not be overridden. For example, if your wiki.conf contains site_desc = then no default site description will be applied.