2015-02-21 22:52:32 +03:00
|
|
|
<?php
|
2015-03-26 13:44:34 +03:00
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2015-06-25 12:43:55 +03:00
|
|
|
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Christian Kampka <christian@kampka.net>
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Daniel Hansson <daniel@techandme.se>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2016-07-21 18:07:57 +03:00
|
|
|
* @author Thomas Pulzer <t.pulzer@kniel.de>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2015-02-21 22:52:32 +03:00
|
|
|
namespace OC\Core\Command\Maintenance;
|
|
|
|
|
2020-08-20 15:08:18 +03:00
|
|
|
use bantu\IniGetWrapper\IniGetWrapper;
|
2015-02-21 22:52:32 +03:00
|
|
|
use InvalidArgumentException;
|
2017-11-24 12:27:58 +03:00
|
|
|
use OC\Installer;
|
2015-03-11 01:44:29 +03:00
|
|
|
use OC\Setup;
|
2017-03-18 01:37:48 +03:00
|
|
|
use OC\SystemConfig;
|
2017-04-07 23:42:43 +03:00
|
|
|
use OCP\Defaults;
|
2015-02-21 22:52:32 +03:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
2016-09-06 22:08:08 +03:00
|
|
|
use Symfony\Component\Console\Helper\QuestionHelper;
|
2015-02-21 22:52:32 +03:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2016-09-06 22:08:08 +03:00
|
|
|
use Symfony\Component\Console\Question\Question;
|
2015-02-21 22:52:32 +03:00
|
|
|
|
|
|
|
class Install extends Command {
|
|
|
|
|
2020-08-20 15:08:18 +03:00
|
|
|
/** @var SystemConfig */
|
2015-02-21 22:52:32 +03:00
|
|
|
private $config;
|
2020-08-20 15:08:18 +03:00
|
|
|
/** @var IniGetWrapper */
|
|
|
|
private $iniGetWrapper;
|
2015-02-21 22:52:32 +03:00
|
|
|
|
2020-08-20 15:08:18 +03:00
|
|
|
public function __construct(SystemConfig $config, IniGetWrapper $iniGetWrapper) {
|
2015-02-21 22:52:32 +03:00
|
|
|
parent::__construct();
|
|
|
|
$this->config = $config;
|
2020-08-20 15:08:18 +03:00
|
|
|
$this->iniGetWrapper = $iniGetWrapper;
|
2015-02-21 22:52:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure() {
|
|
|
|
$this
|
|
|
|
->setName('maintenance:install')
|
2016-07-28 21:55:26 +03:00
|
|
|
->setDescription('install Nextcloud')
|
2015-02-21 22:52:32 +03:00
|
|
|
->addOption('database', null, InputOption::VALUE_REQUIRED, 'Supported database type', 'sqlite')
|
|
|
|
->addOption('database-name', null, InputOption::VALUE_REQUIRED, 'Name of the database')
|
|
|
|
->addOption('database-host', null, InputOption::VALUE_REQUIRED, 'Hostname of the database', 'localhost')
|
2016-07-06 12:31:28 +03:00
|
|
|
->addOption('database-port', null, InputOption::VALUE_REQUIRED, 'Port the database is listening on')
|
2015-02-21 22:52:32 +03:00
|
|
|
->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'User name to connect to the database')
|
2015-04-29 23:53:16 +03:00
|
|
|
->addOption('database-pass', null, InputOption::VALUE_OPTIONAL, 'Password of the database user', null)
|
2017-07-21 12:17:12 +03:00
|
|
|
->addOption('database-table-space', null, InputOption::VALUE_OPTIONAL, 'Table space of the database (oci only)', null)
|
2015-02-21 22:52:32 +03:00
|
|
|
->addOption('admin-user', null, InputOption::VALUE_REQUIRED, 'User name of the admin account', 'admin')
|
|
|
|
->addOption('admin-pass', null, InputOption::VALUE_REQUIRED, 'Password of the admin account')
|
2018-09-13 15:37:06 +03:00
|
|
|
->addOption('admin-email', null, InputOption::VALUE_OPTIONAL, 'E-Mail of the admin account')
|
2015-02-21 22:52:32 +03:00
|
|
|
->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT."/data");
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:54:51 +03:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2015-02-21 22:52:32 +03:00
|
|
|
|
2015-03-11 01:44:29 +03:00
|
|
|
// validate the environment
|
2015-07-30 01:04:30 +03:00
|
|
|
$server = \OC::$server;
|
2017-11-24 12:27:58 +03:00
|
|
|
$setupHelper = new Setup(
|
|
|
|
$this->config,
|
2020-08-20 15:08:18 +03:00
|
|
|
$this->iniGetWrapper,
|
2017-11-24 12:27:58 +03:00
|
|
|
$server->getL10N('lib'),
|
|
|
|
$server->query(Defaults::class),
|
|
|
|
$server->getLogger(),
|
|
|
|
$server->getSecureRandom(),
|
|
|
|
\OC::$server->query(Installer::class)
|
|
|
|
);
|
2015-03-11 17:47:24 +03:00
|
|
|
$sysInfo = $setupHelper->getSystemInfo(true);
|
2015-03-11 01:44:29 +03:00
|
|
|
$errors = $sysInfo['errors'];
|
|
|
|
if (count($errors) > 0) {
|
|
|
|
$this->printErrors($output, $errors);
|
2015-12-09 12:49:54 +03:00
|
|
|
|
|
|
|
// ignore the OS X setup warning
|
2020-04-10 15:19:56 +03:00
|
|
|
if (count($errors) !== 1 ||
|
2018-01-27 01:46:40 +03:00
|
|
|
(string)$errors[0]['error'] !== 'Mac OS X is not supported and Nextcloud will not work properly on this platform. Use it at your own risk! ') {
|
2015-12-09 12:49:54 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2015-02-21 22:52:32 +03:00
|
|
|
}
|
|
|
|
|
2015-03-11 01:44:29 +03:00
|
|
|
// validate user input
|
|
|
|
$options = $this->validateInput($input, $output, array_keys($sysInfo['databases']));
|
|
|
|
|
|
|
|
// perform installation
|
|
|
|
$errors = $setupHelper->install($options);
|
|
|
|
if (count($errors) > 0) {
|
|
|
|
$this->printErrors($output, $errors);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-07-28 21:55:26 +03:00
|
|
|
$output->writeln("Nextcloud was successfully installed");
|
2015-03-11 01:44:29 +03:00
|
|
|
return 0;
|
2015-02-21 22:52:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param InputInterface $input
|
|
|
|
* @param OutputInterface $output
|
2015-03-11 01:44:29 +03:00
|
|
|
* @param string[] $supportedDatabases
|
2015-02-21 22:52:32 +03:00
|
|
|
* @return array
|
|
|
|
*/
|
2015-03-11 01:44:29 +03:00
|
|
|
protected function validateInput(InputInterface $input, OutputInterface $output, $supportedDatabases) {
|
2015-02-21 22:52:32 +03:00
|
|
|
$db = strtolower($input->getOption('database'));
|
|
|
|
|
|
|
|
if (!in_array($db, $supportedDatabases)) {
|
|
|
|
throw new InvalidArgumentException("Database <$db> is not supported.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$dbUser = $input->getOption('database-user');
|
|
|
|
$dbPass = $input->getOption('database-pass');
|
|
|
|
$dbName = $input->getOption('database-name');
|
2016-07-06 10:58:38 +03:00
|
|
|
$dbPort = $input->getOption('database-port');
|
2016-06-10 12:16:32 +03:00
|
|
|
if ($db === 'oci') {
|
|
|
|
// an empty hostname needs to be read from the raw parameters
|
|
|
|
$dbHost = $input->getParameterOption('--database-host', '');
|
|
|
|
} else {
|
|
|
|
$dbHost = $input->getOption('database-host');
|
|
|
|
}
|
2020-02-05 14:47:08 +03:00
|
|
|
if ($dbPort) {
|
|
|
|
// Append the port to the host so it is the same as in the config (there is no dbport config)
|
|
|
|
$dbHost .= ':' . $dbPort;
|
|
|
|
}
|
2015-04-29 13:15:40 +03:00
|
|
|
if ($input->hasParameterOption('--database-pass')) {
|
|
|
|
$dbPass = (string) $input->getOption('database-pass');
|
|
|
|
}
|
2015-02-21 22:52:32 +03:00
|
|
|
$adminLogin = $input->getOption('admin-user');
|
|
|
|
$adminPassword = $input->getOption('admin-pass');
|
2018-09-13 15:37:06 +03:00
|
|
|
$adminEmail = $input->getOption('admin-email');
|
2015-02-21 22:52:32 +03:00
|
|
|
$dataDir = $input->getOption('data-dir');
|
|
|
|
|
|
|
|
if ($db !== 'sqlite') {
|
|
|
|
if (is_null($dbUser)) {
|
|
|
|
throw new InvalidArgumentException("Database user not provided.");
|
|
|
|
}
|
|
|
|
if (is_null($dbName)) {
|
|
|
|
throw new InvalidArgumentException("Database name not provided.");
|
|
|
|
}
|
|
|
|
if (is_null($dbPass)) {
|
2016-09-06 22:08:08 +03:00
|
|
|
/** @var QuestionHelper $helper */
|
|
|
|
$helper = $this->getHelper('question');
|
|
|
|
$question = new Question('What is the password to access the database with user <'.$dbUser.'>?');
|
|
|
|
$question->setHidden(true);
|
|
|
|
$question->setHiddenFallback(false);
|
|
|
|
$dbPass = $helper->ask($input, $output, $question);
|
2015-02-21 22:52:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($adminPassword)) {
|
2016-09-06 22:08:08 +03:00
|
|
|
/** @var QuestionHelper $helper */
|
|
|
|
$helper = $this->getHelper('question');
|
|
|
|
$question = new Question('What is the password you like to use for the admin account <'.$adminLogin.'>?');
|
|
|
|
$question->setHidden(true);
|
|
|
|
$question->setHiddenFallback(false);
|
|
|
|
$adminPassword = $helper->ask($input, $output, $question);
|
2015-02-21 22:52:32 +03:00
|
|
|
}
|
|
|
|
|
2018-09-25 22:53:04 +03:00
|
|
|
if ($adminEmail !== null && !filter_var($adminEmail, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
throw new InvalidArgumentException('Invalid e-mail-address <' . $adminEmail . '> for <' . $adminLogin . '>.');
|
|
|
|
}
|
|
|
|
|
2015-02-21 22:52:32 +03:00
|
|
|
$options = [
|
|
|
|
'dbtype' => $db,
|
|
|
|
'dbuser' => $dbUser,
|
|
|
|
'dbpass' => $dbPass,
|
|
|
|
'dbname' => $dbName,
|
|
|
|
'dbhost' => $dbHost,
|
|
|
|
'adminlogin' => $adminLogin,
|
|
|
|
'adminpass' => $adminPassword,
|
2018-09-13 15:37:06 +03:00
|
|
|
'adminemail' => $adminEmail,
|
2015-02-21 22:52:32 +03:00
|
|
|
'directory' => $dataDir
|
|
|
|
];
|
2017-07-21 12:17:12 +03:00
|
|
|
if ($db === 'oci') {
|
|
|
|
$options['dbtablespace'] = $input->getParameterOption('--database-table-space', '');
|
|
|
|
}
|
2015-02-21 22:52:32 +03:00
|
|
|
return $options;
|
|
|
|
}
|
2015-03-11 01:44:29 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param OutputInterface $output
|
|
|
|
* @param $errors
|
|
|
|
*/
|
|
|
|
protected function printErrors(OutputInterface $output, $errors) {
|
|
|
|
foreach ($errors as $error) {
|
|
|
|
if (is_array($error)) {
|
|
|
|
$output->writeln('<error>' . (string)$error['error'] . '</error>');
|
|
|
|
$output->writeln('<info> -> ' . (string)$error['hint'] . '</info>');
|
|
|
|
} else {
|
|
|
|
$output->writeln('<error>' . (string)$error . '</error>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-21 22:52:32 +03:00
|
|
|
}
|