Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 759 lines (650 sloc) 22.493 kB
d8359ff @BrianAker Fry :)
BrianAker authored
1 #!/usr/bin/perl -w
2 # This code is a part of Slash, and is released under the GPL.
c0e7999 @pudge Update 2005, OSTG, etc.
pudge authored
3 # Copyright 1997-2005 by Open Source Technology Group. See README
d8359ff @BrianAker Fry :)
BrianAker authored
4 # and COPYING for more information, or see http://slashcode.com/.
5
50fdf31 @jamiemccarthy Get database class inheritance working properly, esp. for plugins/tag…
jamiemccarthy authored
6 # This is the script to install a website running Slash. It should
7 # not be run until Slash has been installed with 'make install'.
8 # See INSTALL file for details. Original version by Brian "Krow"
9 # Aker (brian@tangent.org)
d8359ff @BrianAker Fry :)
BrianAker authored
10
11 use strict;
10b7943 @pudge Various install-slashsite portability fixes (glorat, slash bug #500399)
pudge authored
12 use Config '%Config';
d8359ff @BrianAker Fry :)
BrianAker authored
13 use File::Basename;
14 use FindBin '$Bin';
15 use Getopt::Std;
16 use File::Copy;
17 use File::Find;
18 use File::Path;
19 use File::Spec::Functions;
20 use Slash;
21 use Slash::DB;
22 use Slash::Install;
23
24 (my $VERSION) = ' $Revision$ ' =~ /\$Revision:\s+([^\s]+)/;
25 my $PROGNAME = basename($0);
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
26 (my $SLASH_PREFIX = $Bin) =~ s|/[^/]+/?$||;
d8359ff @BrianAker Fry :)
BrianAker authored
27
28 my %opts;
29 # Remember to doublecheck these match usage()!
e41ef67 @jamiemccarthy Typofix, thanks tf23
jamiemccarthy authored
30 usage('Options used incorrectly') unless getopts('hvfu:H:n:xRL:i:T:P:a:e:p:o:g:', \%opts);
d8359ff @BrianAker Fry :)
BrianAker authored
31 usage() if !$opts{'u'} and ($opts{'h'} or !keys %opts);
32 # if invoked with both -u and -h, call usage() later, after we load Slash::Install
33 version() if $opts{'v'};
34
35 $| = 1;
36
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
37 my $prefix_site = "$SLASH_PREFIX/site";
d8359ff @BrianAker Fry :)
BrianAker authored
38 my( $owner, $owner_id, $group, $group_id, $password,
39 $sitename, $username, $realname, $email, $dbh, @create, $sql,
40 @sql, $hostname, $hostname_f, $host_noport, $httpd, %slash_sites,
f92d502 @pudge Add a few more options
pudge authored
41 $driver, $theme, $symlink, $include
d8359ff @BrianAker Fry :)
BrianAker authored
42 );
43
44 my %drivers = (
45 Pg => 'postgresql',
46 mysql => 'mysql',
47 Oracle => 'oracle'
48 );
49
50 unless (DBIx::Password::checkVirtualUser($opts{'u'})) {
51 print "You did not supply a valid DBIx::Password virtual name.\n";
ca851f8 @jamiemccarthy Be smarter about not going to the DB just to fetch the list of
jamiemccarthy authored
52 usage() if $opts{'h'};
d8359ff @BrianAker Fry :)
BrianAker authored
53 exit;
54 }
55
56 $driver = $drivers{DBIx::Password::getDriver($opts{'u'})};
57 my $install = Slash::Install->new($opts{'u'});
58
59 usage() if $opts{'u'} and $opts{'h'};
60
61 eval { require DBIx::Password };
62
63 if ($@) {
64 print "Doesn't look like you have DBIx::Password installed.\n";
65 print "Run the CPAN tool and install DBIx::Password.\n";
66 exit;
67 }
68
69 eval { require Template };
70
71 if ($@) {
72 print <<'EOT';
73 Doesn't look like you have Bundle::Slash installed.
74 Run the CPAN tool and install Bundle::Slash. See
75 INSTALL for more information.
76 EOT
77 exit;
78 }
79
80 $dbh = DBIx::Password->connect($opts{'u'});
81
82 unless ($dbh) {
83 print "Are you sure the database is up and running?\n";
84 exit;
85 }
86
87 END { $dbh->disconnect if $dbh }
88
89 # THIS IS DANGEROUS ... when run as root on a non-GNU
10b7943 @pudge Various install-slashsite portability fixes (glorat, slash bug #500399)
pudge authored
90 # system, it can blank out the hostname entirely.
91 # Better to just not populate it unless we're reasonably
92 # sure.
93 chomp($hostname_f = `hostname -f`) if $^O eq 'linux';
d8359ff @BrianAker Fry :)
BrianAker authored
94 unless ($opts{'H'}) {
95 print "
2e9de55 @jamiemccarthy Clarify some recommendations and other language; add a "last chance
jamiemccarthy authored
96 Feel free to ^C this script at any time up to when you see the
4474ffa @jamiemccarthy Correct spelling helps.
jamiemccarthy authored
97 'last chance to abort' prompt. If you do, no changes will be made.
2e9de55 @jamiemccarthy Clarify some recommendations and other language; add a "last chance
jamiemccarthy authored
98
99 What is the hostname of your Slash site
d8359ff @BrianAker Fry :)
BrianAker authored
100 (e.g., www.slashdot.org)? [$hostname_f] ";
101 chomp($hostname = <STDIN>);
102 $hostname ||= $hostname_f;
103 } else {
104 $hostname = $opts{'H'};
105 }
106 ($host_noport = $hostname) =~ s/:.+$//;
107
108 unless ($opts{'o'}) {
0b44502 @jamiemccarthy Clarify that the user/group referred to is unix, not mysql or slash
jamiemccarthy authored
109 print "\nWhat unix user would you like to run your Slash site as? [nobody] ";
d8359ff @BrianAker Fry :)
BrianAker authored
110 chomp($owner = <STDIN>);
111 $owner ||= 'nobody';
112 } else {
113 $owner = $opts{'o'};
114 }
10b7943 @pudge Various install-slashsite portability fixes (glorat, slash bug #500399)
pudge authored
115 if ($Config{d_getpwent}) {
116 $owner_id = getpwnam($owner);
117 die "$owner is not a valid user name.\n" unless defined $owner_id;
118 die "You really, really don't want to run your Slash site as root!"
119 if $owner eq 'root' || $owner_id == 0;
120 }
d8359ff @BrianAker Fry :)
BrianAker authored
121
122 unless ($opts{'g'}) {
10b7943 @pudge Various install-slashsite portability fixes (glorat, slash bug #500399)
pudge authored
123 my $tmpgroup;
124 $tmpgroup = getgrgid($owner_id) if $Config{d_getgrent};
d8359ff @BrianAker Fry :)
BrianAker authored
125 $tmpgroup = defined($tmpgroup) ? $tmpgroup : 'nobody';
0b44502 @jamiemccarthy Clarify that the user/group referred to is unix, not mysql or slash
jamiemccarthy authored
126 print "\nWhat unix group would you like to run your Slash site under? [$tmpgroup] ";
d8359ff @BrianAker Fry :)
BrianAker authored
127 chomp($group = <STDIN>);
128 $group ||= $tmpgroup;
129 } else {
130 $group = $opts{'g'};
131 }
10b7943 @pudge Various install-slashsite portability fixes (glorat, slash bug #500399)
pudge authored
132 if ($Config{d_getgrent}) {
133 $group_id = getgrnam($group);
134 die "$group is not a valid group name.\n" unless defined $group_id;
135 }
d8359ff @BrianAker Fry :)
BrianAker authored
136
137 if ($opts{'R'}) {
138 $sitename = $host_noport;
139 } else {
140 unless ($opts{'n'}) {
141 print "
142 OK, I am planning on user $host_noport as the unique name
143 for the Slash site. If this is not ok, you need to fill in
144 something else here. [$host_noport] ";
145 chomp($sitename = <STDIN>);
146 $sitename ||= $host_noport;
147 } else {
148 $sitename = $opts{'n'};
149 }
150 }
151
152 # themes
153 my $x;
154 #---------------------------------------------------
155 $theme = 0;
156 my $theme_num = 0;
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
157 my $themes = $install->getThemeList($SLASH_PREFIX);
d8359ff @BrianAker Fry :)
BrianAker authored
158 if ($opts{'T'}) {
159 $theme = $opts{'T'};
160 if (!exists $themes->{$theme}) {
161 print "Error: the theme you specified on the command line, '$theme', does not exist. (Note: case matters.)\n";
162 $theme = '';
163 } else {
164 $theme_num = $themes->{$theme}{order};
165 }
166 }
167 if (!$theme) {
168 print "\nWhich theme do you want to use?\n";
b4de41a @jamiemccarthy Change to Slash::Install and bin/install-{plugin,slashsite} to support
jamiemccarthy authored
169 for (sort {
170 $themes->{$a}{order} <=> $themes->{$b}{order}
171 ||
172 $a cmp $b
173 } keys %$themes) {
d8359ff @BrianAker Fry :)
BrianAker authored
174 if ((keys %$themes) > 1) {
b4de41a @jamiemccarthy Change to Slash::Install and bin/install-{plugin,slashsite} to support
jamiemccarthy authored
175 print "( )$themes->{$_}{order}.\t$_ $themes->{$_}{description}\n";
d8359ff @BrianAker Fry :)
BrianAker authored
176 } else {
b4de41a @jamiemccarthy Change to Slash::Install and bin/install-{plugin,slashsite} to support
jamiemccarthy authored
177 print "(*)$themes->{$_}{order}.\t$_ $themes->{$_}{description}\n";
d8359ff @BrianAker Fry :)
BrianAker authored
178 }
179 }
180 if ((keys %$themes) > 1) {
181 chomp($theme_num = <STDIN>);
182 $theme_num ||= '1';
183 } else {
184 print "\nSkipping theme select since you only have one theme!\n";
185 $theme_num = '1';
186 }
187
188 for (keys %$themes) {
189 if ($themes->{$_}{order} == $theme_num) {
190 $theme = $_;
191 }
192 }
193 }
194 print "Theme selected: $theme\n";
195
196 #---------------------------------------------------
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
197 my $plugins = $install->getPluginList($SLASH_PREFIX);
d8359ff @BrianAker Fry :)
BrianAker authored
198 my @plugins = ( );
6c9873e @jamiemccarthy Bugfix: selecting plugins should not eliminate the default set for the
jamiemccarthy authored
199 my @default_plugins = ( );
b4de41a @jamiemccarthy Change to Slash::Install and bin/install-{plugin,slashsite} to support
jamiemccarthy authored
200 my @all_plugins = sort {
201 $plugins->{$a}{order} <=> $plugins->{$b}{order}
202 ||
203 $a cmp $b
204 } keys %$plugins;
6b0daf0 @jamiemccarthy Added pseudo-plugins "ALL" and "DEFAULT" which can only be given on
jamiemccarthy authored
205 for my $key (@all_plugins) {
6c9873e @jamiemccarthy Bugfix: selecting plugins should not eliminate the default set for the
jamiemccarthy authored
206 if ($themes->{$theme}{plugin}{$plugins->{$key}{name}}) {
207 push @default_plugins, $key;
208 }
209 }
d8359ff @BrianAker Fry :)
BrianAker authored
210 if ($opts{'P'}) {
6b0daf0 @jamiemccarthy Added pseudo-plugins "ALL" and "DEFAULT" which can only be given on
jamiemccarthy authored
211 @plugins = grep { exists $plugins->{$_} or /^(ALL|DEFAULT)$/ }
d8359ff @BrianAker Fry :)
BrianAker authored
212 split /\s*,\s*/, $opts{'P'};
6c9873e @jamiemccarthy Bugfix: selecting plugins should not eliminate the default set for the
jamiemccarthy authored
213 push @plugins, @default_plugins if @default_plugins;
d8359ff @BrianAker Fry :)
BrianAker authored
214 } else {
215 my %order_to_name = ( );
2e9de55 @jamiemccarthy Clarify some recommendations and other language; add a "last chance
jamiemccarthy authored
216 print "\nPlugins:\n";
6b0daf0 @jamiemccarthy Added pseudo-plugins "ALL" and "DEFAULT" which can only be given on
jamiemccarthy authored
217 for my $key (@all_plugins) {
d8359ff @BrianAker Fry :)
BrianAker authored
218 my $c = " ";
219 if ($themes->{$theme}{plugin}{$plugins->{$key}{name}}) {
220 $c = "*";
221 }
222 print "($c) $plugins->{$key}{order}. $key - $plugins->{$key}{description}\n";
223 $order_to_name{$plugins->{$key}{order}} = $key;
224 }
225 my $select = 'a';
2e9de55 @jamiemccarthy Clarify some recommendations and other language; add a "last chance
jamiemccarthy authored
226 print "Please select which plugins you would like ('*' marks the default and minimum).\n";
227 print "Note that some optional plugins may have additional system requirements:\n";
228 print "if you select any beyond the default, you must look over their\n";
229 print "$SLASH_PREFIX/plugins/*/README* files.\n";
230 print "Enter 'a' to select all (which is probably a bad idea). Better, enter\n";
231 print "comma-separated numbers, or 'q' for none.\n";
d8359ff @BrianAker Fry :)
BrianAker authored
232 while ($select ne 'q'){
233 chomp($select = <STDIN>);
234 if ($select =~ /^[\d ,]+$/) {
235 $select =~ s/ +//g;
6c9873e @jamiemccarthy Bugfix: selecting plugins should not eliminate the default set for the
jamiemccarthy authored
236 push @plugins,
237 grep { $_ }
238 map { $order_to_name{$_} }
239 split /,/, $select;
d8359ff @BrianAker Fry :)
BrianAker authored
240 last;
241 } elsif ($select eq 'a') {
6b0daf0 @jamiemccarthy Added pseudo-plugins "ALL" and "DEFAULT" which can only be given on
jamiemccarthy authored
242 @plugins = map { $plugins->{$_}{name} } @all_plugins;
d8359ff @BrianAker Fry :)
BrianAker authored
243 last;
244 }
245 }
246 push @plugins, @default_plugins if @default_plugins;
247 }
6c9873e @jamiemccarthy Bugfix: selecting plugins should not eliminate the default set for the
jamiemccarthy authored
248 {
b4de41a @jamiemccarthy Change to Slash::Install and bin/install-{plugin,slashsite} to support
jamiemccarthy authored
249 # Add in any plugins that are required by the selection set.
68d4dc2 @jamiemccarthy The bug where "requiresplugin" could only be used once has been removed.
jamiemccarthy authored
250 # This may/will add a lot of duplicates, which get uniquified
251 # in the next step.
b4de41a @jamiemccarthy Change to Slash::Install and bin/install-{plugin,slashsite} to support
jamiemccarthy authored
252 for (1..scalar(@all_plugins)) {
253 for my $plugin (@plugins) {
68d4dc2 @jamiemccarthy The bug where "requiresplugin" could only be used once has been removed.
jamiemccarthy authored
254 my $req_hr = $plugins->{$plugin}{requiresplugin};
255 if ($req_hr and %$req_hr) {
256 push @plugins, keys %$req_hr;
257 }
b4de41a @jamiemccarthy Change to Slash::Install and bin/install-{plugin,slashsite} to support
jamiemccarthy authored
258 }
259 }
6c9873e @jamiemccarthy Bugfix: selecting plugins should not eliminate the default set for the
jamiemccarthy authored
260 # Eliminate duplicates.
261 my %temp_plugins = map { $_ => 1 } @plugins;
6b0daf0 @jamiemccarthy Added pseudo-plugins "ALL" and "DEFAULT" which can only be given on
jamiemccarthy authored
262 if ($temp_plugins{DEFAULT}) {
263 # Special feature, if the user asks for the plugin
264 # named "DEFAULT" (presumably with the -P option),
265 # they get whatever the theme's default is.
266 for my $key (@default_plugins) {
267 $temp_plugins{$key} = 1;
268 }
269 delete $temp_plugins{DEFAULT};
270 }
271 if ($temp_plugins{ALL}) {
272 # Special feature, if the user asks for the plugin
273 # named "ALL" (presumably with the -P option),
274 # they get all of them.
275 for my $key (@all_plugins) {
276 $temp_plugins{$key} = 1;
277 }
278 delete $temp_plugins{ALL};
279 }
6c9873e @jamiemccarthy Bugfix: selecting plugins should not eliminate the default set for the
jamiemccarthy authored
280 @plugins = sort keys %temp_plugins;
281 }
d8359ff @BrianAker Fry :)
BrianAker authored
282 # Zero out the list of plugins
283 %{$themes->{$theme}{plugin}} = ( );
284 # Add back in the ones just selected
285 for my $plugin (@plugins) {
b4de41a @jamiemccarthy Change to Slash::Install and bin/install-{plugin,slashsite} to support
jamiemccarthy authored
286 $themes->{$theme}{plugin}{$plugin} = $plugins->{$plugin};
d8359ff @BrianAker Fry :)
BrianAker authored
287 }
288 # Show the user what was picked
289 print "Plugins selected: " . join(" ", sort keys %{$themes->{$theme}{plugin}}) . "\n\n";
290
291
10b7943 @pudge Various install-slashsite portability fixes (glorat, slash bug #500399)
pudge authored
292 if (!$Config{d_symlink}) {
293 $symlink = 0;
495a6fa @pudge Oops! Sorry about that. Late addition wasn't tested.
pudge authored
294 } elsif ($opts{'L'}) {
b2d0a13 @pudge Missed y/n change
pudge authored
295 $symlink = $opts{'L'};
d8359ff @BrianAker Fry :)
BrianAker authored
296 } else {
297 print "
2e9de55 @jamiemccarthy Clarify some recommendations and other language; add a "last chance
jamiemccarthy authored
298 Would you like to install all the files as symlinks to the original?
299 (This is recommended. If not, each file will be copied to your
300 Slash directories). [Y] ";
d8359ff @BrianAker Fry :)
BrianAker authored
301 chomp(my $ans = <STDIN>);
302 $ans ||= 'Y';
303 $symlink = $ans =~ /^\s*[Yy]/;
304 }
305
306
307 unless ($opts{'a'}) {
66b9581 @jamiemccarthy The site's admin account isn't limited to 8 chars. Also, don't try to
jamiemccarthy authored
308 print "Create a name for the site's admin account. [$owner] ";
d8359ff @BrianAker Fry :)
BrianAker authored
309 chomp($username = <STDIN>);
310 $username ||= $owner;
311 } else {
312 $username = $opts{'a'};
313 }
314
315 unless ($opts{'p'}) {
316 do {
317 print "\nCreate a password for the site's admin account. ('QUIT' exits):";
318 chomp($password = <STDIN>);
319 die "Cancelled at user request.\n" if $password eq 'QUIT';
320 print "\nYou need to give us a password.\n" unless $password;
321 } until $password;
322 } else {
323 $password = $opts{'p'};
324 }
325 die "You need to give us a password.\n" unless $password;
326
327 unless ($opts{'e'}) {
328 print "\nWhat is the email address of the account? [$username\@$host_noport] ";
329 chomp($email = <STDIN>);
330 $email ||= "$username\@$host_noport";
331 } else {
332 $email = $opts{'e'};
333 }
334
2e9de55 @jamiemccarthy Clarify some recommendations and other language; add a "last chance
jamiemccarthy authored
335 unless ($opts{'f'}) {
336 print "\nThis is your last chance to abort installation.\n";
337 print "Hit return to install or press ^C now to abort: ";
338 my $line = <STDIN>;
339 $line = ''; # avoid a warning about var only used once
340 }
341
342 print "\nInstalling...\n";
343
d8359ff @BrianAker Fry :)
BrianAker authored
344 my $trgst = '';
345
346 # Dump in the schema then pepper with a trace of your own theme
495a6fa @pudge Oops! Sorry about that. Late addition wasn't tested.
pudge authored
347 my $create = gensym();
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
348 open($create, "< $SLASH_PREFIX/sql/$driver/schema.sql\0")
349 or die "Can't open $SLASH_PREFIX/sql/$driver/schema.sql: $!";
d8359ff @BrianAker Fry :)
BrianAker authored
350 while (<$create>) {
351 # ugly-as-hell hack to keep Oracle trigger code from getting munged
352 # the syntax is sensitive plus there *has* to be a semicolon at the end
353 # (yes, one that gets passed in the statement, not the EOS delimiter!)
354 if ($driver eq 'oracle' and (/^CREATE OR REPLACE TRIGGER/ or $trgst)) {
355 $trgst .= $_;
356 next unless /^END;$/;
357 $trgst =~ s/;/#/g;
358 $_ = "$trgst;";
359 $trgst = '';
360 }
361 chomp;
362 next if /^#/;
363 next if /^$/;
364 next if /^ $/;
365 push @create, $_;
366 }
367 close $create;
368
369 $sql = join '', @create;
370 @sql = split /;/, $sql;
371
372 # again with the oracle trigger thing hacking
373 if ($driver eq 'oracle') {
374 for (@sql) {
375 s/#/;/g if /^CREATE OR REPLACE TRIGGER/;
376 }
377 }
378
495a6fa @pudge Oops! Sorry about that. Late addition wasn't tested.
pudge authored
379 my $dump = gensym();
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
380 open($dump, "< $SLASH_PREFIX/sql/$driver/defaults.sql\0")
381 or die "Can't open $SLASH_PREFIX/sql/$driver/defaults.sql: $!";
d8359ff @BrianAker Fry :)
BrianAker authored
382 while (<$dump>) {
383 next unless /^INSERT/;
384 chomp;
385 s/;$//;
1de8458 @jamiemccarthy Section-Topics rewrite. The old system of separation of "section"
jamiemccarthy authored
386 s/\badmin\@example\.com\b/$email/g;
387 s/\bwww\.example\.com\b/$hostname/g;
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
388 s|/usr/local/slash|$SLASH_PREFIX|g;
d8359ff @BrianAker Fry :)
BrianAker authored
389 if ($driver eq 'oracle') {
390 # With this we can almost use the MySQL dump verbatim
391 # Of course, MySQL could have just compiled with SQL-92, too
392 s/\\r/\r/g;
393 s/\\n/\n/g;
394 s/\\'/''/g;
395 s/\\(["\\])/$1/g;
396 }
397 push @sql, $_;
398 }
399
400 close $dump;
66b9581 @jamiemccarthy The site's admin account isn't limited to 8 chars. Also, don't try to
jamiemccarthy authored
401
402 # We start this whole process by turning off foreign key
403 # constraints -- since we will be adding data in an order
404 # not guaranteed to match those constraints. When all
405 # the data is inserted, we can turn them back on.
d2c2078 @jamiemccarthy Wait until the very end of the SQL before restoring foreign key checks.
jamiemccarthy authored
406
407 $dbh->do("SET FOREIGN_KEY_CHECKS = 0");
408
409 # Now process all the SQL.
66b9581 @jamiemccarthy The site's admin account isn't limited to 8 chars. Also, don't try to
jamiemccarthy authored
410
d8359ff @BrianAker Fry :)
BrianAker authored
411 for my $cmd (@sql) {
412 next unless $cmd;
413 my $rows_affected = $dbh->do($cmd);
414 if (!$rows_affected) {
415 # It's very bad if a CREATE TABLE does nothing.
416 if ($cmd =~ /^CREATE TABLE/) {
417 die <<EOT;
418 The CREATE TABLE command below failed. This almost certainly means
419 the rest of the slashsite installation will fail, so we're aborting.
420 This is probably because your SQL user associated with your
421 DBIx::Password user '$opts{u}' lacks CREATE and/or DROP permissions.
422 Fix this, or whatever the problem is, and rerun $PROGNAME.
423 Failed command: $cmd
424 EOT
5444817 @jamiemccarthy When a CREATE TABLE fails, we should do what our error message says
jamiemccarthy authored
425 exit 1;
d8359ff @BrianAker Fry :)
BrianAker authored
426 }
427 # It's OK if a DROP TABLE does nothing, that just means
428 # the table wasn't there to begin with.
429 print "Failed on '$cmd'\n" unless $cmd =~ /^DROP TABLE/;
430 }
431 }
432
433 mkpath "$prefix_site/$sitename", 0, 0775;
434 mkpath "$prefix_site/$sitename/logs", 0, 0775;
435 mkpath "$prefix_site/$sitename/htdocs", 0, 0775;
436 mkpath "$prefix_site/$sitename/htdocs/images", 0, 0775;
437 mkpath "$prefix_site/$sitename/htdocs/images/topics", 0, 0775;
438 mkpath "$prefix_site/$sitename/backups", 0, 0775;
439 mkpath "$prefix_site/$sitename/sbin", 0, 0775;
440 mkpath "$prefix_site/$sitename/tasks", 0, 0775;
441 mkpath "$prefix_site/$sitename/misc", 0, 0775;
442
443 my $slashdb = Slash::DB->new($opts{'u'});
444
445 my $time = localtime();
446 $install->create({ name => 'installed', value => $time});
447 $install->create({ name => 'admin', value => $username});
448 $install->create({ name => 'adminmail', value => $email});
449 $install->create({ name => 'owner', value => $owner});
450 $install->create({ name => 'owner_id', value => $owner_id});
451 $install->create({ name => 'group', value => $group});
452 $install->create({ name => 'group_id', value => $group_id});
453 $install->create({ name => 'siteid', value => $sitename});
454 $install->create({ name => 'basedomain', value => $hostname});
455 $install->create({ name => 'driver', value => $driver});
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
456 $install->create({ name => 'base_install_directory', value => $SLASH_PREFIX});
d8359ff @BrianAker Fry :)
BrianAker authored
457 $install->create({ name => 'site_install_directory', value => "$prefix_site/$sitename"});
458 $install->create({ name => 'db_driver', value => "$driver"});
459
460 #$install->installPlugins(\@plugins, 0, $symlink);
461 $install->installTheme($theme, 0, $symlink);
462
86595f3 @jamiemccarthy Several bugfixes and improvements.
jamiemccarthy authored
463 (my $matchname = lc $username) =~ s/[^a-zA-Z0-9]//g;
464 my $uid = $slashdb->createUser($matchname, $email, $username);
d8359ff @BrianAker Fry :)
BrianAker authored
465 $slashdb->setUser($uid, {
466 passwd => $password,
467 author => 1,
468 seclev => 10000
469 });
470
f92d502 @pudge Add a few more options
pudge authored
471 if ($opts{'i'}) {
472 $include = $opts{'i'};
473 my @stats = stat($include);
474 if ($stats[7] eq '') {
475 print "Warning: Requested include '$include' does not appear to exist";
476 }
477 $include = "\n Include $include\n";
478 } else {
479 $include = '';
480 }
481
d2c2078 @jamiemccarthy Wait until the very end of the SQL before restoring foreign key checks.
jamiemccarthy authored
482 $dbh->do("SET FOREIGN_KEY_CHECKS = 1");
483
d8359ff @BrianAker Fry :)
BrianAker authored
484 # Now, lets update slash.sites
495a6fa @pudge Oops! Sorry about that. Late addition wasn't tested.
pudge authored
485 my $sites = gensym();
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
486 if (open($sites, "< $SLASH_PREFIX/slash.sites\0")) {
d8359ff @BrianAker Fry :)
BrianAker authored
487 while (<$sites>) {
488 chomp;
489 my($dbuser) = split /:/;
490 $slash_sites{$dbuser} = 1;
491 }
492 close $sites;
493 }
494
495 unless (exists $slash_sites{$opts{'u'}}) {
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
496 open($sites, ">> $SLASH_PREFIX/slash.sites\0")
497 or die "Can't append to $SLASH_PREFIX/slash.sites: $!";
d8359ff @BrianAker Fry :)
BrianAker authored
498 print $sites "$opts{'u'}:$owner:$sitename\n";
499 close $sites;
500 }
501
502 find(sub { chown $owner_id, $group_id, $_ unless -l $_ }, "$prefix_site/$sitename");
503
504 # Install spamarmors for a given site. This can be recoded/moved/whatever
505 # if this code is inappropriate, for whatever reason.
10b7943 @pudge Various install-slashsite portability fixes (glorat, slash bug #500399)
pudge authored
506 system("$^X -w $SLASH_PREFIX/bin/reload_armor -u $opts{'u'} -q");
d8359ff @BrianAker Fry :)
BrianAker authored
507 apache_site_conf();
508
509 $dbh->do("UPDATE vars SET value = " . $dbh->quote("$prefix_site/$sitename/logs") . " WHERE name = 'logdir'");
510 $dbh->do("UPDATE vars SET value = " . $dbh->quote("$prefix_site/$sitename/htdocs") . " WHERE name = 'basedir'");
511 $dbh->do("UPDATE vars SET value = " . $dbh->quote("$prefix_site/$sitename") . " WHERE name = 'datadir'");
512 $dbh->do("UPDATE vars SET value = " . $dbh->quote($sitename) . " WHERE name = 'siteid'");
513 $slashdb->createAuthorCache();
514
515 $dbh->disconnect;
516 install_message();
517
518 sub apache_site_conf {
f92d502 @pudge Add a few more options
pudge authored
519 my $host_port = '';
520 $host_port = $opts{'x'} ? '*' : $hostname;
521 $host_port .= ':80' unless $host_port =~ /:/;
d8359ff @BrianAker Fry :)
BrianAker authored
522 my $text = qq|
523 # note that if your site's path is a symlink, the
524 # path listed here is most likely the actual path;
525 # fix it and DocumentRoot if you want to
526 <Directory $prefix_site/$sitename/htdocs>
527 Options FollowSymLinks ExecCGI Includes Indexes
528 AllowOverride None
529 Order allow,deny
530 Allow from all
531 </Directory>
532
533 <VirtualHost $host_port>
534 ServerAdmin $email
535 DocumentRoot $prefix_site/$sitename/htdocs
536 ServerName $host_noport
537 ErrorLog logs/${sitename}_error_log
538 CustomLog logs/${sitename}_access_log common
539
540 PerlSetupEnv On
541 PerlSetEnv TZ GMT
f92d502 @pudge Add a few more options
pudge authored
542 $include
d8359ff @BrianAker Fry :)
BrianAker authored
543 SlashVirtualUser $opts{'u'}
544
545 # this directive will compile all the templates
546 # in the database, if cache_enabled is true
547 # and template_cache_size is 0. Set to On/Off.
548 # Default is off since most sites don't need it
549 # much and startup performance, as well as
89a0f54 @jamiemccarthy Better comments for your site's .conf file, to list the Apache handlers
jamiemccarthy authored
550 # memory usage, degrades when it is On...
551 # setting template_cache_size to 100 or so is
552 # probably a lot better
d8359ff @BrianAker Fry :)
BrianAker authored
553 SlashCompileTemplates Off
89a0f54 @jamiemccarthy Better comments for your site's .conf file, to list the Apache handlers
jamiemccarthy authored
554
555 ########################
556
557 # First Apache phase: post-read-request
d8359ff @BrianAker Fry :)
BrianAker authored
558
a089ba3 @pudge Fill in remote_ip with actual IP if using frontend/backend setup; imp…
pudge authored
559 # if you have a frontend/backend setup and have X-Forwarded-For
560 # headers (such as from mod_proxy_add_forward), use this
561 # to properly populate remote_ip for formkeys etc.
562 #PerlPostReadRequestHandler Slash::Apache::ProxyRemoteAddr
563
89a0f54 @jamiemccarthy Better comments for your site's .conf file, to list the Apache handlers
jamiemccarthy authored
564 # Second Apache phase: URI translation
565
d8359ff @BrianAker Fry :)
BrianAker authored
566 # this directive will redirect non-logged-in users to
567 # index.shtml if they request the home page; turn it
3b2dd1e @BrianAker Lots of changes, I touched everything. Doesn't that make you feel dirty?
BrianAker authored
568 # on to help increase performance or if you are using something
3f0f385 @jamiemccarthy Numerous INSTALL improvements, including stressing importance of
jamiemccarthy authored
569 # other than index.pl for the index
3b2dd1e @BrianAker Lots of changes, I touched everything. Doesn't that make you feel dirty?
BrianAker authored
570 PerlTransHandler Slash::Apache::IndexHandler
3f0f385 @jamiemccarthy Numerous INSTALL improvements, including stressing importance of
jamiemccarthy authored
571 # this directive will display a user's pages at /~username
d8359ff @BrianAker Fry :)
BrianAker authored
572 PerlTransHandler Slash::Apache::User::userdir_handler
573
89a0f54 @jamiemccarthy Better comments for your site's .conf file, to list the Apache handlers
jamiemccarthy authored
574 # Third Apache phase: header parsing
575
576 # Fourth Apache phase: access control
577 PerlAccessHandler Slash::Apache::Banlist
578 PerlAccessHandler Slash::Apache::User
579
580 # Fifth Apache phase: authentication
581
582 # Sixth Apache phase: authorization
583
584 # Seventh Apache phase: MIME type checking
585
586 # Eighth Apache phase: fixups
587
588 # Ninth Apache phase: response, aka content handler:
589 # Apache::Registry and whatever else is in the slash.conf file
590
591 # Tenth Apache phase: logging
592
593 # Eleventh Apache phase: cleanup
594 PerlCleanupHandler Slash::Apache::Log
595 PerlCleanupHandler Slash::Apache::Log::UserLog
596
597 ########################
598
5b49606 @pudge Use Apache::RegistryLoader by default on new sites
pudge authored
599 # this can be used to preload your .pl scripts in the parent,
600 # saving both startup time and memory in the child
601 # add/remove scripts from \@pls (normally best to include only
602 # and all commonly used scripts)
603 PerlModule Apache::RegistryLoader;
604 <Perl>
605 # if you need to debug, temporarily turn this on
606 # \$Apache::Registry::Debug = 4;
5a7f36b @jamiemccarthy Preload ajax.pl and firehose.pl
jamiemccarthy authored
607 my \@pls = qw(index comments article users journal search ajax firehose);
b2c903e @pudge dum
pudge authored
608 my \$vhost = '$host_noport';
609 my \$docroot = '$prefix_site/$sitename/htdocs';
5b49606 @pudge Use Apache::RegistryLoader by default on new sites
pudge authored
610 my \$r = Apache::RegistryLoader->new;
611
612 for my \$u (\@pls) {
613 my \$f = "\$docroot/\$u.pl";
614 \$r->handler("/\$u.pl", \$f, \$vhost) if -e \$f;
615 }
616 </Perl>
617
d8359ff @BrianAker Fry :)
BrianAker authored
618 DirectoryIndex index.pl index.shtml
619 ErrorDocument 404 /404.pl
620
621 AddType text/xml .xml
0719cac @pudge Begin Atom support
pudge authored
622 AddType application/rss+xml .rdf
623 AddType application/rss+xml .rss
624 AddType application/atom+xml .atom
625 AddType text/vnd.wap.wml .wml
d8359ff @BrianAker Fry :)
BrianAker authored
626
59be074 @pudge Revert to iso-8859-1 as default
pudge authored
627 # change default of "iso-8859-1" here (to, for example, utf-8)
628 # if you change "content_type_webpage" in vars, and vice versa
629 AddType text/html;charset=iso-8859-1 .shtml
d8359ff @BrianAker Fry :)
BrianAker authored
630 AddHandler server-parsed .shtml
631
632 AddType text/html .inc
633 AddHandler server-parsed .inc
634 </VirtualHost>
635 |;
636 my $file = "$prefix_site/$sitename/$sitename.conf";
495a6fa @pudge Oops! Sorry about that. Late addition wasn't tested.
pudge authored
637 my $fh = gensym();
d8359ff @BrianAker Fry :)
BrianAker authored
638
639 open($fh, ">$file\0") or die "Can't write to $file: $!";
640 print $fh $text;
641 close $fh;
642
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
643 open($fh, "< $SLASH_PREFIX/httpd/slash.conf\0")
644 or die "Can't write to $SLASH_PREFIX/httpd/slash.conf: $!";
d8359ff @BrianAker Fry :)
BrianAker authored
645
646 unless (grep /^(?:#\s*)?Include $file$/, <$fh>) {
647 close $fh;
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
648 open($fh, ">> $SLASH_PREFIX/httpd/slash.conf\0")
649 or die "Can't open $SLASH_PREFIX/httpd/slash.conf: $!";
d8359ff @BrianAker Fry :)
BrianAker authored
650 print $fh "Include $file\n";
651 }
652 close $fh;
653 }
654
655 sub install_message {
656 my $text = qq|
657
658
4350dbe @jamiemccarthy Better canonicalization of filenames that symlinks point to: instead of
jamiemccarthy authored
659 You should now have a slashsite! (Unless serious errors were reported
660 during the install. Some plugins do INSERT IGNOREs which may fail and
661 that is harmless, notably the Search plugin if SOAP is not installed,
662 which will report that the soap_methods table does not exist.)
663
1cababb @jamiemccarthy A note about reading README files for optional plugins.
jamiemccarthy authored
664 If you installed optional plugins, remember to read their README files,
665 if any.
666
4350dbe @jamiemccarthy Better canonicalization of filenames that symlinks point to: instead of
jamiemccarthy authored
667 You will need to edit your httpd.conf file to have it Include the
668 Slash file that (in turn) Includes this site's .conf data. Assuming
669 this is the first Slash site you've installed for this Apache, you
670 will almost certainly want to add this to your httpd.conf:
671
672 Include $SLASH_PREFIX/httpd/slash.conf
673
674 which in turn will Include this file (which you should look at and,
675 if you know what you're doing, edit):
d8359ff @BrianAker Fry :)
BrianAker authored
676
677 $prefix_site/$sitename/$sitename.conf
678
3f0f385 @jamiemccarthy Numerous INSTALL improvements, including stressing importance of
jamiemccarthy authored
679 Now you can continue with step 6 of the INSTALL file directions.
d8359ff @BrianAker Fry :)
BrianAker authored
680
681 |;
682 print $text
683 }
684
685 sub usage {
686 print "*** $_[0]\n" if $_[0];
687
688 # Generate a sample list of plugins which just happens to be
689 # the default list for the first theme.
690 my $sample_plugins = '';
ca851f8 @jamiemccarthy Be smarter about not going to the DB just to fetch the list of
jamiemccarthy authored
691 if (!$install) {
692 my $usercheck = $opts{u} || 'slash';
693 if (DBIx::Password::checkVirtualUser($usercheck)) {
694 eval { $install = Slash::Install->new($usercheck) };
695 }
696 $install = undef if !$install or ref $install ne 'Slash::Install';
697 }
d8359ff @BrianAker Fry :)
BrianAker authored
698 if ($install) {
9a754c1 @pudge Fix SLASH_PREFIX on runtask, remove old occurrences of that line, upd…
pudge authored
699 my $plugins = $install->getPluginList($SLASH_PREFIX);
700 my $themes = $install->getThemeList($SLASH_PREFIX);
d8359ff @BrianAker Fry :)
BrianAker authored
701 my $theme = (sort keys %$themes)[0];
702 $sample_plugins = join(",", sort keys %{$themes->{$theme}{plugin}});
703 }
704 $sample_plugins = ", e.g.:\n\t\t\t-P$sample_plugins" if $sample_plugins;
705
706 # Remember to doublecheck these match getopts()!
707 print <<EOT;
708
709 Usage: $PROGNAME [OPTIONS]
710
711 This will create a new Slash site. You must provide a virtual
712 user, which has already been set up in DBIx::Password, and the
713 target database must already exist and be accessible by the
714 given virtual user.
715
716 Main options:
717 -h Help (this message)
718 -v Version
719 -u Virtual user
2e9de55 @jamiemccarthy Clarify some recommendations and other language; add a "last chance
jamiemccarthy authored
720 -f Skip 'last chance' prompt (force installation -- combine
721 this with the other opts below to eliminate interaction)
d8359ff @BrianAker Fry :)
BrianAker authored
722
723 Site options:
724 -H Hostname
725 -n Site name
f92d502 @pudge Add a few more options
pudge authored
726 -x Use '*' as VirtualHost name (boolean)
d8359ff @BrianAker Fry :)
BrianAker authored
727 -R Reuse hostname as site name (boolean)
f92d502 @pudge Add a few more options
pudge authored
728 -L Install files in htdocs/ and tasks/ using symlinks (boolean)
729 -i Include the specified file into the site configuration
730 -T Theme to use
d8359ff @BrianAker Fry :)
BrianAker authored
731 -P Comma-separated list of plugin names$sample_plugins
bf1f057 @pudge Misc. fixes
pudge authored
732 ("ALL"/"DEFAULT" avoid prompt, do what you'd expect)
d8359ff @BrianAker Fry :)
BrianAker authored
733
734 User options:
735 -a Admin name
736 -e Admin email
737 -p Admin password
738 -o Installation owner
739 -g Installation group
740
741 EOT
742 exit;
743 }
744
745 sub version {
746 print <<EOT;
747
748 $PROGNAME $VERSION
749
750 This code is a part of Slash, and is released under the GPL.
c0e7999 @pudge Update 2005, OSTG, etc.
pudge authored
751 Copyright 1997-2005 by Open Source Technology Group. See README
d8359ff @BrianAker Fry :)
BrianAker authored
752 and COPYING for more information, or see http://slashcode.com/.
753
754 EOT
755 exit;
756 }
757
758 __END__
Something went wrong with that request. Please try again.