From 88e92f82c42f2399c5fc50fadcf13932b72791e4 Mon Sep 17 00:00:00 2001 From: Netkas Date: Sun, 11 Sep 2022 14:44:28 -0400 Subject: [PATCH] Fixed issue #2 (https://git.n64.cc/nosial/ncc/-/issues/2) --- src/installer/installer | 20 +++++++++++++------- src/ncc/Managers/ProjectManager.php | 17 +++++++---------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/installer/installer b/src/installer/installer index 9f84353..9b1e43f 100644 --- a/src/installer/installer +++ b/src/installer/installer @@ -23,8 +23,8 @@ 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; -use ncc\ThirdParty\Symfony\process\PhpExecutableFinder; + use ncc\ThirdParty\Symfony\Process\ExecutableFinder; + use ncc\ThirdParty\Symfony\process\PhpExecutableFinder; use ncc\ThirdParty\Symfony\Process\Process; use ncc\ThirdParty\Symfony\Yaml\Yaml; use ncc\Utilities\Console; @@ -37,7 +37,7 @@ use ncc\ThirdParty\Symfony\process\PhpExecutableFinder; # Global Variables $NCC_INSTALL_PATH=DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'ncc'; $NCC_DATA_PATH=DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'ncc'; - $NCC_UPDATE_SOURCE='https://updates.nosial.com/ncc/check_updates?current_version=$VERSION'; # Unused + $NCC_COMPOSER_UPDATE_SOURCE='https://getcomposer.org/installer'; $NCC_CHECKSUM=__DIR__ . DIRECTORY_SEPARATOR . 'checksum.bin'; $NCC_AUTOLOAD=__DIR__ . DIRECTORY_SEPARATOR . 'autoload.php'; $NCC_PHP_EXECUTABLE=null; @@ -154,6 +154,12 @@ use ncc\ThirdParty\Symfony\process\PhpExecutableFinder; } // Check if running as root + if(function_exists('posix_getuid') == false) + { + Console::outError('The function posix_getuid() is not available on your system, please make sure the extension `php-common` is installed'); + exit(1); + } + if (posix_getuid() !== 0) { Console::outError('You must be running as root'); @@ -463,7 +469,7 @@ use ncc\ThirdParty\Symfony\process\PhpExecutableFinder; $fp = fopen($NCC_INSTALL_PATH . DIRECTORY_SEPARATOR . 'composer-setup.php', 'w+'); $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'https://getcomposer.org/installer'); + curl_setopt($ch, CURLOPT_URL, $NCC_COMPOSER_UPDATE_SOURCE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 600); curl_setopt($ch, CURLOPT_FILE, $fp); @@ -491,7 +497,7 @@ use ncc\ThirdParty\Symfony\process\PhpExecutableFinder; } catch(ProcessFailedException $e) { - Console::outError('Cannot install compos)er, ' . $e->getMessage()); + Console::outError('Cannot install composer, ' . $e->getMessage()); exit(1); } @@ -619,11 +625,11 @@ use ncc\ThirdParty\Symfony\process\PhpExecutableFinder; { if(isset($config_obj[$section])) { - foreach($value as $section_item) + foreach($value as $section_item => $section_value) { if(!isset($config_obj[$section][$section_item])) { - $config_obj[$section][$section_item] = $value; + $config_obj[$section][$section_item] = $section_value; } } } diff --git a/src/ncc/Managers/ProjectManager.php b/src/ncc/Managers/ProjectManager.php index e450273..a5f01d3 100644 --- a/src/ncc/Managers/ProjectManager.php +++ b/src/ncc/Managers/ProjectManager.php @@ -9,7 +9,7 @@ use ncc\Exceptions\ProjectAlreadyExistsException; use ncc\Objects\ProjectConfiguration; use ncc\Objects\ProjectConfiguration\Compiler; - use ncc\Symfony\Component\Uid\Uuid; + use ncc\ThirdParty\Symfony\Uid\Uuid; use ncc\Utilities\Validate; class ProjectManager @@ -53,9 +53,9 @@ * Attempts to resolve the project path from the selected directory * Returns false if the selected directory is not a proper project or an initialized project * - * @return bool + * @return void */ - private function detectProjectPath(): bool + private function detectProjectPath(): void { $selected_directory = $this->SelectedDirectory; @@ -69,7 +69,7 @@ // Detect if the folder exists or not if(!file_exists($selected_directory) || !is_dir($selected_directory)) { - return false; + return; } // Detect if project.json exists in the directory @@ -77,10 +77,7 @@ { $this->ProjectPath = $selected_directory; $this->ProjectFilePath = $selected_directory . 'project.json'; - return true; } - - return false; } /** @@ -95,7 +92,7 @@ * @throws MalformedJsonException * @throws ProjectAlreadyExistsException */ - public function initializeProject(Compiler $compiler, string $name, string $package, array $options=[]) + public function initializeProject(Compiler $compiler, string $name, string $package, array $options=[]): void { // Validate the project information first if(!Validate::packageName($package)) @@ -170,9 +167,9 @@ switch($option) { case InitializeProjectOptions::CREATE_SOURCE_DIRECTORY: - if(!file_exists($source)) + if(!file_exists($this->ProjectPath . DIRECTORY_SEPARATOR . 'src')) { - mkdir($source); + mkdir($this->ProjectPath . DIRECTORY_SEPARATOR . 'src'); } break; }