2013-10-24 21:59:39 +04:00
< ? php
/**
2016-07-30 17:26:21 +03:00
* @ copyright Copyright ( c ) 2016 , ownCloud , Inc .
2016-07-21 18:07:57 +03:00
*
2015-03-26 13:44:34 +03:00
* @ author Andreas Fischer < bantu @ owncloud . com >
2016-05-26 20:56:05 +03:00
* @ author Björn Schießle < bjoern @ schiessle . org >
2016-07-21 18:07:57 +03:00
* @ author Joas Schilling < coding @ schilljs . com >
2016-05-26 20:56:05 +03:00
* @ author Lukas Reschke < lukas @ statuscode . ch >
2015-03-26 13:44:34 +03:00
* @ author Morris Jobke < hey @ morrisjobke . de >
* @ author Owen Winkler < a_github @ midnightcircus . com >
2015-06-25 12:43:55 +03:00
* @ author Steffen Lindner < mail @ steffen - lindner . de >
2015-03-26 13:44:34 +03:00
* @ author Thomas Müller < thomas . mueller @ tmit . eu >
2016-07-21 18:07:57 +03:00
* @ author Thomas Pulzer < t . pulzer @ kniel . de >
2015-03-26 13:44:34 +03:00
* @ author Vincent Petry < pvince81 @ owncloud . com >
*
* @ 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 />
*
2013-10-24 21:59:39 +04:00
*/
2015-02-26 13:37:37 +03:00
2013-10-24 21:59:39 +04:00
namespace OC\Core\Command ;
2015-06-23 18:07:28 +03:00
use OC\Console\TimestampFormatter ;
2013-10-28 18:15:56 +04:00
use OC\Updater ;
2014-09-22 14:04:48 +04:00
use OCP\IConfig ;
2015-10-09 15:08:22 +03:00
use OCP\ILogger ;
2013-10-24 21:59:39 +04:00
use Symfony\Component\Console\Command\Command ;
2016-03-31 00:38:26 +03:00
use Symfony\Component\Console\Helper\ProgressBar ;
2013-10-24 21:59:39 +04:00
use Symfony\Component\Console\Input\InputInterface ;
use Symfony\Component\Console\Output\OutputInterface ;
2014-06-05 18:19:24 +04:00
use Symfony\Component\Console\Input\InputOption ;
2016-03-31 00:38:26 +03:00
use Symfony\Component\EventDispatcher\GenericEvent ;
2013-10-24 21:59:39 +04:00
class Upgrade extends Command {
2013-10-29 00:50:28 +04:00
const ERROR_SUCCESS = 0 ;
const ERROR_NOT_INSTALLED = 1 ;
const ERROR_MAINTENANCE_MODE = 2 ;
2016-08-03 16:51:55 +03:00
const ERROR_UP_TO_DATE = 0 ;
2014-06-05 18:19:24 +04:00
const ERROR_INVALID_ARGUMENTS = 4 ;
2015-06-23 11:03:27 +03:00
const ERROR_FAILURE = 5 ;
2014-09-22 13:59:13 +04:00
2015-10-09 15:08:22 +03:00
/** @var IConfig */
2014-09-22 14:04:48 +04:00
private $config ;
2015-10-09 15:08:22 +03:00
/** @var ILogger */
private $logger ;
2014-09-22 14:04:48 +04:00
/**
* @ param IConfig $config
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
* @ param ILogger $logger
2014-09-22 14:04:48 +04:00
*/
2015-10-09 15:08:22 +03:00
public function __construct ( IConfig $config , ILogger $logger ) {
2014-11-03 15:53:59 +03:00
parent :: __construct ();
2014-09-22 14:04:48 +04:00
$this -> config = $config ;
2015-10-09 15:08:22 +03:00
$this -> logger = $logger ;
2014-09-22 14:04:48 +04:00
}
2013-10-24 21:59:39 +04:00
protected function configure () {
$this
-> setName ( 'upgrade' )
2015-03-27 00:30:35 +03:00
-> setDescription ( 'run upgrade routines after installation of a new release. The release has to be installed before.' )
2015-05-20 18:06:00 +03:00
-> addOption (
'--no-app-disable' ,
null ,
InputOption :: VALUE_NONE ,
'skips the disable of third party apps'
2014-06-05 18:19:24 +04:00
);
2013-10-24 21:59:39 +04:00
}
2014-03-14 13:48:07 +04:00
/**
* Execute the upgrade command
*
* @ param InputInterface $input input interface
* @ param OutputInterface $output output interface
*/
2013-10-24 21:59:39 +04:00
protected function execute ( InputInterface $input , OutputInterface $output ) {
2013-10-28 18:15:56 +04:00
if ( \OC :: checkUpgrade ( false )) {
2015-06-23 18:07:28 +03:00
if ( OutputInterface :: VERBOSITY_NORMAL < $output -> getVerbosity ()) {
// Prepend each line with a little timestamp
$timestampFormatter = new TimestampFormatter ( $this -> config , $output -> getFormatter ());
$output -> setFormatter ( $timestampFormatter );
}
2014-09-22 13:59:13 +04:00
$self = $this ;
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
$updater = new Updater (
$this -> config ,
\OC :: $server -> getIntegrityCodeChecker (),
$this -> logger
);
2013-10-28 18:15:56 +04:00
2017-04-28 00:11:33 +03:00
if ( $input -> getOption ( 'no-app-disable' )) {
$updater -> setSkip3rdPartyAppsDisable ( true );
}
2016-03-31 00:38:26 +03:00
$dispatcher = \OC :: $server -> getEventDispatcher ();
$progress = new ProgressBar ( $output );
2016-04-04 17:20:53 +03:00
$progress -> setFormat ( " %message% \n %current%/%max% [%bar%] %percent:3s%% " );
$listener = function ( $event ) use ( $progress , $output ) {
2016-03-31 00:38:26 +03:00
if ( $event instanceof GenericEvent ) {
2016-03-31 13:41:57 +03:00
$message = $event -> getSubject ();
2016-04-04 17:20:53 +03:00
if ( OutputInterface :: VERBOSITY_NORMAL < $output -> getVerbosity ()) {
$output -> writeln ( ' Checking table ' . $message );
} else {
if ( strlen ( $message ) > 60 ) {
$message = substr ( $message , 0 , 57 ) . '...' ;
}
$progress -> setMessage ( $message );
if ( $event [ 0 ] === 1 ) {
$output -> writeln ( '' );
$progress -> start ( $event [ 1 ]);
}
$progress -> setProgress ( $event [ 0 ]);
if ( $event [ 0 ] === $event [ 1 ]) {
$progress -> setMessage ( 'Done' );
$progress -> finish ();
$output -> writeln ( '' );
}
2016-03-31 00:38:26 +03:00
}
}
2016-04-04 17:20:53 +03:00
};
2016-04-27 14:19:00 +03:00
$repairListener = function ( $event ) use ( $progress , $output ) {
if ( ! $event instanceof GenericEvent ) {
return ;
}
switch ( $event -> getSubject ()) {
case '\OC\Repair::startProgress' :
$progress -> setMessage ( 'Starting ...' );
$output -> writeln ( $event -> getArgument ( 1 ));
$output -> writeln ( '' );
$progress -> start ( $event -> getArgument ( 0 ));
break ;
case '\OC\Repair::advance' :
$desc = $event -> getArgument ( 1 );
if ( ! empty ( $desc )) {
$progress -> setMessage ( $desc );
}
$progress -> advance ( $event -> getArgument ( 0 ));
break ;
case '\OC\Repair::finishProgress' :
$progress -> setMessage ( 'Done' );
$progress -> finish ();
$output -> writeln ( '' );
break ;
case '\OC\Repair::step' :
if ( OutputInterface :: VERBOSITY_NORMAL < $output -> getVerbosity ()) {
$output -> writeln ( '<info>Repair step: ' . $event -> getArgument ( 0 ) . '</info>' );
}
break ;
case '\OC\Repair::info' :
if ( OutputInterface :: VERBOSITY_NORMAL < $output -> getVerbosity ()) {
$output -> writeln ( '<info>Repair info: ' . $event -> getArgument ( 0 ) . '</info>' );
}
break ;
case '\OC\Repair::warning' :
$output -> writeln ( '<error>Repair warning: ' . $event -> getArgument ( 0 ) . '</error>' );
break ;
case '\OC\Repair::error' :
$output -> writeln ( '<error>Repair error: ' . $event -> getArgument ( 0 ) . '</error>' );
break ;
}
};
2016-04-04 17:20:53 +03:00
$dispatcher -> addListener ( '\OC\DB\Migrator::executeSql' , $listener );
$dispatcher -> addListener ( '\OC\DB\Migrator::checkTable' , $listener );
2016-04-27 14:19:00 +03:00
$dispatcher -> addListener ( '\OC\Repair::startProgress' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::advance' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::finishProgress' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::step' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::info' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::warning' , $repairListener );
$dispatcher -> addListener ( '\OC\Repair::error' , $repairListener );
2014-06-05 18:19:24 +04:00
2015-05-19 11:27:53 +03:00
$updater -> listen ( '\OC\Updater' , 'maintenanceEnabled' , function () use ( $output ) {
2013-10-29 01:26:44 +04:00
$output -> writeln ( '<info>Turned on maintenance mode</info>' );
2013-10-28 18:15:56 +04:00
});
2015-05-19 11:27:53 +03:00
$updater -> listen ( '\OC\Updater' , 'maintenanceDisabled' , function () use ( $output ) {
$output -> writeln ( '<info>Turned off maintenance mode</info>' );
});
$updater -> listen ( '\OC\Updater' , 'maintenanceActive' , function () use ( $output ) {
$output -> writeln ( '<info>Maintenance mode is kept active</info>' );
});
$updater -> listen ( '\OC\Updater' , 'updateEnd' ,
2016-09-27 19:45:05 +03:00
function ( $success ) use ( $output , $self ) {
2015-06-23 18:07:28 +03:00
if ( $success ) {
2016-09-21 16:12:00 +03:00
$message = " <info>Update successful</info> " ;
2015-06-23 18:07:28 +03:00
} else {
2016-09-21 16:12:00 +03:00
$message = " <error>Update failed</error> " ;
2015-06-23 18:07:28 +03:00
}
2014-09-22 13:59:13 +04:00
$output -> writeln ( $message );
});
2015-10-21 10:17:38 +03:00
$updater -> listen ( '\OC\Updater' , 'dbUpgradeBefore' , function () use ( $output ) {
$output -> writeln ( '<info>Updating database schema</info>' );
});
2013-10-29 00:50:28 +04:00
$updater -> listen ( '\OC\Updater' , 'dbUpgrade' , function () use ( $output ) {
2013-10-29 01:26:44 +04:00
$output -> writeln ( '<info>Updated database</info>' );
2013-10-28 18:15:56 +04:00
});
2015-10-21 10:17:38 +03:00
$updater -> listen ( '\OC\Updater' , 'dbSimulateUpgradeBefore' , function () use ( $output ) {
$output -> writeln ( '<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>' );
});
2014-06-04 18:40:53 +04:00
$updater -> listen ( '\OC\Updater' , 'dbSimulateUpgrade' , function () use ( $output ) {
$output -> writeln ( '<info>Checked database schema update</info>' );
});
2015-02-17 14:00:39 +03:00
$updater -> listen ( '\OC\Updater' , 'incompatibleAppDisabled' , function ( $app ) use ( $output ) {
2016-08-09 14:46:41 +03:00
$output -> writeln ( '<comment>Disabled incompatible app: ' . $app . '</comment>' );
2015-02-17 14:00:39 +03:00
});
2015-05-20 18:06:00 +03:00
$updater -> listen ( '\OC\Updater' , 'thirdPartyAppDisabled' , function ( $app ) use ( $output ) {
2016-08-09 14:46:41 +03:00
$output -> writeln ( '<comment>Disabled 3rd-party app: ' . $app . '</comment>' );
2014-05-27 17:20:33 +04:00
});
2017-05-11 21:35:17 +03:00
$updater -> listen ( '\OC\Updater' , 'checkAppStoreAppBefore' , function ( $app ) use ( $output ) {
$output -> writeln ( '<info>Checking for update of app ' . $app . ' in appstore</info>' );
});
2015-05-12 19:02:31 +03:00
$updater -> listen ( '\OC\Updater' , 'upgradeAppStoreApp' , function ( $app ) use ( $output ) {
2017-05-11 21:35:17 +03:00
$output -> writeln ( '<info>Update app ' . $app . ' from appstore</info>' );
});
$updater -> listen ( '\OC\Updater' , 'checkAppStoreApp' , function ( $app ) use ( $output ) {
$output -> writeln ( '<info>Checked for update of app "' . $app . '" in appstore </info>' );
2015-05-12 19:02:31 +03:00
});
2015-10-21 10:17:38 +03:00
$updater -> listen ( '\OC\Updater' , 'appUpgradeCheckBefore' , function () use ( $output ) {
$output -> writeln ( '<info>Checking updates of apps</info>' );
});
$updater -> listen ( '\OC\Updater' , 'appSimulateUpdate' , function ( $app ) use ( $output ) {
$output -> writeln ( " <info>Checking whether the database schema for < $app > can be updated (this can take a long time depending on the database size)</info> " );
});
2015-02-24 14:52:16 +03:00
$updater -> listen ( '\OC\Updater' , 'appUpgradeCheck' , function () use ( $output ) {
$output -> writeln ( '<info>Checked database schema update for apps</info>' );
});
2015-06-23 11:43:45 +03:00
$updater -> listen ( '\OC\Updater' , 'appUpgradeStarted' , function ( $app , $version ) use ( $output ) {
$output -> writeln ( " <info>Updating < $app > ...</info> " );
});
2015-02-24 14:52:16 +03:00
$updater -> listen ( '\OC\Updater' , 'appUpgrade' , function ( $app , $version ) use ( $output ) {
$output -> writeln ( " <info>Updated < $app > to $version </info> " );
});
2014-09-22 13:59:13 +04:00
$updater -> listen ( '\OC\Updater' , 'failure' , function ( $message ) use ( $output , $self ) {
$output -> writeln ( " <error> $message </error> " );
2013-10-28 18:15:56 +04:00
});
2015-09-29 15:35:32 +03:00
$updater -> listen ( '\OC\Updater' , 'setDebugLogLevel' , function ( $logLevel , $logLevelName ) use ( $output ) {
2016-01-04 13:50:07 +03:00
$output -> writeln ( " <info>Set log level to debug</info> " );
2015-09-29 15:35:32 +03:00
});
$updater -> listen ( '\OC\Updater' , 'resetLogLevel' , function ( $logLevel , $logLevelName ) use ( $output ) {
2016-01-04 13:50:07 +03:00
$output -> writeln ( " <info>Reset log level</info> " );
2015-09-29 15:35:32 +03:00
});
2016-01-22 15:18:00 +03:00
$updater -> listen ( '\OC\Updater' , 'startCheckCodeIntegrity' , function () use ( $output ) {
$output -> writeln ( " <info>Starting code integrity check...</info> " );
});
$updater -> listen ( '\OC\Updater' , 'finishedCheckCodeIntegrity' , function () use ( $output ) {
$output -> writeln ( " <info>Finished code integrity check</info> " );
});
2013-10-28 18:15:56 +04:00
2015-06-23 11:03:27 +03:00
$success = $updater -> upgrade ();
2014-03-14 13:48:07 +04:00
$this -> postUpgradeCheck ( $input , $output );
2015-06-23 11:03:27 +03:00
if ( ! $success ) {
return self :: ERROR_FAILURE ;
}
2013-10-29 00:50:28 +04:00
return self :: ERROR_SUCCESS ;
2014-09-22 14:04:48 +04:00
} else if ( $this -> config -> getSystemValue ( 'maintenance' , false )) {
2016-07-30 16:39:32 +03:00
//Possible scenario: Nextcloud core is updated but an app failed
$output -> writeln ( '<warning>Nextcloud is in maintenance mode</warning>' );
2013-10-29 01:26:44 +04:00
$output -> write ( '<comment>Maybe an upgrade is already in process. Please check the '
2016-07-04 12:50:32 +03:00
. 'logfile (data/nextcloud.log). If you want to re-run the '
2013-10-29 01:19:15 +04:00
. 'upgrade procedure, remove the "maintenance mode" from '
2013-10-29 01:26:44 +04:00
. 'config.php and call this script again.</comment>'
2013-10-29 01:19:15 +04:00
, true );
return self :: ERROR_MAINTENANCE_MODE ;
2013-10-28 18:15:56 +04:00
} else {
2016-07-30 16:39:32 +03:00
$output -> writeln ( '<info>Nextcloud is already latest version</info>' );
2013-10-29 01:19:15 +04:00
return self :: ERROR_UP_TO_DATE ;
2013-10-28 18:15:56 +04:00
}
2013-10-24 21:59:39 +04:00
}
2014-03-14 13:48:07 +04:00
/**
* Perform a post upgrade check ( specific to the command line tool )
*
* @ param InputInterface $input input interface
* @ param OutputInterface $output output interface
*/
protected function postUpgradeCheck ( InputInterface $input , OutputInterface $output ) {
2014-09-22 14:04:48 +04:00
$trustedDomains = $this -> config -> getSystemValue ( 'trusted_domains' , array ());
2014-03-14 13:48:07 +04:00
if ( empty ( $trustedDomains )) {
$output -> write (
'<warning>The setting "trusted_domains" could not be ' .
'set automatically by the upgrade script, ' .
'please set it manually</warning>'
);
}
}
2013-10-24 21:59:39 +04:00
}