Debian Codegraph @

bin/wiki-toolkit-setupdb

raw
1 #!/usr/bin/perl -w
2 use strict;
3 use Getopt::Long;
4
5 my ($dbtype, $dbname, $dbuser, $dbpass, $dbhost, $help, $preclear);
6 GetOptions( "type=s" => \$dbtype,
7 "name=s" => \$dbname,
8 "user=s" => \$dbuser,
9 "pass=s" => \$dbpass,
10 "host=s" => \$dbhost,
11 "help" => \$help,
12 "force-preclear" => \$preclear
13 );
14
15 unless (defined($dbtype)) {
16 print "You must supply a database type with the --type option.\n";
17 print "Further help can be found by typing 'perldoc $0'\n";
18 exit 1;
19 }
20
21 unless (defined($dbname)) {
22 print "You must supply a database name with the --name option.\n";
23 print "Further help can be found by typing 'perldoc $0'\n";
24 exit 1;
25 }
26
27 if ($help) {
28 print "Help can be found by typing 'perldoc $0'\n";
29 exit 0;
30 }
31
32 my %setup_modules = ( postgres => "Wiki::Toolkit::Setup::Pg",
33 mysql => "Wiki::Toolkit::Setup::MySQL",
34 sqlite => "Wiki::Toolkit::Setup::SQLite"
35 );
36
37 unless ( defined($setup_modules{$dbtype}) ) {
38 print "dbtype must be one of 'postgres', 'mysql', and 'sqlite'\n";
39 print "further help can be found by typing 'perldoc $0'\n";
40 exit 1;
41 }
42
43 my $class = $setup_modules{$dbtype};
44 eval "require $class";
45 if ( $@ ) {
46 print "Couldn't 'use' $class: $@\n";
47 exit 1;
48 }
49
50 if ($preclear) {
51 no strict 'refs';
52 &{$class."::cleardb"}($dbname, $dbuser, $dbpass, $dbhost);
53 }
54
55 {
56 no strict 'refs';
57 &{$class."::setup"}($dbname, $dbuser, $dbpass, $dbhost);
58 }
59
60 =head1 NAME
61
62 wiki-toolkit-setupdb - Set up a database storage backend for Wiki::Toolkit.
63
64 =head1 SYNOPSIS
65
66 # Set up or update the storage backend, leaving any existing data
67 # intact. Useful for upgrading from old versions of Wiki::Toolkit to
68 # newer ones with more backend features.
69
70 wiki-toolkit-setupdb --type postgres
71 --name mywiki \
72 --user wiki \
73 --pass wiki \
74 --host 'db.example.com'
75
76 # Clear out any existing data and set up a fresh backend from scratch.
77
78 wiki-toolkit-setupdb --type postgres
79 --name mywiki \
80 --user wiki \
81 --pass wiki \
82 --force-preclear
83
84 =head1 DESCRIPTION
85
86 Takes three mandatory arguments:
87
88 =over 4
89
90 =item type
91
92 The database type. Should be one of 'postgres', 'mysql' and 'sqlite'.
93
94 =item name
95
96 The database name.
97
98 =item user
99
100 The user that connects to the database. It must have permission
101 to create and drop tables in the database.
102
103 =back
104
105 two optional arguments:
106
107 =over 4
108
109 =item pass
110
111 The user's database password.
112
113 =item host
114
115 The hostname of the machine the database server is running on (omit
116 for local databases).
117
118 =back
119
120 and one optional flag:
121
122 =over 4
123
124 =item force-preclear
125
126 By default, this script will leave any existing data alone. To force
127 that to be cleared out first, pass the C<--force-preclear> flag.
128
129 =back
130
131 =head1 AUTHOR
132
133 Kake Pugh ([email protected]).
134
135 =head1 COPYRIGHT
136
137 Copyright (C) 2002-2003 Kake Pugh. All Rights Reserved.
138 Copyright (C) 2006 the Wiki::Toolkit team. All Rights Reserved.
139
140 This code is free software; you can redistribute it and/or modify it
141 under the same terms as Perl itself.
142
143 =head1 SEE ALSO
144
145 L<Wiki::Toolkit>
146
147 =cut
148
149 1;