| 1 | |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | |
|---|
| 6 | use OpenGuides::Config; |
|---|
| 7 | |
|---|
| 8 | my $config_file = shift or die "Must specify config file on command line!"; |
|---|
| 9 | |
|---|
| 10 | if ( ! -r $config_file ) { |
|---|
| 11 | die "Config file specified is not readable: $!"; |
|---|
| 12 | } |
|---|
| 13 | |
|---|
| 14 | my $config = OpenGuides::Config->new( file => $config_file); |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | my $dbname = $config->dbname; |
|---|
| 18 | my $dbuser = $config->dbuser; |
|---|
| 19 | my $dbpass = $config->dbpass; |
|---|
| 20 | my $dbhost = $config->dbhost; |
|---|
| 21 | my $dbtype = $config->dbtype; |
|---|
| 22 | |
|---|
| 23 | my %cgi_wiki_exts = ( postgres => "Pg", |
|---|
| 24 | mysql => "MySQL", |
|---|
| 25 | sqlite => "SQLite" ); |
|---|
| 26 | |
|---|
| 27 | my %dbd_exts = ( postgres => "Pg", |
|---|
| 28 | mysql => "mysql", |
|---|
| 29 | sqlite => "SQLite" ); |
|---|
| 30 | |
|---|
| 31 | my $cgi_wiki_module = "CGI::Wiki::Setup::" . $cgi_wiki_exts{$dbtype}; |
|---|
| 32 | my $dbd_module = "DBD::" . $dbd_exts{$dbtype}; |
|---|
| 33 | |
|---|
| 34 | eval "require $dbd_module"; |
|---|
| 35 | |
|---|
| 36 | if ($@) { |
|---|
| 37 | print "The DBD module is probably not installed;\n"; |
|---|
| 38 | print "we won't set up the database now.\n"; |
|---|
| 39 | exit 0; |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | eval "require $cgi_wiki_module"; |
|---|
| 43 | |
|---|
| 44 | if ($@) { |
|---|
| 45 | print "The DBD module is probably not installed;\n"; |
|---|
| 46 | print "we won't set up the database now.\n"; |
|---|
| 47 | exit 0; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | print "Checking database schema...\n"; |
|---|
| 51 | { |
|---|
| 52 | no strict 'refs'; |
|---|
| 53 | &{$cgi_wiki_module . "::setup"}( $dbname, $dbuser, $dbpass, $dbhost ); |
|---|
| 54 | } |
|---|