console.php 3.72 KB
Newer Older
1
2
<?php
/**
Jenkins for ownCloud's avatar
Jenkins for ownCloud committed
3
 * @author Bart Visscher <bartv@thisnet.nl>
Thomas Müller's avatar
Thomas Müller committed
4
 * @author Edward Crompton <edward.crompton@gmail.com>
Thomas Müller's avatar
Thomas Müller committed
5
 * @author Joas Schilling <coding@schilljs.com>
6
 * @author Jost Baron <Jost.Baron@gmx.de>
Lukas Reschke's avatar
Lukas Reschke committed
7
 * @author Lukas Reschke <lukas@statuscode.ch>
Jenkins for ownCloud's avatar
Jenkins for ownCloud committed
8
 * @author Morris Jobke <hey@morrisjobke.de>
9
 * @author Philippe Le Brouster <plb@nebkha.net>
Jenkins for ownCloud's avatar
Jenkins for ownCloud committed
10
 * @author Thomas Müller <thomas.mueller@tmit.eu>
Lukas Reschke's avatar
Lukas Reschke committed
11
 * @author Victor Dubiniuk <dubiniuk@owncloud.com>
Jenkins for ownCloud's avatar
Jenkins for ownCloud committed
12
 *
Thomas Müller's avatar
Thomas Müller committed
13
 * @copyright Copyright (c) 2016, ownCloud GmbH.
Jenkins for ownCloud's avatar
Jenkins for ownCloud committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * @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,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
28
 */
29

30
use OC\Console\Application;
31
use Symfony\Component\Console\Input\ArgvInput;
32
use Symfony\Component\Console\Output\ConsoleOutput;
33

34
35
define('OC_CONSOLE', 1);

36
37
38
39
// Show warning if a PHP version below 5.6.0 is used, this has to happen here
// because base.php will already use 5.6 syntax.
if (version_compare(PHP_VERSION, '5.6.0') === -1) {
	echo 'This version of ownCloud requires at least PHP 5.6.0'.PHP_EOL;
40
41
42
43
	echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'.PHP_EOL;
	return;
}

44
45
46
47
48
function exceptionHandler($exception) {
	echo "An unhandled exception has been thrown:" . PHP_EOL;
	echo $exception;
	exit(1);
}
49
try {
50
	require_once __DIR__ . '/lib/base.php';
51

52
53
54
	// set to run indefinitely if needed
	set_time_limit(0);

55
56
	if (!OC::$CLI) {
		echo "This script can be run from the command line only" . PHP_EOL;
57
		exit(1);
58
	}
59

60
61
	set_exception_handler('exceptionHandler');

62
	if (!OC_Util::runningOnWindows())  {
63
64
		if (!function_exists('posix_getuid')) {
			echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
65
			exit(1);
66
		}
67
		$user = posix_getpwuid(posix_getuid());
68
		$configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
69
		if ($user['name'] !== $configUser['name']) {
70
			echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
71
			echo "Current user: " . $user['name'] . PHP_EOL;
72
			echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
73
74
			echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
			exit(1);
75
76
77
		}
	}

78
79
80
81
82
83
	$oldWorkingDir = getcwd();
	if ($oldWorkingDir === false) {
		echo "This script can be run from the ownCloud root directory only." . PHP_EOL;
		echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
	} else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
		echo "This script can be run from the ownCloud root directory only." . PHP_EOL;
Morris Jobke's avatar
Morris Jobke committed
84
		echo "Can't change to ownCloud root directory." . PHP_EOL;
85
86
87
		exit(1);
	}

88
	if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) {
89
90
91
		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;
	}

92
	$application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest());
93
	$application->loadCommands(new ArgvInput(), new ConsoleOutput());
94
95
	$application->run();
} catch (Exception $ex) {
96
	exceptionHandler($ex);
97
98
} catch (Error $ex) {
	exceptionHandler($ex);
99
}