1
0

console.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author hoellen <dev@hoellen.eu>
  8. * @author J0WI <J0WI@users.noreply.github.com>
  9. * @author Joas Schilling <coding@schilljs.com>
  10. * @author Ko- <k.stoffelen@cs.ru.nl>
  11. * @author Lukas Reschke <lukas@statuscode.ch>
  12. * @author Michael Weimann <mail@michael-weimann.eu>
  13. * @author Morris Jobke <hey@morrisjobke.de>
  14. * @author Patrick Paysant <patrick.paysant@linagora.com>
  15. * @author Roeland Jago Douma <roeland@famdouma.nl>
  16. * @author Thomas Müller <thomas.mueller@tmit.eu>
  17. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  18. *
  19. * @license AGPL-3.0
  20. *
  21. * This code is free software: you can redistribute it and/or modify
  22. * it under the terms of the GNU Affero General Public License, version 3,
  23. * as published by the Free Software Foundation.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU Affero General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU Affero General Public License, version 3,
  31. * along with this program. If not, see <http://www.gnu.org/licenses/>
  32. *
  33. */
  34. require_once __DIR__ . '/lib/versioncheck.php';
  35. use OC\Console\Application;
  36. use Symfony\Component\Console\Input\ArgvInput;
  37. use Symfony\Component\Console\Output\ConsoleOutput;
  38. define('OC_CONSOLE', 1);
  39. function exceptionHandler($exception) {
  40. echo "An unhandled exception has been thrown:" . PHP_EOL;
  41. echo $exception;
  42. exit(1);
  43. }
  44. try {
  45. require_once __DIR__ . '/lib/base.php';
  46. // set to run indefinitely if needed
  47. if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
  48. @set_time_limit(0);
  49. }
  50. if (!OC::$CLI) {
  51. echo "This script can be run from the command line only" . PHP_EOL;
  52. exit(1);
  53. }
  54. $config = \OC::$server->getConfig();
  55. set_exception_handler('exceptionHandler');
  56. if (!function_exists('posix_getuid')) {
  57. echo "The posix extensions are required - see https://www.php.net/manual/en/book.posix.php" . PHP_EOL;
  58. exit(1);
  59. }
  60. $user = posix_getuid();
  61. $configUser = fileowner(OC::$configDir . 'config.php');
  62. if ($user !== $configUser) {
  63. echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
  64. echo "Current user id: " . $user . PHP_EOL;
  65. echo "Owner id of config.php: " . $configUser . PHP_EOL;
  66. echo "Try adding 'sudo -u #" . $configUser . "' to the beginning of the command (without the single quotes)" . PHP_EOL;
  67. echo "If running with 'docker exec' try adding the option '-u " . $configUser . "' to the docker command (without the single quotes)" . PHP_EOL;
  68. exit(1);
  69. }
  70. $oldWorkingDir = getcwd();
  71. if ($oldWorkingDir === false) {
  72. echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
  73. echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
  74. } elseif ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
  75. echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
  76. echo "Can't change to Nextcloud root directory." . PHP_EOL;
  77. exit(1);
  78. }
  79. if (!(function_exists('pcntl_signal') && function_exists('pcntl_signal_dispatch')) && !in_array('--no-warnings', $argv)) {
  80. echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see https://www.php.net/manual/en/book.pcntl.php" . PHP_EOL;
  81. echo "Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini." . PHP_EOL;
  82. }
  83. $application = new Application(
  84. $config,
  85. \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
  86. \OC::$server->getRequest(),
  87. \OC::$server->get(\Psr\Log\LoggerInterface::class),
  88. \OC::$server->query(\OC\MemoryInfo::class)
  89. );
  90. $application->loadCommands(new ArgvInput(), new ConsoleOutput());
  91. $application->run();
  92. } catch (Exception $ex) {
  93. exceptionHandler($ex);
  94. } catch (Error $ex) {
  95. exceptionHandler($ex);
  96. }