Added cli installation
This commit is contained in:
+102
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2019 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
if (substr(php_sapi_name(), 0, 3) != 'cli') die('The file can be run only via CLI.');
|
||||
|
||||
$options = getopt("a:d:");
|
||||
|
||||
if (empty($options['a'])) {
|
||||
fwrite(\STDOUT, "Error: the option [-a] is required.\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
$allPostData = [];
|
||||
|
||||
if (!empty($options['d'])) {
|
||||
parse_str($options['d'], $allPostData);
|
||||
|
||||
if (empty($allPostData) || !is_array($allPostData)) {
|
||||
fwrite(\STDOUT, "Error: Incorrect input data.\n");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$action = $options['a'];
|
||||
$allPostData['action'] = $action;
|
||||
|
||||
chdir(dirname(__FILE__));
|
||||
set_include_path(dirname(__FILE__));
|
||||
require_once('../bootstrap.php');
|
||||
|
||||
$_SERVER['SERVER_SOFTWARE'] = 'Cli';
|
||||
|
||||
require_once('core/PostData.php');
|
||||
$postData = new PostData();
|
||||
$postData->set($allPostData);
|
||||
|
||||
require_once('core/InstallerConfig.php');
|
||||
$installerConfig = new InstallerConfig();
|
||||
|
||||
if ($installerConfig->get('isInstalled')) {
|
||||
fwrite(\STDOUT, "Error: EspoCRM is already installed.\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$installerConfig->get('cliSessionId')) {
|
||||
session_start();
|
||||
$installerConfig->set('cliSessionId', session_id());
|
||||
$installerConfig->save();
|
||||
}
|
||||
|
||||
$sessonId = session_id($installerConfig->get('cliSessionId'));
|
||||
|
||||
ob_start();
|
||||
|
||||
try {
|
||||
require('install/index.php');
|
||||
} catch (\Throwable $e) {
|
||||
fwrite(\STDOUT, "Error: ". $e->getMessage() .".\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if (preg_match('/"success":false/i', $result)) {
|
||||
$resultData = json_decode($result, true);
|
||||
if (empty($resultData)) {
|
||||
fwrite(\STDOUT, "Error: Unexpected error occurred.\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
fwrite(\STDOUT, "Error: ". (!empty($resultData['errors']) ? print_r($resultData['errors'], true) : $resultData['errorMsg']) .".\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
fwrite(\STDOUT, "Done.\n");
|
||||
+16
-12
@@ -248,29 +248,33 @@ class Installer
|
||||
* @param string $language
|
||||
* @return bool
|
||||
*/
|
||||
public function saveData($database, $language)
|
||||
public function saveData(array $saveData)
|
||||
{
|
||||
$initData = include('install/core/afterInstall/config.php');
|
||||
$siteUrl = $this->getSystemHelper()->getBaseUrl();
|
||||
$databaseDefaults = $this->app->getContainer()->get('config')->get('database');
|
||||
|
||||
$data = [
|
||||
'database' => array_merge($databaseDefaults, $database),
|
||||
'language' => $language,
|
||||
'siteUrl' => $siteUrl,
|
||||
'database' => array_merge($databaseDefaults, $saveData['database']),
|
||||
'language' => $saveData['language'],
|
||||
'siteUrl' => !empty($saveData['siteUrl']) ? $saveData['siteUrl'] : $this->getSystemHelper()->getBaseUrl(),
|
||||
'passwordSalt' => $this->getPasswordHash()->generateSalt(),
|
||||
'cryptKey' => $this->getContainer()->get('crypt')->generateKey(),
|
||||
'hashSecretKey' => \Espo\Core\Utils\Util::generateSecretKey(),
|
||||
];
|
||||
|
||||
$owner = $this->getFileManager()->getPermissionUtils()->getDefaultOwner(true);
|
||||
$group = $this->getFileManager()->getPermissionUtils()->getDefaultGroup(true);
|
||||
|
||||
if (!empty($owner)) {
|
||||
$data['defaultPermissions']['user'] = $owner;
|
||||
if (empty($saveData['defaultPermissions']['user'])) {
|
||||
$saveData['defaultPermissions']['user'] = $this->getFileManager()->getPermissionUtils()->getDefaultOwner(true);
|
||||
}
|
||||
if (!empty($group)) {
|
||||
$data['defaultPermissions']['group'] = $group;
|
||||
|
||||
if (empty($saveData['defaultPermissions']['group'])) {
|
||||
$saveData['defaultPermissions']['group'] = $this->getFileManager()->getPermissionUtils()->getDefaultGroup(true);
|
||||
}
|
||||
|
||||
if (!empty($saveData['defaultPermissions']['user'])) {
|
||||
$data['defaultPermissions']['user'] = $saveData['defaultPermissions']['user'];
|
||||
}
|
||||
if (!empty($saveData['defaultPermissions']['group'])) {
|
||||
$data['defaultPermissions']['group'] = $saveData['defaultPermissions']['group'];
|
||||
}
|
||||
|
||||
$data = array_merge($data, $initData);
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
class PostData
|
||||
{
|
||||
protected $data = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
if (isset($_POST) && is_array($_POST)) {
|
||||
$this->data = $_POST;
|
||||
}
|
||||
}
|
||||
|
||||
public function set($name, $value = null)
|
||||
{
|
||||
if (!is_array($name)) {
|
||||
$name = [
|
||||
$name => $value
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($name as $key => $value) {
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
if (array_key_exists($name, $this->data)) {
|
||||
return $this->data[$name];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
@@ -25,13 +25,13 @@
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
************************************************************************/
|
||||
|
||||
ob_start();
|
||||
$result = array('success' => true, 'errorMsg' => '');
|
||||
|
||||
// save settings
|
||||
$data = array(
|
||||
$database = array(
|
||||
'driver' => 'pdo_mysql',
|
||||
'dbname' => $_SESSION['install']['db-name'],
|
||||
'user' => $_SESSION['install']['db-user-name'],
|
||||
@@ -41,10 +41,22 @@ $host = $_SESSION['install']['host-name'];
|
||||
if (strpos($host,':') === false) {
|
||||
$host .= ":";
|
||||
}
|
||||
list($data['host'], $data['port']) = explode(':', $host);
|
||||
list($database['host'], $database['port']) = explode(':', $host);
|
||||
|
||||
$lang = (!empty($_SESSION['install']['user-lang']))? $_SESSION['install']['user-lang'] : 'en_US';
|
||||
if (!$installer->saveData($data, $lang)) {
|
||||
$saveData = [
|
||||
'database' => $database,
|
||||
'language' => !empty($_SESSION['install']['user-lang']) ? $_SESSION['install']['user-lang'] : 'en_US',
|
||||
'siteUrl' => !empty($_SESSION['install']['site-url']) ? $_SESSION['install']['site-url'] : null,
|
||||
];
|
||||
|
||||
if (!empty($_SESSION['install']['default-permissions-user']) && !empty($_SESSION['install']['default-permissions-group'])) {
|
||||
$saveData['defaultPermissions'] = [
|
||||
'user' => $_SESSION['install']['default-permissions-user'],
|
||||
'group' => $_SESSION['install']['default-permissions-group'],
|
||||
];
|
||||
}
|
||||
|
||||
if (!$installer->saveData($saveData)) {
|
||||
$result['success'] = false;
|
||||
$result['errorMsg'] = $langs['messages']['Can not save settings'];
|
||||
}
|
||||
|
||||
@@ -50,16 +50,18 @@ foreach ($phpRequiredList as $name => $details) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($result['success'] && !empty($_REQUEST['dbName']) && !empty($_REQUEST['hostName']) && !empty($_REQUEST['dbUserName'])) {
|
||||
$allPostData = $postData->getAll();
|
||||
|
||||
if ($result['success'] && !empty($allPostData['dbName']) && !empty($allPostData['hostName']) && !empty($allPostData['dbUserName'])) {
|
||||
$connect = false;
|
||||
|
||||
$dbName = trim($_REQUEST['dbName']);
|
||||
if (strpos($_REQUEST['hostName'],':') === false) {
|
||||
$_REQUEST['hostName'] .= ":";
|
||||
$dbName = trim($allPostData['dbName']);
|
||||
if (strpos($allPostData['hostName'],':') === false) {
|
||||
$allPostData['hostName'] .= ":";
|
||||
}
|
||||
list($hostName, $port) = explode(':', trim($_REQUEST['hostName']));
|
||||
$dbUserName = trim($_REQUEST['dbUserName']);
|
||||
$dbUserPass = trim($_REQUEST['dbUserPass']);
|
||||
list($hostName, $port) = explode(':', trim($allPostData['hostName']));
|
||||
$dbUserName = trim($allPostData['dbUserName']);
|
||||
$dbUserPass = trim($allPostData['dbUserPass']);
|
||||
|
||||
$databaseParams = [
|
||||
'host' => $hostName,
|
||||
@@ -84,7 +86,7 @@ if ($result['success'] && !empty($_REQUEST['dbName']) && !empty($_REQUEST['hostN
|
||||
$databaseRequiredList = $installer->getSystemRequirementList('database', true, ['database' => $databaseParams]);
|
||||
|
||||
foreach ($databaseRequiredList as $name => $details) {
|
||||
if (!$details['acceptable']) {
|
||||
if (!$details['acceptable']) {
|
||||
|
||||
switch ($details['type']) {
|
||||
case 'version':
|
||||
|
||||
+19
-7
@@ -27,11 +27,23 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
session_start();
|
||||
require_once('../bootstrap.php');
|
||||
if (session_status() !== \PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
if (file_exists('../bootstrap.php')) {
|
||||
require_once('../bootstrap.php');
|
||||
}
|
||||
|
||||
if (!isset($postData)) {
|
||||
require_once('core/PostData.php');
|
||||
$postData = new PostData();
|
||||
}
|
||||
|
||||
$allPostData = $postData->getAll();
|
||||
|
||||
//action
|
||||
$action = (!empty($_POST['action']))? $_POST['action'] : 'main';
|
||||
$action = (!empty($allPostData['action']))? $allPostData['action'] : 'main';
|
||||
require_once('core/Utils.php');
|
||||
if (!Utils::checkActionExists($action)) {
|
||||
die('This page does not exist.');
|
||||
@@ -40,8 +52,8 @@ if (!Utils::checkActionExists($action)) {
|
||||
// temp save all settings
|
||||
$ignoredFields = array('installProcess', 'dbName', 'hostName', 'dbUserName', 'dbUserPass', 'dbDriver');
|
||||
|
||||
if (!empty($_POST)) {
|
||||
foreach ($_POST as $key => $val) {
|
||||
if (!empty($allPostData)) {
|
||||
foreach ($allPostData as $key => $val) {
|
||||
if (!in_array($key, $ignoredFields)) {
|
||||
$_SESSION['install'][$key] = trim($val);
|
||||
}
|
||||
@@ -64,7 +76,7 @@ $systemHelper = new SystemHelper();
|
||||
|
||||
$systemConfig = include('application/Espo/Core/defaults/systemConfig.php');
|
||||
if (isset($systemConfig['requiredPhpVersion']) && version_compare(PHP_VERSION, $systemConfig['requiredPhpVersion'], '<')) {
|
||||
die(str_replace('{minVersion}', $systemConfig['requiredPhpVersion'], $sanitizedLangs['messages']['phpVersion']) . '.');
|
||||
die(str_replace("{minVersion}", $systemConfig['requiredPhpVersion'], $sanitizedLangs['messages']['phpVersion']) . ".\n");
|
||||
}
|
||||
|
||||
if (!$systemHelper->initWritable()) {
|
||||
@@ -74,7 +86,7 @@ if (!$systemHelper->initWritable()) {
|
||||
$message = str_replace('{*}', $dir, $message);
|
||||
$message = str_replace('{C}', $systemHelper->getPermissionCommands(array($dir, ''), '775'), $message);
|
||||
$message = str_replace('{CSU}', $systemHelper->getPermissionCommands(array($dir, ''), '775', true), $message);
|
||||
die($message);
|
||||
die($message . "\n");
|
||||
}
|
||||
|
||||
require_once ('install/vendor/smarty/libs/Smarty.class.php');
|
||||
|
||||
Reference in New Issue
Block a user