summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-02-23 22:41:10 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-02-23 22:41:10 +0100
commite87ada86d16043402f64ae45d75995a6cffb7c51 (patch)
tree2fbdc0b131e0b2e992d1e85acf0630e631f8d622 /core
parent66e3211fd8a57b0fb296d1dcc980272721e9f99d (diff)
parent0a9b8242eeffa16eba84b59603be967d0bcc5bae (diff)
downloadnextcloud-server-e87ada86d16043402f64ae45d75995a6cffb7c51.tar.gz
nextcloud-server-e87ada86d16043402f64ae45d75995a6cffb7c51.zip
Merge pull request #14416 from owncloud/setup-command
Setup command
Diffstat (limited to 'core')
-rw-r--r--core/command/maintenance/install.php129
-rw-r--r--core/register_command.php37
-rw-r--r--core/setup/controller.php6
3 files changed, 153 insertions, 19 deletions
diff --git a/core/command/maintenance/install.php b/core/command/maintenance/install.php
new file mode 100644
index 00000000000..0b01afc20ed
--- /dev/null
+++ b/core/command/maintenance/install.php
@@ -0,0 +1,129 @@
+<?php
+
+namespace OC\Core\Command\Maintenance;
+
+use InvalidArgumentException;
+use OCP\IConfig;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class Install extends Command {
+
+ /**
+ * @var IConfig
+ */
+ private $config;
+
+ public function __construct(IConfig $config) {
+ parent::__construct();
+ $this->config = $config;
+ }
+
+ protected function configure() {
+ $this
+ ->setName('maintenance:install')
+ ->setDescription('install ownCloud')
+ ->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')
+ ->addOption('database-user', null, InputOption::VALUE_REQUIRED, 'User name to connect to the database')
+ ->addOption('database-pass', null, InputOption::VALUE_REQUIRED, 'Password of the database user')
+ ->addOption('database-table-prefix', null, InputOption::VALUE_REQUIRED, 'Prefix for all tables', 'oc_')
+ ->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')
+ ->addOption('data-dir', null, InputOption::VALUE_REQUIRED, 'Path to data directory', \OC::$SERVERROOT."/data");
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output) {
+
+ $options = $this->validateInput($input, $output);
+
+ $errors = \OC\Setup::install($options);
+ if (count($errors) === 0) {
+ $output->writeln("ownCloud was successfully installed");
+ return 0;
+ }
+ 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>');
+ }
+ }
+
+ return 1;
+ }
+
+ /**
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ * @return array
+ */
+ protected function validateInput(InputInterface $input, OutputInterface $output) {
+ $db = strtolower($input->getOption('database'));
+ $supportedDatabases = $this->config->getSystemValue('supportedDatabases', [
+ 'sqlite',
+ 'mysql',
+ 'pgsql',
+ 'oci',
+ 'mssql'
+ ]);
+
+ 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');
+ $dbHost = $input->getOption('database-host');
+ $dbTablePrefix = $input->getOption('database-table-prefix');
+ $adminLogin = $input->getOption('admin-user');
+ $adminPassword = $input->getOption('admin-pass');
+ $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)) {
+ /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
+ $dialog = $this->getHelperSet()->get('dialog');
+ $dbPass = $dialog->askHiddenResponse(
+ $output,
+ "<question>What is the password to access the database with user <$dbUser>?</question>",
+ false
+ );
+ }
+ }
+
+ if (is_null($adminPassword)) {
+ /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */
+ $dialog = $this->getHelperSet()->get('dialog');
+ $adminPassword = $dialog->askHiddenResponse(
+ $output,
+ "<question>What is the password you like to use for the admin account <$adminLogin>?</question>",
+ false
+ );
+ }
+
+ $options = [
+ 'dbtype' => $db,
+ 'dbuser' => $dbUser,
+ 'dbpass' => $dbPass,
+ 'dbname' => $dbName,
+ 'dbhost' => $dbHost,
+ 'dbtableprefix' => $dbTablePrefix,
+ 'adminlogin' => $adminLogin,
+ 'adminpass' => $adminPassword,
+ 'directory' => $dataDir
+ ];
+ return $options;
+ }
+}
diff --git a/core/register_command.php b/core/register_command.php
index 4af423054d7..c62282c084c 100644
--- a/core/register_command.php
+++ b/core/register_command.php
@@ -24,23 +24,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
-$repair = new \OC\Repair(\OC\Repair::getRepairSteps());
/** @var $application Symfony\Component\Console\Application */
$application->add(new OC\Core\Command\Status);
-$application->add(new OC\Core\Command\Db\GenerateChangeScript());
-$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory()));
-$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig()));
-$application->add(new OC\Core\Command\Maintenance\SingleUser());
-$application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig()));
-$application->add(new OC\Core\Command\App\CheckCode());
-$application->add(new OC\Core\Command\App\Disable());
-$application->add(new OC\Core\Command\App\Enable());
-$application->add(new OC\Core\Command\App\ListApps());
-$application->add(new OC\Core\Command\Maintenance\Repair($repair, \OC::$server->getConfig()));
-$application->add(new OC\Core\Command\User\Report());
-$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
-$application->add(new OC\Core\Command\User\LastSeen());
-$application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
-$application->add(new OC\Core\Command\L10n\CreateJs());
+if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
+ $repair = new \OC\Repair(\OC\Repair::getRepairSteps());
+
+ $application->add(new OC\Core\Command\Db\GenerateChangeScript());
+ $application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory()));
+ $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig()));
+ $application->add(new OC\Core\Command\Maintenance\SingleUser());
+ $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig()));
+ $application->add(new OC\Core\Command\App\CheckCode());
+ $application->add(new OC\Core\Command\App\Disable());
+ $application->add(new OC\Core\Command\App\Enable());
+ $application->add(new OC\Core\Command\App\ListApps());
+ $application->add(new OC\Core\Command\Maintenance\Repair($repair, \OC::$server->getConfig()));
+ $application->add(new OC\Core\Command\User\Report());
+ $application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager()));
+ $application->add(new OC\Core\Command\User\LastSeen());
+ $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager()));
+ $application->add(new OC\Core\Command\L10n\CreateJs());
+} else {
+ $application->add(new OC\Core\Command\Maintenance\Install(\OC::$server->getConfig()));
+}
diff --git a/core/setup/controller.php b/core/setup/controller.php
index 330de2537ac..dfd7e0d8d96 100644
--- a/core/setup/controller.php
+++ b/core/setup/controller.php
@@ -75,7 +75,7 @@ class Controller {
if(isset($post['install']) AND $post['install']=='true') {
// We have to launch the installation process :
- $e = \OC_Setup::install($post);
+ $e = \OC\Setup::install($post);
$errors = array('errors' => $e);
if(count($e) > 0) {
@@ -145,7 +145,7 @@ class Controller {
* in case of errors/warnings
*/
public function getSystemInfo() {
- $setup = new \OC_Setup($this->config);
+ $setup = new \OC\Setup($this->config);
$databases = $setup->getSupportedDatabases();
$dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data');
@@ -159,7 +159,7 @@ class Controller {
$htAccessWorking = true;
if (is_dir($dataDir) && is_writable($dataDir)) {
// Protect data directory here, so we can test if the protection is working
- \OC_Setup::protectDataDirectory();
+ \OC\Setup::protectDataDirectory();
try {
$htAccessWorking = \OC_Util::isHtaccessWorking();