1
0

console.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. require_once __DIR__ . '/lib/versioncheck.php';
  28. use OC\Console\Application;
  29. use Symfony\Component\Console\Input\ArgvInput;
  30. use Symfony\Component\Console\Output\ConsoleOutput;
  31. define('OC_CONSOLE', 1);
  32. function exceptionHandler($exception) {
  33. echo "An unhandled exception has been thrown:" . PHP_EOL;
  34. echo $exception;
  35. exit(1);
  36. }
  37. try {
  38. require_once __DIR__ . '/lib/base.php';
  39. // set to run indefinitely if needed
  40. if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
  41. @set_time_limit(0);
  42. }
  43. if (!OC::$CLI) {
  44. echo "This script can be run from the command line only" . PHP_EOL;
  45. exit(1);
  46. }
  47. set_exception_handler('exceptionHandler');
  48. if (!function_exists('posix_getuid')) {
  49. echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
  50. exit(1);
  51. }
  52. $user = posix_getpwuid(posix_getuid());
  53. $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
  54. if ($user['name'] !== $configUser['name']) {
  55. echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
  56. echo "Current user: " . $user['name'] . PHP_EOL;
  57. echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
  58. echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
  59. exit(1);
  60. }
  61. $oldWorkingDir = getcwd();
  62. if ($oldWorkingDir === false) {
  63. echo "This script can be run from the ownCloud root directory only." . PHP_EOL;
  64. echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
  65. } else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
  66. echo "This script can be run from the ownCloud root directory only." . PHP_EOL;
  67. echo "Can't change to ownCloud root directory." . PHP_EOL;
  68. exit(1);
  69. }
  70. if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) {
  71. 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;
  72. }
  73. $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest(), \OC::$server->getLogger());
  74. $application->loadCommands(new ArgvInput(), new ConsoleOutput());
  75. $application->run();
  76. } catch (Exception $ex) {
  77. exceptionHandler($ex);
  78. } catch (Error $ex) {
  79. exceptionHandler($ex);
  80. }