Repository navigation
Expand file tree
/
Copy pathinstall-cli.php
More file actions
119 lines (105 loc) · 3.8 KB
/
Copy pathinstall-cli.php
File metadata and controls
119 lines (105 loc) · 3.8 KB
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
<?php
/**
* Non-interactive Revive Adserver installer.
*
* Bypasses the broken web installer (which checks for /var/UPGRADE and
* redirects to index.php in a loop on fresh installs). Calls Revive's own
* OA_Upgrade API directly, the same way the web installer would internally.
*
* Reads config from environment variables:
* REVIVE_DB_HOST, REVIVE_DB_NAME, REVIVE_DB_USER, REVIVE_DB_PASS
* REVIVE_ADMIN_USER, REVIVE_ADMIN_PASSWORD, REVIVE_ADMIN_EMAIL
* REVIVE_DOMAIN, REVIVE_TIMEZONE (defaults to UTC)
*
* Exits 0 on success, 1 on failure. Idempotent guard lives in entrypoint.sh.
*/
declare(strict_types=1);
const MAX_PATH = '/var/www/html';
if (php_sapi_name() !== 'cli') {
fwrite(STDERR, "ERROR: install-cli.php must be run from the CLI.\n");
exit(1);
}
$required = [
'REVIVE_DB_HOST', 'REVIVE_DB_NAME', 'REVIVE_DB_USER', 'REVIVE_DB_PASS',
'REVIVE_ADMIN_USER', 'REVIVE_ADMIN_PASSWORD', 'REVIVE_ADMIN_EMAIL',
'REVIVE_DOMAIN',
];
foreach ($required as $k) {
if (getenv($k) === false || getenv($k) === '') {
fwrite(STDERR, "ERROR: env var {$k} is required.\n");
exit(1);
}
}
$domain = getenv('REVIVE_DOMAIN');
// Pretend we're being invoked as the web installer for the right vhost,
// so saveConfig() writes var/{domain}.conf.php and not var/cli.conf.php.
$_SERVER['HTTP_HOST'] = $domain;
$_SERVER['SERVER_NAME'] = $domain;
$_SERVER['REQUEST_URI'] = '/www/admin/install.php';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = '443';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
define('phpAds_installing', true);
chdir(MAX_PATH);
require MAX_PATH . '/init.php';
// init.php doesn't pull in OA_Upgrade for us — load it explicitly.
require MAX_PATH . '/lib/OA/Upgrade/Upgrade.php';
$config = [
'database' => [
'type' => 'mysqli',
'host' => getenv('REVIVE_DB_HOST'),
'socket' => '',
'port' => '3306',
'username' => getenv('REVIVE_DB_USER'),
'password' => getenv('REVIVE_DB_PASS'),
'name' => getenv('REVIVE_DB_NAME'),
'protocol' => 'tcp',
'persistent' => false,
'mysql4_compatibility' => false,
],
'table' => [
'prefix' => 'rv_',
'type' => 'innodb',
'split' => false,
],
// OA_Upgrade::install() stores only the host in [webpath] unless we feed
// it the full host+path here. Without /www/admin etc. Revive builds admin
// URLs that point at the root, which loops the browser to itself.
'webpath' => [
'admin' => "{$domain}/www/admin",
'delivery' => "{$domain}/www/delivery",
'deliverySSL' => "{$domain}/www/delivery",
'images' => "{$domain}/www/images",
'imagesSSL' => "{$domain}/www/images",
],
];
echo "[install-cli] Running OA_Upgrade->install() ...\n";
$oUpgrade = new OA_Upgrade();
$ok = $oUpgrade->install($config);
if (!$ok) {
fwrite(STDERR, "[install-cli] OA_Upgrade->install() returned false.\n");
if (method_exists($oUpgrade, 'getMessages')) {
fwrite(STDERR, implode("\n", (array) $oUpgrade->getMessages()) . "\n");
}
exit(1);
}
echo "[install-cli] Schema + config created.\n";
echo "[install-cli] Running OA_Upgrade->putAdmin() ...\n";
$admin = [
'name' => getenv('REVIVE_ADMIN_USER'),
'email' => getenv('REVIVE_ADMIN_EMAIL'),
'pword' => getenv('REVIVE_ADMIN_PASSWORD'),
'language' => 'en',
];
$prefs = [
'timezone' => getenv('REVIVE_TIMEZONE') ?: 'UTC',
];
$oUpgrade->putAdmin($admin, $prefs);
echo "[install-cli] Admin user created: {$admin['name']} <{$admin['email']}>\n";
if (method_exists($oUpgrade, 'setOpenadsInstalledOn')) {
$oUpgrade->setOpenadsInstalledOn();
echo "[install-cli] Install marked complete.\n";
}
echo "[install-cli] Done.\n";
exit(0);