-
Notifications
You must be signed in to change notification settings - Fork 0
/
hostingsetup.php
187 lines (152 loc) · 6.63 KB
/
hostingsetup.php
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
// Once the form is submitted, we setup the server
if (!empty($_POST)) {
$return = array();
$ss4 = false;
if (isset($_POST["ss4"]) && !empty($_POST["ss4"])) {
$ss4 = true;
}
$dbuser = $_POST["dbuser"];
$dbpass = $_POST["dbpass"];
$dbname = $_POST["dbname"];
$defaultdomain = $_POST["defaultdomain"];
$adminemail = $_POST["adminemail"];
$adminpass = $_POST["adminpass"];
// First create scripts folder
$return[] = "Setting up scripts dir.";
if (!file_exists('../scripts')) {
mkdir('../scripts');
}
// Now download and install sake
if (!$ss4) {
$return[] = "Installing Sake...";
copy("https://raw.githubusercontent.com/silverstripe/silverstripe-framework/3.6/sake", "../scripts/sake");
chmod("../scripts/sake", 0755);
}
// Download and install sspak
$return[] = "Installing sspak...";
copy("https://silverstripe.github.io/sspak/sspak.phar", "../scripts/sspak");
chmod("../scripts/sspak", 0755);
// Download and install SSPAK backup script
$return[] = "Installing sspak backup...";
copy("https://raw.githubusercontent.com/i-lateral/scripts/master/sspaksimplebackup.sh", "../scripts/sspaksimplebackup.sh");
chmod("../scripts/sspaksimplebackup.sh", 0755);
// Install Silverstripe deployment script
$return[] = "Installing deployment script...";
copy("https://raw.githubusercontent.com/i-lateral/scripts/master/deployment.sh", "../scripts/deployment.sh");
chmod("../scripts/deployment.sh", 0755);
// Now add .bash_profile
$return[] = "Setting up Bash Profile";
$bash_file = '../.bash_profile';
$handle = fopen($bash_file, 'w') or die('Cannot open file: ' . $bash_file);
$data = 'PATH=$PATH:~/scripts';
fwrite($handle, $data);
fclose($handle);
// Now add _ss_environment
$return[] = "Adding SS Environment";
if ($ss4) {
$env_file = '../.env';
} else {
$env_file = '../_ss_environment.php';
}
$handle = fopen($env_file, 'w') or die('Cannot open file: ' . $env_file);
$ss3_data = "<?php
/* What kind of environment is this: development, test, or live (ie, production)? */
define('SS_ENVIRONMENT_TYPE', 'live');
/* Database connection */
define('SS_DATABASE_SERVER', 'localhost');
define('SS_DATABASE_USERNAME', '$dbuser');
define('SS_DATABASE_PASSWORD', '$dbpass');
define('SS_DATABASE_NAME', '$dbname');
/* Command Line Access */
global \$_FILE_TO_URL_MAPPING;
\$_FILE_TO_URL_MAPPING['/var/www/vhosts/$defaultdomain/httpdocs'] = 'http://$defaultdomain';
/* Configure a default username and password to access the CMS on all sites in this environment. */
define('SS_DEFAULT_ADMIN_USERNAME', '$adminemail');
define('SS_DEFAULT_ADMIN_PASSWORD', '$adminpass');";
$ss4_data = "# Base URL of site and env type
SS_BASE_URL='http://$defaultdomain'
SS_ENVIRONMENT_TYPE='live'
# Database Config
SS_DATABASE_CLASS='MySQLPDODatabase'
SS_DATABASE_SERVER='localhost'
SS_DATABASE_NAME='$dbname'
SS_DATABASE_USERNAME='$dbuser'
SS_DATABASE_PASSWORD='$dbpass'
# Default login
SS_DEFAULT_ADMIN_USERNAME='$adminemail'
SS_DEFAULT_ADMIN_PASSWORD='$adminpass'";
if ($ss4) {
$data = $ss4_data;
} else {
$data = $ss3_data;
}
fwrite($handle, $data);
fclose($handle);
$return[] = "Setup Complete";
$result_html = implode($return, "<br/>");
} else {
$result_html = null;
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-push-4">
<br/>
<br/>
<div class="panel panel-default">
<div class="panel-heading text-center">
Prep this server
</div>
<div class="panel-body">
<?php if ($result_html) {
echo "<p class=\"alert alert-info\">$result_html</p>";
} ?>
<form action="hostingsetup.php" method="post">
<div class="form-group">
<label for="dbname">What is the DB name?</label>
<input type="text" class="form-control" name="dbname" required>
</div>
<div class="form-group">
<label for="dbuser">What is the DB username?</label>
<input type="text" class="form-control" name="dbuser" required>
</div>
<div class="form-group">
<label for="dbpass">What is the DB password?</label>
<input type="password" class="form-control" name="dbpass" required>
</div>
<div class="form-group">
<label for="adminemail">What is the SS admin email?</label>
<input type="text" class="form-control" name="adminemail" required>
</div>
<div class="form-group">
<label for="adminpass">What is the SS admin password?</label>
<input type="password" class="form-control" name="adminpass" required>
</div>
<div class="form-group">
<label for="defaultdomain">What is the default domain (WITHOUT HTTP)?</label>
<input type="text" class="form-control" name="defaultdomain" required>
</div>
<div class="form-group">
<label class="checkbox-inline">
<input type="checkbox" id="ss4" name="ss4" value="1">
SilverStripe 4?
</label>
</div>
<div class="text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>