console.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christian Kampka <christian@kampka.net>
  7. * @author Edward Crompton <edward.crompton@gmail.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Jost Baron <Jost.Baron@gmx.de>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Philippe Le Brouster <plb@nebkha.net>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  15. *
  16. * @license AGPL-3.0
  17. *
  18. * This code is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License, version 3,
  20. * as published by the Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License, version 3,
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>
  29. *
  30. */
  31. use OC\Console\Application;
  32. use Symfony\Component\Console\Input\ArgvInput;
  33. use Symfony\Component\Console\Output\ConsoleOutput;
  34. define('OC_CONSOLE', 1);
  35. // Show warning if a PHP version below 5.4.0 is used, this has to happen here
  36. // because base.php will already use 5.4 syntax.
  37. if (version_compare(PHP_VERSION, '5.4.0') === -1) {
  38. echo 'This version of Nextcloud requires at least PHP 5.4.0'.PHP_EOL;
  39. echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'.PHP_EOL;
  40. return;
  41. }
  42. // Show warning if PHP 7.1 is used as Nextcloud is not compatible with PHP 7.1 for now
  43. // @see https://github.com/nextcloud/docker-ci/issues/10
  44. if (version_compare(PHP_VERSION, '7.1.0') !== -1) {
  45. echo 'This version of Nextcloud is not compatible with PHP 7.1.<br/>';
  46. echo 'You are currently running ' . PHP_VERSION . '.';
  47. return;
  48. }
  49. try {
  50. require_once __DIR__ . '/lib/base.php';
  51. // set to run indefinitely if needed
  52. set_time_limit(0);
  53. if (!OC::$CLI) {
  54. echo "This script can be run from the command line only" . PHP_EOL;
  55. exit(0);
  56. }
  57. if (!OC_Util::runningOnWindows()) {
  58. if (!function_exists('posix_getuid')) {
  59. echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
  60. exit(0);
  61. }
  62. $user = posix_getpwuid(posix_getuid());
  63. $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
  64. if ($user['name'] !== $configUser['name']) {
  65. echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
  66. echo "Current user: " . $user['name'] . PHP_EOL;
  67. echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
  68. echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
  69. exit(0);
  70. }
  71. }
  72. $oldWorkingDir = getcwd();
  73. if ($oldWorkingDir === false) {
  74. echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
  75. echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
  76. } else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
  77. echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
  78. echo "Can't change to Nextcloud root directory." . PHP_EOL;
  79. exit(1);
  80. }
  81. if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) {
  82. echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php" . PHP_EOL;
  83. }
  84. $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest());
  85. $application->loadCommands(new ArgvInput(), new ConsoleOutput());
  86. $application->run();
  87. } catch (Exception $ex) {
  88. echo "An unhandled exception has been thrown:" . PHP_EOL;
  89. echo $ex;
  90. exit(1);
  91. }