-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaravel.pl
386 lines (304 loc) · 11.2 KB
/
Laravel.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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
##
##
##Author: Evan Garcia
##
##
## if you have a older version of php as well as 5.6 or higher ##
## Make sure you Set Your PHPVesion for this virtual server to PHP 5.6 or higher ##
# script_Laravel_desc()
sub script_Laravel_desc
{
return "Laravel";
}
sub script_Laravel_uses
{
return ( "php" );
}
sub script_Laravel_longdesc
{
return "Installs Composer and Laravel For Virtual Server";
}
# script_Laravel_versions()
sub script_Laravel_versions
{
return ( "Latest" );
}
sub script_Laravel_category
{
return "Framework";
}
sub script_Laravel_php_vers
{
local ($d, $ver) = @_;
if ($ver >= 3.2) {
return ( 5 );
}
else {
return ( 4, 5 );
}
}
sub script_Laravel_php_modules
{
return ("mysql", "gd", "mbstring");
}
sub script_Laravel_php_optional_modules
{
return ("curl");
}
sub script_Laravel_dbs
{
return ("mysql");
}
# script_Laravel_depends(&domain, version)
sub script_Laravel_depends
{
local ($d, $ver) = @_;
local @rv;
# Check for MySQL 4+
&require_mysql();
if (&mysql::get_mysql_version() < 4) {
push(@rv, "Laravel requires MySQL version 4 or higher");
}
# Check for PHP 5.6+
local $phpv = &get_php_version(5, $d);
if (!$phpv) {
push(@rv, "Could not work out exact PHP version");
}
#~ elsif ($phpv < 5.6) {##for php versions 5.6 and up
elsif ($phpv < 5.2) { ## if you have a older version of php as well as 5.6 or higher ## get_php_version doesnt always return the higher if you have multiple installed
push(@rv, "Laravel requires PHP version 5.6 or later");
}
return @rv;
}
# script_Laravel_params(&domain, version, &upgrade-info)
# Returns HTML for table rows for options for installing Laravel
sub script_Laravel_params
{
local ($d, $ver, $upgrade) = @_;
local $rv;
local $hdir = &public_html_dir($d, 1);
if ($upgrade) {
# Options are fixed when upgrading
local ($dbtype, $dbname) = split(/_/, $upgrade->{'opts'}->{'db'}, 2);
$rv .= &ui_table_row("Database for Laravel tables", $dbname);
local $dir = $upgrade->{'opts'}->{'dir'};
$dir =~ s/^$d->{'home'}\///;
$rv .= &ui_table_row("Install directory", $dir);
}
else {
# Show editable install options
local @dbs = &domain_databases($d, [ "mysql" ]);
$rv .= &ui_table_row("Database for Laravel tables",
&ui_database_select("db", undef, \@dbs, $d, "Laravel"));
}
return $rv;
}
# script_Laravel_parse(&domain, version, &in, &upgrade-info)
# Returns either a hash ref of parsed options, or an error string
sub script_Laravel_parse
{
local ($d, $ver, $in, $upgrade) = @_;
if ($upgrade) {
# Options are always the same
return $upgrade->{'opts'};
}
else {
local $hdir = &public_html_dir($d, 0);
local $dir = $hdir;
local ($newdb) = ($in->{'db'} =~ s/^\*//);
return { 'db' => $in->{'db'},
'newdb' => $newdb,
'dir' => $dir,
'path' => "/", };
}
}
# script_Laravel_check(&domain, version, &opts, &upgrade-info)
# Returns an error message if a required option is missing or invalid
sub script_Laravel_check
{
local ($d, $ver, $opts, $upgrade) = @_;
$opts->{'db'} || return "Missing database";
if (-r "$d->{'home'}/.composer") {
return "Laravel appears to be already installed in the selected directory";
}
return undef;
}
# script_Laravel_files(&domain, version, &opts, &upgrade-info)
# Returns a list of files needed by Laravel, each of which is a hash ref
# containing a name, filename and URL
sub script_Laravel_files
{
local ($d, $ver, $opts, $upgrade) = @_;
return undef;
}
sub script_Laravel_commands
{
return ("unzip");
}
# script_Laravel_install(&domain, version, &opts, &files, &upgrade-info)
# Actually installs Laravel, and returns either 1 and an informational
# message, or 0 and an error
sub script_Laravel_install
{
local ($d, $version, $opts, $files, $upgrade) = @_;
local ($out, $ex);
local $url = &script_path_url($d, $opts);
#~ return (0, "yay done");
if ($opts->{'newdb'} && !$upgrade) {
local $err = &create_script_database($d, $opts->{'db'});
return (0, "Database creation failed : $err") if ($err);
}
local ($dbtype, $dbname) = split(/_/, $opts->{'db'}, 2);
local $dbuser = $dbtype eq "mysql" ? &mysql_user($d) : &postgres_user($d);
local $dbpass = $dbtype eq "mysql" ? &mysql_pass($d) : &postgres_pass($d, 1);
local $dbphptype = $dbtype eq "mysql" ? "mysql" : "psql";
local $dbhost = &get_database_host($dbtype);
local $dberr = &check_script_db_connection($dbtype, $dbname, $dbuser, $dbpass);
return (0, "Database connection failed : $dberr") if ($dberr);
# Extract tar file to temp dir and copy to target
local $verdir = "Laravel";
##workaround ## failed when using run_as_domain_user##so we just sudo to that user and run the commads
$shell_out = <<`SHELL`;
cd $d->{'home'}
EXPECTED_SIGNATURE=`wget -q -O - https://composer.github.io/installer.sig`
sudo -H -u $d->{'user'} whoami
sudo -H -u $d->{'user'} php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo -H -u $d->{'user'} php -r "if (hash_file('SHA384', 'composer-setup.php') === $EXPECTED_SIGNATURE) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo -H -u $d->{'user'} php composer-setup.php
sudo -H -u $d->{'user'} php -r "unlink('composer-setup.php');"
SHELL
if ($shell_out !~ /successfully installed to/) {
return (0, "Install Composer failed: ".
"<pre>".&html_escape($shell_out)."</pre>");
}
##install laravel with composer
#~ local $icmd = "$d->{'home'}/composer.phar global require \"laravel/installer\"";##for php versions 5.6 and up
##points to our php 5.6 instread of our php 5.3 ## if you have a older version of php as well as 5.6 or higher ## this says to try and use the php 5.6
local $icmd = "export PATH=/opt/rh/rh-php56/root/usr/bin:\$PATH && $d->{'home'}/composer.phar global require \"laravel/installer\"";
local $out = &run_as_domain_user($d, $icmd);
if ($?) {
return (0, "Install Laravel failed: ".
"<pre>".$icmd."</pre><pre>".&html_escape($out)."</pre>");
}
##navigates to our home dir and creates a new laravel application
#~ local $icmd = "cd $d->{'home'} && $d->{'home'}/.composer/vendor/bin/laravel new application"##for php versions 5.6 and up
##points to our php 5.6 instread of our php 5.3 ## if you have a older version of php as well as 5.6 or higher ## this says to try and use the php 5.6
local $icmd = "export PATH=/opt/rh/rh-php56/root/usr/bin:\$PATH && cd $d->{'home'} && $d->{'home'}/.composer/vendor/bin/laravel new application";
local $out = &run_as_domain_user($d, $icmd);
if ($out !~ /Crafting application/) {
return (0, "Install Laravel Application failed: ".
"<pre>".$icmd."</pre><pre>".&html_escape($out)."</pre>");
}
local $cfileorig = "$d->{'home'}/application/.env.example";
local $cfile = "$d->{'home'}/application/.env";
# Copy and update the environment config file for laravel
if (!-r $cfile) {
&run_as_domain_user($d, "cp ".quotemeta($cfileorig)." ".
quotemeta($cfile));
local $lref = &read_file_lines_as_domain_user($d, $cfile);
local $l;
foreach $l (@$lref) {
if ($l =~ /DB_DATABASE/) {
$l = "DB_DATABASE=$dbname";
}
if ($l =~ /DB_USERNAME/) {
$l = "DB_USERNAME=$dbuser";
}
if ($l =~ /DB_HOST/) {
$l = "DB_HOST=$dbhost";
}
if ($l =~ /DB_PASSWORD/) {
$l = "DB_PASSWORD=".
&php_quotemeta($dbpass)."";
}
if ($l =~ /APP_URL/) {
$l = "APP_URL=$url";
}
}
&flush_file_lines_as_domain_user($d, $cfile);
}else{
return (0, "Laravel Application .Env file not configured: ".
"<pre>".$icmd."</pre><pre>".&html_escape($out)."</pre>");
}
##update laravel with composer and regenerate vendor files
#~ local $icmd = "cd $d->{'home'}/application && $d->{'home'}/composer.phar update";##for php versions 5.6 and up
##points to our php 5.6 instread of our php 5.3 ## if you have a older version of php as well as 5.6 or higher ## this says to try and use the php 5.6
local $icmd = "export PATH=~/.composer/vendor/bin:/opt/rh/rh-php56/root/usr/bin:\$PATH && cd $d->{'home'}/application && $d->{'home'}/composer.phar update";
local $out = &run_as_domain_user($d, $icmd);
if ($?) {
return (0, "Update Laravel failed: ".
"<pre>".$icmd."</pre><pre>".&html_escape($out)."</pre>");
}
##navigates to our application dir and creates a new laravel application key
#~ local $icmd = "cd $d->{'home'}/application && php artisan key:generate";##for php versions 5.6 and up
##points to our php 5.6 instread of our php 5.3 ## if you have a older version of php as well as 5.6 or higher ## this says to try and use the php 5.6
local $icmd = "export PATH=/opt/rh/rh-php56/root/usr/bin:\$PATH && cd $d->{'home'}/application && php artisan key:generate";
local $out = &run_as_domain_user($d, $icmd);
if ($out !~ /set successfully/) {
return (0, "Setup Laravel Application Key failed: ".
"<pre>".$icmd."</pre><pre>".&html_escape($out)."</pre>");
}
##backup our public html and point to our new document root /application/public
local $icmd = "mv $d->{'home'}/public_html $d->{'home'}/public_html_backup && ln -s $d->{'home'}/application/public $d->{'home'}/public_html";
local $out = &run_as_domain_user($d, $icmd);
if ($?) {
return (0, "Setup New document root failed: ".
"<pre>".$icmd."</pre><pre>".&html_escape($out)."</pre>");
}
#~ return (1, "Laravel installation complete. It can be accessed at <a target=_blank href='$url'>$url</a>.", "test test test", $url);
# Return a URL for the user
local $userurl = &script_path_url($d, $opts);
local $rp = $opts->{'dir'};
$rp =~ s/^$d->{'home'}\///;
return (1, "Laravel installation complete. It can be accessed at <a target=_blank href='$url'>$url</a>.", "Under $rp using $dbphptype database $dbname", $userurl);
}
# script_Laravel_uninstall(&domain, version, &opts)
# Un-installs a Laravel installation, by deleting the directory and database.
# Returns 1 on success and a message, or 0 on failure and an error
sub script_Laravel_uninstall
{
local ($d, $version, $opts) = @_;
##restore public html document root
local $icmd = "rm $d->{'home'}/public_html && mv $d->{'home'}/public_html_backup $d->{'home'}/public_html";
local $out = &run_as_domain_user($d, $icmd);
if ($?) {
return (0, "Restore public_html document root failed: ".
"<pre>".$icmd."</pre><pre>".&html_escape($out)."</pre>");
}
local $icmd = "rm -rf $d->{'home'}/application";
local $out = &run_as_domain_user($d, $icmd);
if ($?) {
return (0, "Remove Application failed : ".
"<pre>".&html_escape($icmd)."</pre><pre>".&html_escape($out)."</pre>");
}
local $icmd = "rm -rf $d->{'home'}/.composer";
local $out = &run_as_domain_user($d, $icmd);
if ($?) {
return (0, "Remove Composer failed : ".
"<pre>".&html_escape($icmd)."</pre><pre>".&html_escape($out)."</pre>");
}
unlink("$d->{'home'}/composer.phar");
# drop DB
if ($opts->{'newdb'}) {
&delete_script_database($d, $opts->{'db'});
}
return (1, "Laravel directory and tables deleted.");
}
# script_Laravel_realversion(&domain, &opts)
# Returns the real version number of some script install, or undef if unknown
sub script_Laravel_realversion
{
local ($d, $opts, $sinfo) = @_;
return undef;
}
# script_Laravel_latest(version)
# Returns a URL and regular expression or callback func to get the version
sub script_Laravel_latest
{
return undef;
}
sub script_Laravel_site
{
return 'https://laravel.com/';
}
1;