/
addsite.pl
executable file
·112 lines (90 loc) · 3.78 KB
/
addsite.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/data/wre/prereqs/bin/perl
#-------------------------------------------------------------------
# WRE is Copyright 2005-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use lib '/data/wre/lib';
use strict;
use Getopt::Long;
use WRE::Config;
use WRE::Site;
$| = 1;
my $config = WRE::Config->new();
my ($var1, $var2, $var3, $var4, $var5, $var6, $var7, $var8, $var9, $var0, $sitename, $adminPassword,
$dbUser, $dbPassword, $dbName, $help, $fromConfig) = "";
GetOptions(
"help" => \$help,
"var1=s" => \$var1,
"var2=s" => \$var2,
"var3=s" => \$var3,
"var4=s" => \$var4,
"var5=s" => \$var5,
"var6=s" => \$var6,
"var7=s" => \$var7,
"var8=s" => \$var8,
"var9=s" => \$var9,
"var0=s" => \$var0,
"sitename=s" => \$sitename,
"adminPassword=s" => \$adminPassword,
"databaseUser=s" => \$dbUser,
"databasePassword=s" => \$dbPassword,
"databaseName=s" => \$dbName,
"fromConfig=s" => \$fromConfig,
);
my $dbAdminUser = $config->get("mysql/adminUser");
if ($help || $adminPassword eq "" || ($sitename eq "" && $fromConfig eq '')) {
print <<STOP;
Usage: $0 --sitename=www.example.com --adminPassword=123qwe
Options:
--adminPassword The password for the "$dbAdminUser" in your MySQL database.
--databaseUser The username you'd like created to access this site's database.
--databasePassword The password you'd like created to access this site's database.
--databaseName The name of the database to create in MySQL (defaults to www_site_com for the domain www.site.com).
--help This message.
--sitename The name of the site you'd like to create. For example: www.example.com
or intranet.example.com
--fromConfig Pull the sitename, dbUser and dbPassword from the referenced config file
--var0-9 A series of variables you can use to arbitrary information into the site
creation process. These variables will be exposed to all templates used to
create this site.
STOP
exit;
}
if ($fromConfig) {
use Config::JSON;
my $webguiConfig = Config::JSON->new($fromConfig);
$sitename ||= $webguiConfig->get('sitename')->[0];
$dbUser ||= $webguiConfig->get('dbuser');
$dbPassword ||= $webguiConfig->get('dbpass');
}
my $site = WRE::Site->new(
wreConfig => $config,
sitename => $sitename,
adminPassword => $adminPassword,
databaseName => $dbName,
);
if (eval {$site->checkCreationSanity}) {
$site->create({
databaseUser => $dbUser,
databasePassword => $dbPassword,
var0 => $var0,
var1 => $var1,
var2 => $var2,
var3 => $var3,
var4 => $var4,
var5 => $var5,
var6 => $var6,
var7 => $var7,
var8 => $var8,
var9 => $var9,
});
print $site->sitename." was created. Don't forget to restart the web servers and Spectre.\n";
}
else {
print $site->sitename." could not be created because: ".$@."\n";
}