2018-04-18 05:43:23 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Core\Console;
|
|
|
|
|
|
|
|
use Asika\SimpleConsole\Console;
|
|
|
|
use dba;
|
|
|
|
use Friendica\App;
|
2018-04-23 16:56:59 -04:00
|
|
|
use Friendica\Core\Install;
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
require_once 'mod/install.php';
|
2018-04-29 12:11:24 -04:00
|
|
|
require_once 'include/dba.php';
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
class AutomaticInstallation extends Console
|
|
|
|
{
|
|
|
|
protected function getHelp()
|
|
|
|
{
|
|
|
|
return <<<HELP
|
|
|
|
Installation - Install Friendica automatically
|
|
|
|
Synopsis
|
2018-04-18 08:30:42 -04:00
|
|
|
bin/console autoinstall [-h|--help|-?] [-v] [-a]
|
2018-04-19 04:21:41 -04:00
|
|
|
|
|
|
|
Description
|
|
|
|
Installs Friendica with data based on the htconfig.php file
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
Notes:
|
|
|
|
Not checking .htaccess/URL-Rewrite during CLI installation.
|
|
|
|
|
|
|
|
Options
|
|
|
|
-h|--help|-? Show help information
|
|
|
|
-v Show more debug information.
|
|
|
|
-a All setup checks are required (except .htaccess)
|
2018-05-01 07:14:41 -04:00
|
|
|
-f prepared config file (e.g. ".htconfig.php" itself)
|
2018-04-18 05:43:23 -04:00
|
|
|
HELP;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function doExecute()
|
|
|
|
{
|
|
|
|
// Initialise the app
|
2018-04-18 08:30:42 -04:00
|
|
|
$this->out("Initializing setup...\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
$a = get_app();
|
|
|
|
$db_host = '';
|
|
|
|
$db_user = '';
|
|
|
|
$db_pass = '';
|
|
|
|
$db_data = '';
|
2018-05-01 07:11:25 -04:00
|
|
|
|
|
|
|
$config_file = $this->getOption('f', 'htconfig.php');
|
|
|
|
|
|
|
|
$this->out("Using config $config_file...\n");
|
|
|
|
require_once $config_file;
|
2018-04-18 05:43:23 -04:00
|
|
|
|
2018-04-23 16:56:59 -04:00
|
|
|
Install::setInstallMode();
|
|
|
|
|
2018-04-18 08:30:42 -04:00
|
|
|
$this->out(" Complete!\n\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
// Check basic setup
|
2018-04-18 08:30:42 -04:00
|
|
|
$this->out("Checking basic setup...\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
$checkResults = [];
|
|
|
|
$checkResults['basic'] = $this->runBasicChecks($a);
|
|
|
|
$errorMessage = $this->extractErrors($checkResults['basic']);
|
|
|
|
|
|
|
|
if ($errorMessage !== '') {
|
2018-04-18 08:30:42 -04:00
|
|
|
throw new \RuntimeException($errorMessage);
|
2018-04-18 05:43:23 -04:00
|
|
|
}
|
|
|
|
|
2018-04-18 08:30:42 -04:00
|
|
|
$this->out(" Complete!\n\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
// Check database connection
|
2018-04-18 08:30:42 -04:00
|
|
|
$this->out("Checking database...\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
$checkResults['db'] = array();
|
|
|
|
$checkResults['db'][] = $this->runDatabaseCheck($db_host, $db_user, $db_pass, $db_data);
|
|
|
|
$errorMessage = $this->extractErrors($checkResults['db']);
|
|
|
|
|
|
|
|
if ($errorMessage !== '') {
|
2018-04-18 08:30:42 -04:00
|
|
|
throw new \RuntimeException($errorMessage);
|
2018-04-18 05:43:23 -04:00
|
|
|
}
|
|
|
|
|
2018-04-18 08:30:42 -04:00
|
|
|
$this->out(" Complete!\n\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
// Install database
|
2018-04-18 08:30:42 -04:00
|
|
|
$this->out("Inserting data into database...\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
|
2018-04-29 12:11:24 -04:00
|
|
|
$checkResults['data'] = Install::installDatabaseStructure();
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
if ($checkResults['data'] !== '') {
|
2018-04-18 08:30:42 -04:00
|
|
|
throw new \RuntimeException("ERROR: DB Database creation error. Is the DB empty?\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
}
|
|
|
|
|
2018-04-18 08:30:42 -04:00
|
|
|
$this->out(" Complete!\n\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
// Copy config file
|
2018-04-18 08:30:42 -04:00
|
|
|
$this->out("Saving config file...\n");
|
2018-05-01 07:11:25 -04:00
|
|
|
if ($config_file != '.htconfig.php' && !copy($config_file, '.htconfig.php')) {
|
2018-05-01 07:21:42 -04:00
|
|
|
throw new \RuntimeException("ERROR: Saving config file failed. Please copy '$config_file' to '.htconfig.php' manually.\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
}
|
2018-04-18 08:30:42 -04:00
|
|
|
$this->out(" Complete!\n\n");
|
|
|
|
$this->out("\nInstallation is finished\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param App $app
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-04-18 08:30:42 -04:00
|
|
|
private function runBasicChecks($app)
|
2018-04-18 05:43:23 -04:00
|
|
|
{
|
|
|
|
$checks = [];
|
|
|
|
|
2018-04-23 16:56:59 -04:00
|
|
|
Install::checkFunctions($checks);
|
2018-04-29 12:11:24 -04:00
|
|
|
Install::checkImagick($checks);
|
2018-04-23 16:56:59 -04:00
|
|
|
Install::checkHtConfig($checks);
|
|
|
|
Install::checkSmarty3($checks);
|
|
|
|
Install::checkKeys($checks);
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
if (!empty($app->config['php_path'])) {
|
2018-04-23 16:56:59 -04:00
|
|
|
Install::checkPHP($app->config['php_path'], $checks);
|
2018-04-18 05:43:23 -04:00
|
|
|
} else {
|
2018-04-18 08:30:42 -04:00
|
|
|
throw new \RuntimeException(" ERROR: The php_path is not set in the config. Please check the file .htconfig.php.\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
}
|
|
|
|
|
2018-04-18 08:30:42 -04:00
|
|
|
$this->out(" NOTICE: Not checking .htaccess/URL-Rewrite during CLI installation.\n");
|
2018-04-18 05:43:23 -04:00
|
|
|
|
|
|
|
return $checks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $db_host
|
|
|
|
* @param $db_user
|
|
|
|
* @param $db_pass
|
|
|
|
* @param $db_data
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-04-18 08:30:42 -04:00
|
|
|
private function runDatabaseCheck($db_host, $db_user, $db_pass, $db_data)
|
2018-04-18 05:43:23 -04:00
|
|
|
{
|
|
|
|
$result = array(
|
|
|
|
'title' => 'MySQL Connection',
|
|
|
|
'required' => true,
|
|
|
|
'status' => true,
|
|
|
|
'help' => '',
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2018-04-28 06:36:40 -04:00
|
|
|
if (!dba::connect($db_host, $db_user, $db_pass, $db_data)) {
|
2018-04-18 05:43:23 -04:00
|
|
|
$result['status'] = false;
|
|
|
|
$result['help'] = 'Failed, please check your MySQL settings and credentials.';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $results
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-04-18 08:30:42 -04:00
|
|
|
private function extractErrors($results)
|
2018-04-18 05:43:23 -04:00
|
|
|
{
|
|
|
|
$errorMessage = '';
|
|
|
|
$allChecksRequired = $this->getOption('a') !== null;
|
|
|
|
|
|
|
|
foreach ($results as $result) {
|
|
|
|
if (($allChecksRequired || $result['required'] === true) && $result['status'] === false) {
|
|
|
|
$errorMessage .= "--------\n";
|
|
|
|
$errorMessage .= $result['title'] . ': ' . $result['help'] . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $errorMessage;
|
|
|
|
}
|
|
|
|
}
|