Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 385 lines (328 sloc) 10.25 kB
#!/usr/bin/perl -w
# This code is a part of Slash, which is Copyright 1997-2001 OSDN, and
# released under the GPL. See README and COPYING for more information.
# $Id$
use strict;
use File::Copy;
use File::Find;
use File::Path;
use Slash::DB;
use Getopt::Std;
use Slash::Install;
# This is the uber install script.
# -Brian (brian@tangent.org)
my %opts;
usage() unless getopts('h:o:g:s:a:e:p:?r', \%opts);
usage() if $opts{'?'};
$| = 1;
my $prefix = "/usr/local/slash";
my $prefix_site = "/usr/local/slash/site";
my( $user, $owner, $owner_id, $group, $group_id, $password,
$sitename, $username, $realname, $email, $dbh, @create, $sql,
@sql, $hostname, $hostname_f, $host_noport, $httpd, %slash_sites,
$driver, $theme
);
my %drivers = (
Pg => 'postgresql',
mysql => 'mysql',
oracle => 'oracle'
);
usage() unless ($ARGV[0]);
unless (DBIx::Password::checkVirtualUser($ARGV[0])) {
print "You did not supply a valid DBIx::Password virtual name.\n";
exit;
}
$driver = $drivers{DBIx::Password::getDriver($ARGV[0])};
my $install = Slash::Install->new($ARGV[0]);
eval { require DBIx::Password };
if ($@) {
print "Doesn't look like you have DBIx::Password installed.\n";
print "Run the CPAN tool and install DBIx::Password.\n";
exit;
}
eval { require Template };
if ($@) {
print "Doesn't look like you have Bundle::Slash installed.\n";
print "Run the CPAN tool and install Bundle::Slash.\n";
exit;
}
$user = $ARGV[0];
$dbh = DBIx::Password->connect($user);
unless ($dbh) {
print "Are you sure the database is up and running?\n";
exit;
}
END { $dbh->disconnect if $dbh }
chomp($hostname_f = `hostname -f`);
unless ($opts{'h'}) {
print "\nWhat is hostname of your slash site
(e.g., www.slashdot.org)? [$hostname_f] ";
chomp($hostname = <STDIN>);
$hostname ||= $hostname_f;
} else {
$hostname = $opts{'h'};
}
($host_noport = $hostname) =~ s/:.+$//;
unless ($opts{'o'}) {
print "\nWhat user would you like to run your slash site as? [nobody] ";
chomp($owner = <STDIN>);
$owner ||= 'nobody';
} else {
$owner = $opts{'o'};
}
$owner_id = getpwnam($owner) or die "$owner is not a valid user name.\n";
unless ($opts{'g'}) {
print "\nWhat group would you like to run your slash site under? [nobody] ";
chomp($group = <STDIN>);
$group ||= 'nobody';
} else {
$group = $opts{'g'};
}
$group_id = getgrnam($group) or die "$group is not a valid group name.\n";
if($opts{'r'}) {
$sitename = $host_noport;
} else {
unless ($opts{'s'}) {
print "\nOK, I am planning on user $host_noport as the unique name
for the slash site. If this is not ok, you need to fill in
something else here. [$host_noport] ";
chomp($sitename = <STDIN>);
$sitename ||= $host_noport;
} else {
$sitename = $opts{'s'};
}
}
# themes
print "\nWhich theme do you want to use?\n";
my $x;
#---------------------------------------------------
opendir(THEMEDIR, "$prefix/themes");
my %themes;
$x = 0;
while(my $dir = readdir(THEMEDIR)) {
chomp($dir);
next if $dir =~ /^\.$/;
next if $dir =~ /^\.\.$/;
next if $dir =~ /^CVS$/;
$x++;
$themes{$x}->{'order'} = $x;
$themes{$x}->{'dir'} = "$prefix/themes/$dir/";
$themes{$x}->{'name'} = $dir;
print "$themes{$x}->{'order'}.\t$dir\n";
open(THEME,"<$prefix/themes/$dir/PLUGIN") or next;
my @info = <THEME>;
chomp(@info);
for(@info) {
my ($key, $val) = split(/=/, $_, 2);
$key = lc($key);
$themes{$x}->{$key} = $val;
}
print "\t$themes{$x}->{'description'}\n" if $themes{$dir}->{'description'};
}
chomp($theme = <STDIN>);
$theme ||= '0';
$theme = $themes{$theme}->{dir};
#---------------------------------------------------
print "\nPlease select which plugins you would like?\n";
my $plugins = $install->getPluginList($prefix);
for (sort keys %$plugins) {
print "$plugins->{$_}{'order'}.\t$_ $plugins->{$_}{'description'}\n";
}
my @answers;
my $select = 'a';
print "Hit 'a' to select all, otherwise select comma separated numbers or 'q' to quit\n";
while($select ne 'q'){
chomp($select = <STDIN>);
if($select =~ /^\d\,/) {
@answers = split(/\,/,$select);
last;
}
elsif($select eq 'a') {
for(keys %$plugins) {
push @answers, $plugins->{$_}{'order'};
}
last;
} elsif($select ne 'q') {
push @answers, $select;
}
}
unless ($opts{'a'}) {
print "\nOK, we need to create an admin account;
give us a name (8 characters only please). [$owner] ";
chomp($username = <STDIN>);
$username ||= $owner;
} else {
$username = $opts{'a'};
}
unless ($opts{'p'}) {
print "\nWhat is the password for the account? ";
chomp($password = <STDIN>);
} else {
$password = $opts{'p'};
}
die "You need to give us a password.\n" unless $password;
unless ($opts{'e'}) {
print "\nWhat is the email address of the account? [$username\@$host_noport] ";
chomp($email = <STDIN>);
$email ||= "$owner\@$host_noport";
} else {
$email = $opts{'e'};
}
# Dump in the schema then pepper with a trace of your own theme
open(CREATE, "< $prefix/sql/$driver/schema.sql")
or die "Can't open $prefix/sql/$driver/schema.sql: $!.\n";
while (<CREATE>) {
chomp;
next if /^#/;
next if /^$/;
next if /^ $/;
push @create, $_;
}
close (CREATE);
$sql = join '', @create;
@sql = split /;/, $sql;
open(DUMP,"< $theme/sql/$driver/datadump.sql")
or die "Can't open $theme/sql/$driver/datadump.sql: $!.\n";
while(<DUMP>) {
next unless /^INSERT/;
chomp;
s/www\.example\.com/$hostname/g;
s/admin\@example\.com/$email/g;
push @sql, $_;
}
close(DUMP);
open(DUMP,"< $theme/sql/$driver/prep.sql");
while(<DUMP>) {
chomp;
push @sql, $_;
}
close(DUMP);
for (@sql) {
next unless $_;
unless ($dbh->do($_)) {
print "Failed on :$_:\n";
}
}
$dbh->do("UPDATE vars SET value = " . $dbh->quote("$prefix_site/$sitename/logs") . " WHERE name = 'logdir'");
$dbh->do("UPDATE vars SET value = " . $dbh->quote("$prefix_site/$sitename/htdocs") . " WHERE name = 'basedir'");
$dbh->do("UPDATE vars SET value = " . $dbh->quote("$prefix_site/$sitename") . " WHERE name = 'datadir'");
$dbh->do("UPDATE vars SET value = " . $dbh->quote($sitename) . " WHERE name = 'siteid'");
mkpath "$prefix_site/$sitename", 0, 0775;
mkpath "$prefix_site/$sitename/logs", 0, 0775;
mkpath "$prefix_site/$sitename/htdocs", 0, 0775;
mkpath "$prefix_site/$sitename/backups", 0, 0775;
mkpath "$prefix_site/$sitename/sbin", 0, 0775;
find(sub {
my $f1 = $File::Find::name;
(my $f2 = $f1) =~ s|^$theme/htdocs/|$prefix_site/$sitename/htdocs/|;
if (-d $f1) {
mkpath $f2, 0, 0775;
} else {
copy $f1, $f2;
chmod((stat(_))[2], $f2);
}
}, "$theme/htdocs/");
$install->create({ name => 'admin', value => $username});
$install->create({ name => 'adminmail', value => $email});
$install->create({ name => 'theme', value => $theme});
$install->create({ name => 'owner', value => $owner});
$install->create({ name => 'owner_id', value => $owner_id});
$install->create({ name => 'group', value => $group});
$install->create({ name => 'group_id', value => $group_id});
$install->create({ name => 'siteid', value => $sitename});
$install->create({ name => 'basedomain', value => $hostname});
$install->create({ name => 'driver', value => $driver});
$install->create({ name => 'base_install_directory', value => $prefix});
$install->create({ name => 'site_install_directory', value => "$prefix_site/$sitename"});
$install->create({ name => 'db_driver', value => "$driver"});
my $time = localtime();
$install->create({ name => 'installed', value => $time});
for(@answers) {
$install->create({ name => 'plugin', value => $_});
}
$install->installPlugin(\@answers);
my $slashdb = Slash::DB->new($ARGV[0]);
my $uid = $slashdb->createUser($username, $email, $username);
$slashdb->setUser($uid, {
passwd => $password,
author => 1,
seclev => 10000
});
# Now, lets update slash.sites
if (open(SLASHSITES, "< $prefix/slash.sites")) {
while (<SLASHSITES>) {
chomp;
my($dbuser) = split /:/;
$slash_sites{$dbuser} = 1;
}
close(SLASHSITES);
}
unless (exists $slash_sites{$user}) {
open(SLASHSITES, ">> $prefix/slash.sites")
or die "Can't append to $prefix/slash.sites: $!.\n";
print SLASHSITES "$user:$owner\n";
close(SLASHSITES);
}
find(sub { chown $owner_id, $group_id, $_ }, "$prefix_site/$sitename");
apache_site_conf();
$dbh->disconnect;
install_message();
sub usage {
usage() unless getopts('h:o:g:s:a:e:p:?r', \%opts);
print "Usage:install-slashsite [OPTIONS] <DBIx:Password Virtual User>\n";
print "\t?: Gives you this list.\n";
print "\th: Hostname to use.\n";
print "\to: Owner to use.\n";
print "\tg: Group to use.\n";
print "\ts: Sitename to use.\n";
print "\ta: Admin name to use.\n";
print "\te: Admin's email.\n";
print "\tp: The admin password.\n";
print "\tr: Reuse the hostname minus the port as the sitename.\n";
print "\tt: Choose your theme.\n";
print "\ti: Install all plugins.\n";
print "\n\tIf no virtual user is given the install will not run\n\n";
exit();
}
sub apache_site_conf {
#Ok, I should fix this at somepoint to extract port
my $text = qq|
<VirtualHost $sitename:80>
ServerAdmin $email
DocumentRoot $prefix_site/$sitename/htdocs
ServerName $sitename
ErrorLog logs/${sitename}_error_log
CustomLog logs/${sitename}_access_log common
SlashVirtualUser $ARGV[0]
ErrorDocument 404 /404.pl
PerlAccessHandler Slash::Apache::User::handler
# Enable the line below if you are worried about performance
#PerlTransHandler Slash::Apache::IndexHandler
PerlLogHandler Slash::Apache::Log
</VirtualHost>
|;
my $file = "$prefix_site/$sitename/$sitename.conf";
open(FILE, '>' . $file);
print FILE $text;
close(FILE);
open(FILE, ">>$prefix/httpd/slash.conf");
print FILE "Include $file\n";
close(FILE);
}
sub install_message {
my $text = qq|
Unless any errors reported themself during the install you should now
have a slashsite. You will either need to edit your httpd.conf file
unless you are have slash handle it. The correct syntax can be found in:
$prefix_site/$sitename/$sitename.conf
You may want to take a look at it. If you are using virtual hosting by
hostname you may also need to add a NameVirtualHost to your httpd.conf.
To restart apache do:
apachectl stop
apachectl start
Have fun with your new site. You should also consider registering it:
http://slashcode.com/sites.shtml
|;
print $text
}
__END__
Jump to Line
Something went wrong with that request. Please try again.