Changeset 587 for trunk/Build.PL


Ignore:
Timestamp:
Dec 14, 2004, 6:46:00 PM (17 years ago)
Author:
kake
Message:

Encapsulate config data in OpenGuides::Config.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Build.PL

    r586 r587  
    22use lib "lib";
    33use OpenGuides::Build;
     4use OpenGuides::Config;
    45use Data::Dumper;
    56
    67eval "use Config::Tiny";
    78die "Config::Tiny is required to configure this application.\n" if $@;
    8 
    9 ##### Find out where to install, etc.
    10 
    11 # See if we already have some config variables set.
    12 my $read_config = Config::Tiny->read('wiki.conf');
    13 my %existing_config = $read_config ? %{ $read_config->{_} } : ();
    14 
    15 my @questions = (
    16 { question =>
    17         "What's the name of the database that this site runs on?",
    18   variable => "dbname"
    19 },
    20 { question => "...the database user that can access that database?",
    21   variable => "dbuser"
    22   },
    23 { question => "...the password that they use to access the database?",
    24   variable => "dbpass"
    25   },
    26 { question => "...the machine that the database is hosted on? (blank if local)",
    27   variable => "dbhost"
    28   },
    29 { question => "What do you want the script to be called?",
    30   variable => "script_name",
    31   default  => "wiki.cgi"
    32   },
    33 { question => "What directory should I install it in?",
    34   variable => "install_directory",
    35   default  => "/usr/lib/cgi-bin/openguides/"
    36   },
    37 { question => "What URL does the install directory map to?",
    38   variable => "script_url",
    39   },
    40 { question => "Do you want me to munge a custom lib path into the scripts? "
    41              . "If so, enter it here.  Separate path entries with whitespace:",
    42   variable => "custom_lib_path",
    43   },
    44 { question => "Do you want to use Plucene for searching? (recommended, but see Changes file before saying yes to this if you are upgrading)",
    45   variable => "use_plucene",
    46   default  => "y",
    47   type     => "y_n"
    48   },
    49 { question => "What directory can I use to store indexes in for searching? "
    50             . "***NOTE*** This directory must exist and be writeable by the "
    51             . "user that your script will run as.  See README for more on this.",
    52   variable => "indexing_directory",
    53   default  => "/usr/lib/cgi-bin/openguides/indexes/"
    54   },
    55 { question => "Do you want to enable page deletion?",
    56   variable => "enable_page_deletion",
    57   default  => "n",
    58   type     => "y_n"
    59   },
    60 { question => "Please specify a password for the site admin:",
    61   variable => "admin_pass",
    62   default  => "Change this!"
    63   },
    64 { question => "What's the URL of the site's stylesheet?",
    65   variable => "stylesheet_url"
    66   },
    67 { question => "What's the site called? (should be unique)",
    68   variable => "site_name",
    69   default  => "My OpenGuides Site"
    70   },
    71 { question => "Do you want the navigation bar included on the home page?",
    72   variable => "navbar_on_home_page",
    73   default  => "y",
    74   type     => "y_n"
    75   },
    76 { question => "What should the home page of the wiki be called?",
    77   variable => "home_name",
    78   default  => "Home"
    79   },
    80 { question => "How would you describe the site?",
    81   variable => "site_desc",
    82   default  => "A guide to [my city]"
    83   },
    84 { question => "What city is the site based in?",
    85   variable => "default_city",
    86   default  => "London"
    87   },
    88 { question => "What country is the site based in?",
    89   variable => "default_country",
    90   default  => "United Kingdom"
    91   },
    92 { question => "Contact email address for the site administrator?",
    93   variable => "contact_email"
    94   },
    95 { question => "What language will the site be in? (Please give an ISO language code.)",
    96   variable => "default_language",
    97   default  => "en"
    98   },
    99 { question => "What's the name of the node to use for the text formatting rules link?",
    100   variable => "formatting_rules_node",
    101   default  => "Text Formatting Examples"
    102   },
    103 { question => "Make node titles link to node backlinks (C2 style)?",
    104   variable => "backlinks_in_title",
    105   default  => "n",
    106   type     => "y_n"
    107   },
    108 );
    1099
    11010print <<EOF;
     
    11919my $continue = Module::Build->y_n("Continue with install?", "y");
    12020exit 0 unless $continue;
     21
     22my $existing_config = OpenGuides::Config->new( file => "wiki.conf" );
     23
     24my %yn_vars = map { $_ => 1 }
     25   qw(use_plucene enable_page_deletion navbar_on_home_page backlinks_in_title);
    12126
    12227my $skip_config = Module::Build->y_n("Skip OpenGuides configuration?", "n");
     
    13540# It is an ancient Configurer, and he chooseth one of three.
    13641my $dbtype;
    137 my $dbtype_qu = "what type of database do you want the site to run on?  postgres/mysql/sqlite";
     42my $dbtype_qu = $existing_config->dbtype__qu;
    13843if ( $skip_config ) {
    139     $dbtype = $existing_config{dbtype} || "postgres";
     44    $dbtype = $existing_config->dbtype;
    14045} else {
    14146    until ( $dbtype ) {
    142         my $def = $existing_config{dbtype} || "postgres";
     47        my $def = $existing_config->dbtype;
    14348        $dbtype = Module::Build->prompt("\n$dbtype_qu", $def);
    14449        $dbtype = lc($dbtype);
     
    16469                 value    => $dbtype };
    16570
    166 foreach my $qset (@questions) {
    167     my $qu  = $qset->{question};
    168     my $type = $qset->{type} || "";
    169     my $var = $qset->{variable};
    170     my $def = defined $existing_config{$var} ? $existing_config{$var}
    171                                              : $qset->{default};
     71my $install_directory; # used to suggest template paths
     72foreach my $var ( qw(
     73   dbname dbuser dbpass dbhost script_name
     74   install_directory template_path custom_template_path script_url
     75   custom_lib_path use_plucene indexing_directory enable_page_deletion
     76   admin_pass stylesheet_url site_name navbar_on_home_page home_name
     77   site_desc default_city default_country contact_email default_language
     78   formatting_rules_node backlinks_in_title
     79  ) ) {
     80    my $q_method = $var . "__qu";
     81    my $qu  = $existing_config->$q_method;
     82    my $type = $yn_vars{$var} ? "y_n" : "";
     83    my $def = $existing_config->$var;
    17284    my $val = $def;
    17385
     86    # Override dbname question for SQLite only.
    17487    if ( $dbtype eq "sqlite" and $var eq "dbname" ) {
    17588        $qu = "what's the full filename of the SQLite database this site runs on?";
     
    18699    }
    187100
     101    # Make sensible suggestions for template paths if we don't already
     102    # have them stored.  Not really a default, but a useful hint/shortcut.
     103    if ( $var eq "template_path" && !defined $existing_config->$var ) {
     104        $def = $install_directory;
     105        $def .= "/" unless $def =~ m|/$|;
     106        $def .= "templates";
     107    }
     108    if ( $var eq "custom_template_path" && !defined $existing_config->$var ) {
     109        $def = $install_directory;
     110        $def .= "/" unless $def =~ m|/$|;
     111        $def .= "custom-templates";
     112    }
     113
     114    # Here is where we actually ask the questions.
    188115    unless ( $skip_config ) {
    189116        if ( $type eq "y_n" ) {
     
    198125    }
    199126
     127    # Store install_directory so we can use it to suggest template paths.
     128    $install_directory = $val if $var eq "install_directory";
     129
    200130    # Make sure that script_url ends in a /
    201131    if ( $var eq "script_url" and $val !~ /\/$/ ) {
     
    206136                     variable => $var,
    207137                     value    => $val };
    208 
    209     if ( $var eq "install_directory" ) {
    210         push @answers, {
    211             question => "what directory should I install the templates in?",
    212             variable => "template_path",
    213             value    => $val . "/templates" };
    214         push @answers, {
    215             question => "where should I look for custom templates?",
    216             variable => "custom_template_path",
    217             value    => $val . "/custom-templates" };
    218     }
    219138}
    220139
     
    229148if ( $skip_config ) {
    230149    # We default to GB National Grid for historical reasons.
    231     $geo_handler = $existing_config{geo_handler} || 1;
     150    $geo_handler = $existing_config->geo_handler;
    232151} else {
    233152    my $choice;
    234153    until ( $choice ) {
    235         my $def = $existing_config{geo_handler} || 1;
     154        my $def = $existing_config->geo_handler;
    236155        $choice = Module::Build->prompt("\n".$geo_handler_qu, $def);
    237156        $choice =~ s/^\s*//;
     
    252171
    253172if ( $geo_handler eq "3" ) {
    254     my $qu = "Which ellipsoid do you want to use? (eg 'Airy', 'WGS-84')";
     173    my $qu = $existing_config->ellipsoid__qu;
    255174    my $ellipsoid;
    256175    if ( $skip_config ) {
    257         $ellipsoid = $existing_config{ellipsoid} || "International";
     176        $ellipsoid = $existing_config->ellipsoid;
    258177    } else {
    259         my $def = $existing_config{ellipsoid} || "International";
     178        my $def = $existing_config->ellipsoid;
    260179        $ellipsoid = Module::Build->prompt("\n".$qu, $def);
    261180        $ellipsoid =~ s/^\s*//;
     
    298217        'CGI::Wiki::Plugin::RSS::ModWiki' => '0.06', # for fancy stuff
    299218        'CGI::Wiki::Plugin::RSS::Reader'  => '1.3',  # earlier versions don't support RSS 2.0
     219        'Class::Accessor'                 => 0,
    300220        'Config::Tiny'                    => 0,
    301221        'Data::Dumper'                    => 0,
Note: See TracChangeset for help on using the changeset viewer.