From 134c26452a8535c4125dfd671bb283e98724c8a8 Mon Sep 17 00:00:00 2001 From: Netkas Date: Thu, 15 Dec 2022 22:24:12 -0500 Subject: [PATCH] Updated installer to automatically install pre-defined remote repositories --- src/installer/installer | 57 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/installer/installer b/src/installer/installer index 6cfb6e5..a064276 100644 --- a/src/installer/installer +++ b/src/installer/installer @@ -14,9 +14,11 @@ use ncc\Abstracts\ConsoleColors; use ncc\Exceptions\FileNotFoundException; - use ncc\ncc; +use ncc\Managers\RemoteSourcesManager; +use ncc\ncc; use ncc\Objects\CliHelpSection; - use ncc\ThirdParty\Symfony\Filesystem\Exception\IOException; +use ncc\Objects\DefinedRemoteSource; +use ncc\ThirdParty\Symfony\Filesystem\Exception\IOException; use ncc\ThirdParty\Symfony\Filesystem\Filesystem; use ncc\ThirdParty\Symfony\Process\Exception\ProcessFailedException; use ncc\ThirdParty\Symfony\Process\ExecutableFinder; @@ -818,6 +820,57 @@ return; } + if($NCC_FILESYSTEM->exists(__DIR__ . DIRECTORY_SEPARATOR . 'repositories')) + { + if(!$NCC_FILESYSTEM->exists(__DIR__ . DIRECTORY_SEPARATOR . 'repositories' . DIRECTORY_SEPARATOR . 'custom_repositories.json')) + return; + + try + { + $custom_repositories = Functions::loadJsonFile(__DIR__ . DIRECTORY_SEPARATOR . 'repositories' . DIRECTORY_SEPARATOR . 'custom_repositories.json', Functions::FORCE_ARRAY); + } + catch(Exception $e) + { + $custom_repositories = null; + Console::outWarning(sprintf('Failed to load custom repositories: %s', $e->getMessage())); + } + + if($custom_repositories !== null) + { + $source_manager = new RemoteSourcesManager(); + foreach($custom_repositories as $repository) + { + $repo_path = __DIR__ . DIRECTORY_SEPARATOR . 'repositories' . DIRECTORY_SEPARATOR . $repository; + if($NCC_FILESYSTEM->exists($repo_path)) + { + try + { + $definedEntry = DefinedRemoteSource::fromArray(Functions::loadJsonFile($repo_path, Functions::FORCE_ARRAY)); + if(!$source_manager->getRemoteSource($definedEntry->Name)) + $source_manager->addRemoteSource($definedEntry); + } + catch(Exception $e) + { + Console::outWarning(sprintf('Failed to load custom repository %s: %s', $repository, $e->getMessage())); + } + } + else + { + Console::outWarning(sprintf('Failed to load custom repository %s, file does not exist', $repository)); + } + } + + try + { + $source_manager->save(); + } + catch (\ncc\Exceptions\IOException $e) + { + Console::outWarning(sprintf('Failed to save sources: %s', $e->getMessage())); + } + } + } + Console::out('NCC version: ' . NCC_VERSION_NUMBER . ' has been successfully installed'); Console::out('For licensing information see \'' . $NCC_INSTALL_PATH . DIRECTORY_SEPARATOR . 'LICENSE\' or run \'ncc help --license\'');