-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset-magento.php
152 lines (122 loc) · 4.73 KB
/
set-magento.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
<?php
// shell_exec('
// /usr/bin/php
// /var/www/set-magento.php
// host=mariadb
// db=db
// user=dna
// pass=secret
// web_unsecure_base_url=http://magento.dev.it
// web_secure_base_url=http://magento.dev.it
// web_cookie_cookie_domain=*.magento.dev.it
// ');
parse_str(implode('&', array_slice($argv, 1)), $_GET);
function printDebug($str) {
if (isset($_GET['debug'])) {
echo $str;
}
}
///////////////////////////////////////////
/// Config del DB
//////////////////////////////////////////
if (isset($_GET['host'])
&& isset($_GET['db'])
&& isset($_GET['user'])
&& isset($_GET['pass'])
&& isset($_GET['web_unsecure_base_url'])
&& isset($_GET['web_secure_base_url'])
&& isset($_GET['web_cookie_cookie_domain'])) {
printDebug('Mi preparo per fixare il DB');
$host = $_GET['host'];
$db = $_GET['db'];
$user = $_GET['user'];
$pass = $_GET['pass'];
try {
$pdo = new PDO('mysql:host='.$host.';dbname='.$db.'', $user, $pass);
if (isset($_GET['web_unsecure_base_url'])) {
printDebug('Cambio web unsecure base URL');
$unsecureBaseUrl = $_GET['web_unsecure_base_url'];
if ($pdo->query("UPDATE core_config_data SET value = '$unsecureBaseUrl' WHERE path LIKE 'web/unsecure/base_url'")) {
printDebug('Web unsecure base URL cambiato in ' . $unsecureBaseUrl);
} else {
printDebug('Web unsecure base URL NON cambiato in ' . $unsecureBaseUrl);
}
}
if (isset($_GET['web_secure_base_url'])) {
printDebug('Cambio web secure base URL');
$secureBaseUrl = $_GET['web_secure_base_url'];
if ($pdo->query("UPDATE core_config_data SET value = '$secureBaseUrl' WHERE path LIKE 'web/secure/base_url'")) {
printDebug('Web secure base URL cambiato in ' . $secureBaseUrl);
} else {
printDebug('Web secure base URL NON cambiato in ' . $secureBaseUrl);
}
}
if (isset($_GET['web_cookie_cookie_domain'])) {
printDebug('Cambio web cookie domain');
$cookieDomain = $_GET['web_cookie_cookie_domain'];
if ($pdo->query("UPDATE core_config_data SET value = NULL WHERE path LIKE 'web/cookie/cookie_domain'")) {
printDebug('Cookie domain cambiato in ' . $cookieDomain);
} else {
printDebug('Cookie domain NON cambiato in ' . $cookieDomain);
}
}
} catch (Exception $e) {
printDebug('Eccezione ' . $e->getMessage());
}
$pdo = null;
}
///////////////////////////////////////////
/// Config dell'ambiente
//////////////////////////////////////////
if (isset($_GET['webroot']) && isset($_GET['weburl'])) {
$webroot = $_GET['webroot'];
$weburl = $_GET['weburl'];
if (!file_exists($webroot)) {
mkdir($webroot);
printDebug('Creata directory ' . $webroot);
}
// Entro nella webroot
chdir($webroot);
// Sto in /var/www/WEBROOT
// Se è previsto un file localxml, lo butto in app/etc/
if (isset($_GET['localxml'])) {
$localXml = file_get_contents($_GET['localxml']);
file_put_contents("app/etc/local.xml", $localXml);
printDebug('Caricato il file localxml');
}
// Se è previsto un archivio media
if (isset($_GET['media'])) {
if (!file_exists("media")) {
mkdir("media");
printDebug('Creata cartella media');
}
chdir("media");
// Entrato in media, sto in /var/www/WEBROOT/media
$media = file_get_contents($_GET['media']);
file_put_contents("media.zip", $media);
shell_exec("unzip media.zip");
printDebug('Popolata cartella media');
chdir("../");
// Uscito da media, sto in /var/www/WEBROOT
}
if (isset($_GET['install-n98'])) {
$magerun = file_get_contents("https://files.magerun.net/n98-magerun.phar");
file_put_contents("n98-magerun.phar", $magerun);
printDebug('Installato n98');
}
if (isset($_GET['flush-cache'])) {
shell_exec('php n98-magerun.phar cache:clean');
shell_exec('php n98-magerun.phar cache:flush');
printDebug('Flushata cache');
}
chdir("../");
// Uscito dalla webroot, sto in /var/www
$template = file_get_contents("magento.conf.tpl");
$template = str_replace("{{SERVER_NAME}}", $weburl, $template);
$template = str_replace("{{FOLDER_NAME}}", $webroot, $template);
printDebug('Creato file di config');
chdir("sites-available");
// Sto in /var/www/sites-available
file_put_contents($webroot . ".conf", $template);
printDebug('Piazzato file di config');
}