From 467c8a9d787b0005e05aa36154d7036b377b3221 Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Sun, 13 Jun 2021 10:08:17 +0100 Subject: [PATCH 1/4] Remove the CAN_INSTALL file when occ maintenance:install is complete When occ maintenance:install is run from the CLI, the CAN_INSTALL in the config directory is left in place when installed is set to true, whereas this file is removed when the web installer is used. Removing this file in the CLI command maintains consistency between the two. This allows automation tools an easier way to determine if this process has been completed. Signed-off-by: Alex Harpin --- lib/private/Setup.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 7b08fb2f66fd2..d1936f55f281b 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -419,6 +419,9 @@ public function install($options) { //and we are done $config->setSystemValue('installed', true); + if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { + unlink(\OC::$configDir.'/CAN_INSTALL'); + } $bootstrapCoordinator = \OC::$server->query(\OC\AppFramework\Bootstrap\Coordinator::class); $bootstrapCoordinator->runInitialRegistration(); From 72af1407237f716282308c9288e7e7170343376e Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Sat, 19 Jun 2021 19:56:54 +0100 Subject: [PATCH 2/4] Move CAN_INSTALL check to method and remove unlink from SetupController Move the check for the CAN_INSTALL file in the config directory to a method in the Setup class and remove the call to unlink from the SetupController as this in now handled in the Setup class. Signed-off-by: Alex Harpin --- core/Controller/SetupController.php | 8 +++----- lib/private/Setup.php | 9 ++++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core/Controller/SetupController.php b/core/Controller/SetupController.php index ab8b1973bf2b8..b4f41b48da2ac 100644 --- a/core/Controller/SetupController.php +++ b/core/Controller/SetupController.php @@ -59,7 +59,7 @@ public function run(array $post): void { $post['dbpass'] = $post['dbpassword']; } - if (!is_file(\OC::$configDir.'/CAN_INSTALL')) { + if (!$this->setupHelper->canInstallExists()) { $this->displaySetupForbidden(); return; } @@ -107,10 +107,8 @@ private function finishSetup() { } \OC::$server->getIntegrityCodeChecker()->runInstanceVerification(); - if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { - if (!unlink(\OC::$configDir.'/CAN_INSTALL')) { - \OC_Template::printGuestPage('', 'installation_incomplete'); - } + if ($this->setupHelper->canInstallExists()) { + \OC_Template::printGuestPage('', 'installation_incomplete'); } header('Location: ' . \OC::$server->getURLGenerator()->getAbsoluteURL('index.php/core/apps/recommended')); diff --git a/lib/private/Setup.php b/lib/private/Setup.php index d1936f55f281b..bd17698467827 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -419,7 +419,7 @@ public function install($options) { //and we are done $config->setSystemValue('installed', true); - if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL')) { + if (self::canInstallExists()) { unlink(\OC::$configDir.'/CAN_INSTALL'); } @@ -599,4 +599,11 @@ private function getVendorData(): array { 'channel' => (string)$OC_Channel, ]; } + + /** + * @return bool + */ + public function canInstallExists() { + return \OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL'); + } } From d5b52ddd21bc32d250d1d8d3d4308c00d505a0cf Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Sat, 19 Jun 2021 20:01:06 +0100 Subject: [PATCH 3/4] Log a warning to CLI install command if CAN_INSTALL is not removed Log a warning for the CLI install command if the CAN_INSTALL file still exists at the end of the installation. This matches the warning logged by the web installer. Signed-off-by: Alex Harpin --- core/Command/Maintenance/Install.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php index c445f2c2f46b7..c06cffe7dfc40 100644 --- a/core/Command/Maintenance/Install.php +++ b/core/Command/Maintenance/Install.php @@ -107,6 +107,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->printErrors($output, $errors); return 1; } + if ($setupHelper->canInstallExists()) { + $output->writeln('Could not remove CAN_INSTALL from the config folder. Please remove this file manually.'); + } $output->writeln("Nextcloud was successfully installed"); return 0; } From 644df591b138d28b1631ecc13ebe600c16a909f1 Mon Sep 17 00:00:00 2001 From: Alex Harpin Date: Sat, 19 Jun 2021 21:06:57 +0100 Subject: [PATCH 4/4] Rename canInstallExists method and add new method for removal Rename canInstallExists to shouldRemoveCanInstallFile to cover removal of this file for non-git channels and logging any failure to remove it. Add new method to detect if this file exists during web based installation. Signed-off-by: Alex Harpin --- core/Command/Maintenance/Install.php | 2 +- core/Controller/SetupController.php | 4 ++-- lib/private/Setup.php | 11 +++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php index c06cffe7dfc40..d53cd867b0663 100644 --- a/core/Command/Maintenance/Install.php +++ b/core/Command/Maintenance/Install.php @@ -107,7 +107,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->printErrors($output, $errors); return 1; } - if ($setupHelper->canInstallExists()) { + if ($setupHelper->shouldRemoveCanInstallFile()) { $output->writeln('Could not remove CAN_INSTALL from the config folder. Please remove this file manually.'); } $output->writeln("Nextcloud was successfully installed"); diff --git a/core/Controller/SetupController.php b/core/Controller/SetupController.php index b4f41b48da2ac..cdab39edf8438 100644 --- a/core/Controller/SetupController.php +++ b/core/Controller/SetupController.php @@ -59,7 +59,7 @@ public function run(array $post): void { $post['dbpass'] = $post['dbpassword']; } - if (!$this->setupHelper->canInstallExists()) { + if (!$this->setupHelper->canInstallFileExists()) { $this->displaySetupForbidden(); return; } @@ -107,7 +107,7 @@ private function finishSetup() { } \OC::$server->getIntegrityCodeChecker()->runInstanceVerification(); - if ($this->setupHelper->canInstallExists()) { + if ($this->setupHelper->shouldRemoveCanInstallFile()) { \OC_Template::printGuestPage('', 'installation_incomplete'); } diff --git a/lib/private/Setup.php b/lib/private/Setup.php index bd17698467827..e84a5e4987aae 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -419,7 +419,7 @@ public function install($options) { //and we are done $config->setSystemValue('installed', true); - if (self::canInstallExists()) { + if (self::shouldRemoveCanInstallFile()) { unlink(\OC::$configDir.'/CAN_INSTALL'); } @@ -603,7 +603,14 @@ private function getVendorData(): array { /** * @return bool */ - public function canInstallExists() { + public function shouldRemoveCanInstallFile() { return \OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir.'/CAN_INSTALL'); } + + /** + * @return bool + */ + public function canInstallFileExists() { + return is_file(\OC::$configDir.'/CAN_INSTALL'); + } }